[PATCH] Decode setsockopt() multicast arguments

Philippe Ombredanne pombredanne at nexb.com
Tue Mar 18 13:48:04 UTC 2014


On Mon, Mar 17, 2014 at 7:24 PM, Ben Noordhuis <info at bnoordhuis.nl> wrote:
> A small test program follows:
>
>   #include <sys/socket.h>
>   #include <netinet/in.h>
>   #include <arpa/inet.h>
>   #include <stddef.h>
>
>   int main(void) {
>     int fd;
>     struct ip_mreq m4;
>     struct ipv6_mreq m6;
>     fd = socket(AF_INET6, SOCK_DGRAM, 0);
>     inet_aton("224.0.0.2", &m4.imr_multiaddr);
>     inet_aton("0.0.0.0", &m4.imr_interface);
>     inet_pton(AF_INET6, "ff01::c", &m6.ipv6mr_multiaddr);
>     m6.ipv6mr_interface = 42;
>     setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &m4, 4);
>     setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP, &m4, 4);
>     setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &m4, sizeof(m4));
>     setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP, &m4, sizeof(m4));
>     setsockopt(fd, SOL_IP, IPV6_ADD_MEMBERSHIP, &m6, sizeof(m6));
>     setsockopt(fd, SOL_IP, IPV6_DROP_MEMBERSHIP, &m6, sizeof(m6));
>     setsockopt(fd, SOL_IP, IPV6_ADD_MEMBERSHIP, &m6, 4);
>     setsockopt(fd, SOL_IP, IPV6_DROP_MEMBERSHIP, &m6, 4);
>     return 0;
>   }
>
> And prints the following output when traced:
>
>   setsockopt(3, SOL_IP, IP_ADD_MEMBERSHIP, "\340\0\0\2", 4)
>     = -1 EINVAL (Invalid argument)
>   setsockopt(3, SOL_IP, IP_DROP_MEMBERSHIP, "\340\0\0\2", 4)
>     = -1 EINVAL (Invalid argument)
>   setsockopt(3, SOL_IP, IP_ADD_MEMBERSHIP,
>       {imr_multiaddr=inet_addr("224.0.0.2"),
>       imr_interface=inet_addr("0.0.0.0")}, 8) = 0
>   setsockopt(3, SOL_IP, IP_DROP_MEMBERSHIP,
>       {imr_multiaddr=inet_addr("224.0.0.2"),
>       imr_interface=inet_addr("0.0.0.0")}, 8) = 0
>   setsockopt(3, SOL_IP, IPV6_ADD_MEMBERSHIP,
>       {ipv6mr_multiaddr=inet_addr("ff01::c"), ipv6mr_interface=42}, 20)
>     = 0
>   setsockopt(3, SOL_IP, IPV6_DROP_MEMBERSHIP,
>       {ipv6mr_multiaddr=inet_addr("ff01::c"), ipv6mr_interface=42}, 20)
>     = -1 EINVAL (Invalid argument)
>   setsockopt(3, SOL_IP, IPV6_ADD_MEMBERSHIP, "\377\1\0\0", 4) = 0
>   setsockopt(3, SOL_IP, IPV6_DROP_MEMBERSHIP, "\377\1\0\0", 4)
>     = -1 EINVAL (Invalid argument)

Excellent, really thanks mucho for providing a test.
I will let Dmitry review and comment on the patch proper.

On my side I am interested in the test and I might try to make this
part of the make check.
Time to beef up a notch strace's test framework!

-- 
Philippe Ombredanne




More information about the Strace-devel mailing list