[lkml]   [2000]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: getsockopt() with IP_PKTINFO not working?
On Wed, Dec 20, 2000 at 05:44:34PM +0100, Cord Seele wrote:
> I am trying to get the destination address of an incoming udp packet
> with getsockopt().
> According to the man pages flag IP_PKTINFO should do that. But it
> doesn't work:
> struct in_pktinfo pktinfo;
> socklen_t optlen;
> struct in_addr local_addr;
> optlen=(socklen_t)sizeof(pktinfo);
> syslog (LOG_ERR, "ERR %d",
> getsockopt(fd, SOL_IP, IP_PKTINFO, &pktinfo, &optlen));

You're misreading the manpage. IP_PKTINFO just enables recvmsg() to pass
ancillary messages that contain pktinfo structures. getsockopt IP_PKTINFO
returns the state of the the IP_PKTINFO flag on the socket.

So use setsockopt IP_PKTINFO to set the flag to true and then receive
them using recvmsg().

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:52    [W:0.032 / U:0.772 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site