Recv UDP v6 pkt destination address Sierra?

I'm working on an app for MacOSX Sierra (10.12.6). It has an IPv6 UDP socket on which it receives requests. This runs on a multi-homed host. I need a way to get the IPv6 destination address for each received packet. After searching the web I've found two potential socket options to use with recvmsg: IP_RECVDSTADDR and IP_RECVPKTINFO. I've tried them both with no success.


const unsigned int opt = 1;

rc = setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof opt);

if (rc < 0) {

perror("setsockopt(IPPROTO_IP, IP_RECVDSTADDR) failed");

}


I get the error with either option, IP_RECVDSTADDR and IP_RECVPKTINFO.

How do I do this?

Replies

IP_RECVDSTADDR
is supported on 10.12 (I’m not sure when support was introduced, but I see it in the 10.4 SDK!). You wrote:
rc = setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof opt);

If

s
is an IPv6 socket, shouldn’t you be using
IPPROTO_IPV6
?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"