[lug] sendto(2) problem with ipv4/ipv6 addresses...
Alan Robertson
alanr at unix.sh
Mon Apr 2 12:38:42 MDT 2012
As part of the Assimilation Monitoring project (assimmon.org), I've been
writing some UDP network code to send packets. It seems to work fine
when sending to the ipv6 loopback address (::1), but not when sending to
ipv4 addresses. I'm sending to ipv4 addresses by using the ipv4 part of
the ipv6 address space ("::ffff:aa.bb.cc.dd"). Tcpdump is showing that
nothing is being sent - so the kernel is blocking this call before it
goes out.
The code being invoked is exactly the same (except for the address) for
the working and failing cases - so it must be something in the data...
The failing line of code is simple:
rc = sendto(self->getfd(self), packet, (size_t)length, flags,
(const struct sockaddr*)&v6addr, sizeof(v6addr));
g_return_if_fail(rc == length);
When the v6addr structure refers to "::1" it works fine. But when it is
set to "::ffff:10.10.10.4" (my local address) it fails with ENETUNREACH
When I watch it with strace you see this system call when it succeeds:
sendto(4,
"\0\1\0*\0\0\0\1\0\"\1\2\337?a\230\4\251/\333 at W\31-\304=\327H\352w\212\334"...,
48, 0, {sa_family=AF_INET6, sin6_port=htons(1984), inet_pton(AF_INET6,
"::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 48
When I watch it with strace you see this system call when it fails:
sendto(4,
"\0\1\0*\0\0\0\1\0\"\1\2\337?a\230\4\251/\333 at W\31-\304=\327H\352w\212\334"...,
48, 0, {sa_family=AF_INET6, sin6_port=htons(1984), inet_pton(AF_INET6,
"::ffff:10.10.10.5", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28)
= -1 ENETUNREACH (Network is unreachable)
When I look at the struct sockaddr_in6 in gdb in the failing case, I see
this:
*(gdb)* /print v6addr/
$1 = {sin6_family = 10, sin6_port = 49159, sin6_flowinfo = 0, sin6_addr
= {__in6_u = {
__u6_addr8 =
"\000\000\000\000\000\000\000\000\000\000\377\377\n\n\n\005",
__u6_addr16 = {0, 0, 0, 0, 0, 65535, 2570, 1290},
__u6_addr32 = {0, 0, 4294901760, 84544010}}}, sin6_scope_id = 0}
Any suggestions?
--
Alan Robertson<alanr at unix.sh> - @OSSAlanR
"Openness is the foundation and preservative of friendship... Let me claim from you at all times your undisguised opinions." - William Wilberforce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20120402/94cc9001/attachment.html>
More information about the LUG
mailing list