All of lore.kernel.org
 help / color / mirror / Atom feed
* getsockopt() with IP_PKTINFO not working?
@ 2000-12-20 16:44 Cord Seele
  2000-12-20 17:23 ` Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Cord Seele @ 2000-12-20 16:44 UTC (permalink / raw)
  To: linux-kernel

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));
        syslog (LOG_ERR, "LENGTH %d %d", (int)optlen, sizeof(pktinfo));
        local_addr=pktinfo.ipi_addr;                                   
        syslog (LOG_ERR,"ADDR %s",inet_ntoa(local_addr));

results in /var/log/messages:

Dec 19 19:27:49 coda tftpd[20081]: ERR 0
Dec 19 19:27:49 coda tftpd[20081]: LENGTH 4 12
Dec 19 19:27:49 coda tftpd[20081]: ADDR 232.252.255.191

While getsockopt() returns no error, the resulting length is too short
and the addr is
definitely invalid. I would expect either getsockopt() to return -1, it
this is not
implemented or return at least 12 valid bytes.
(I am running a 2.2.16 kernel with glibc 2.1.3.)

I even tried the 'hard way' using recvmsg() but the resulting
msg_controllen == 0. 


Background:
If a machine has more than one address in a single network, i.e.

	eth0   192.168.0.10
	eth0:1 192.168.0.20

a call to bind() normally assigns the primary ip address (.10) to the
socket.
If the server was addressed on his second address (.20) the request is
not answered
and fails. I have this problem with tftpd.
Or is there a better way to get the destination address of an incoming
udp packet?

Thanks for any help.

	Cord Seele

PS: Please CC me since I am not an the list.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: getsockopt() with IP_PKTINFO not working?
  2000-12-20 16:44 getsockopt() with IP_PKTINFO not working? Cord Seele
@ 2000-12-20 17:23 ` Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2000-12-20 17:23 UTC (permalink / raw)
  To: Cord Seele; +Cc: linux-kernel

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 majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-12-20 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-12-20 16:44 getsockopt() with IP_PKTINFO not working? Cord Seele
2000-12-20 17:23 ` Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.