tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
sendmsg(), IPv4, and ancilliary socket data
Hi,
I would appreciate a pointer to documentation here - "man ip" isn't
helping, "man sendmsg" isn't helping either...
What I want to do is:
- have an UDP socket that is bound to INADDR_ANY
- receive the destination address for incoming packets via recvmsg()
(this works, using IP_RECVDSTADDR setsockopt())
- send the reply packet with sendmsg(), ensuring the source address is
where the incoming packet was sent to
I have this working for IPv6, and for IPv4 on "about everything but
NetBSD"
On "the other BSDs", using
mesg.msg_controllen = CMSG_SPACE(sizeof (struct in_addr));
cmsg = CMSG_FIRSTHDR (&mesg);
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_RECVDSTADDR;
*(struct in_addr *) CMSG_DATA (cmsg) = to->pi.in4;
(where to->pi.in4 is a struct in_addr)
works nicely for sending, but NetBSD 7.0.1 returns EINVAL.
Reading through
http://www.nerv.org/~ryo/files/netbsd/sendfromto/sockfromto.c
made me try IP_PKTINFO instead
mesg.msg_controllen = CMSG_SPACE(sizeof (struct in_pktinfo));
cmsg = CMSG_FIRSTHDR (&mesg);
cmsg->cmsg_len = CMSG_LEN(sizeof (struct in_pktinfo));
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
struct in_pktinfo *pkti;
pkti = (struct in_pktinfo *) CMSG_DATA (cmsg);
pkti->ipi_ifindex = 0;
pkti->ipi_addr = to->pi.in4;
... but that yields EINVAL just as well.
So, right now I'm wondering if this is a case of "not implemented for
sending" (as per ryo's comment: "socket(), bind() and sendto()"), or
whether I'm doing something wrong - which might well be.
Thus: a pointer to the part of the documentation that documents what
sort of ancilliary socket options sendmsg() will accept would be
highly appreciated...
(in parallel, I'm digging through src/sys/ to see if I can find the
answer there, but a concise document would be nicer :) )
thanks,
gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany gert%greenie.muc.de@localhost
fax: +49-89-35655025 gert%net.informatik.tu-muenchen.de@localhost
Home |
Main Index |
Thread Index |
Old Index