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().

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to