From a26a7f976701c7616d95b0d732b708498b4abf41 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 29 Oct 2018 06:51:56 -0600 Subject: [PATCH] apps/netutils/netlib and apps/examples/igmp: Adapt to use the corrected, semi-standard version of struct ip_msfilter. --- examples/igmp/igmp.c | 12 +++++++---- include/netutils/ipmsfilter.h | 10 +++++----- netutils/netlib/netlib_ipmsfilter.c | 31 +++++++++++++++++++---------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/examples/igmp/igmp.c b/examples/igmp/igmp.c index 8cb2e9a27..0d1a3b0bf 100644 --- a/examples/igmp/igmp.c +++ b/examples/igmp/igmp.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/igmp/igmp.c * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -90,6 +90,7 @@ int igmp_main(int argc, char *argv[]) #endif { struct in_addr addr; + struct in_addr mcast; #if defined(CONFIG_EXAMPLES_IGMP_NOMAC) uint8_t mac[IFHWADDRLEN]; #endif @@ -130,11 +131,14 @@ int igmp_main(int argc, char *argv[]) netlib_ifup("eth0"); /* Not much of a test for now */ + + addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_IPADDR); + mcast.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_GRPADDR); + /* Join the group */ printf("Join group...\n"); - addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_GRPADDR); - ipmsfilter("eth0", &addr, MCAST_INCLUDE); + ipmsfilter(&addr, &mcast, MCAST_INCLUDE); /* Wait a while */ @@ -144,7 +148,7 @@ int igmp_main(int argc, char *argv[]) /* Leave the group */ printf("Leave group...\n"); - ipmsfilter("eth0", &addr, MCAST_EXCLUDE); + ipmsfilter(&addr, &mcast, MCAST_EXCLUDE); /* Wait a while */ diff --git a/include/netutils/ipmsfilter.h b/include/netutils/ipmsfilter.h index 895c35a01..98c514cfb 100644 --- a/include/netutils/ipmsfilter.h +++ b/include/netutils/ipmsfilter.h @@ -2,7 +2,7 @@ * apps/include/netutils/ipmsfilter.h * User interface to add/remove IP multicast address * - * Copyright (C) 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -76,11 +76,10 @@ extern "C" * * Description: * Add or remove an IP address from a multicast filter set. - * (See netutils/netlib/netlib_ipmsfilter.c) * * Parameters: - * ifname The name of the interface to use, size must less than IMSFNAMSIZ - * multiaddr Multicast group address to add/remove + * interface The local address of the local interface to use. + * multiaddr Multicast group address to add/remove (network byte order) * fmode MCAST_INCLUDE: Add multicast address * MCAST_EXCLUDE: Remove multicast address * @@ -89,7 +88,8 @@ extern "C" * ****************************************************************************/ -int ipmsfilter(FAR const char *ifname, FAR const struct in_addr *multiaddr, +int ipmsfilter(FAR const struct in_addr *interface, + FAR const struct in_addr *multiaddr, uint32_t fmode); #undef EXTERN diff --git a/netutils/netlib/netlib_ipmsfilter.c b/netutils/netlib/netlib_ipmsfilter.c index fc5e51dfd..ac04f6ebc 100644 --- a/netutils/netlib/netlib_ipmsfilter.c +++ b/netutils/netlib/netlib_ipmsfilter.c @@ -1,7 +1,7 @@ /**************************************************************************** * netutils/netlib/netlib_setipmsfilter.c * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,7 +70,7 @@ * Add or remove an IP address from a multicast filter set. * * Parameters: - * ifname The name of the interface to use, size must less than IMSFNAMSIZ + * interface The local address of the local interface to use. * multiaddr Multicast group address to add/remove (network byte order) * fmode MCAST_INCLUDE: Add multicast address * MCAST_EXCLUDE: Remove multicast address @@ -80,13 +80,14 @@ * ****************************************************************************/ -int ipmsfilter(FAR const char *ifname, FAR const struct in_addr *multiaddr, +int ipmsfilter(FAR const struct in_addr *interface, + FAR const struct in_addr *multiaddr, uint32_t fmode) { int ret = ERROR; - ninfo("ifname: %s muliaddr: %08x fmode: %ld\n", ifname, *multiaddr, fmode); - if (ifname && multiaddr) + ninfo("interface: %08x muliaddr: %08x fmode: %ld\n", interface, *multiaddr, fmode); + if (interface != NULL && multiaddr != NULL) { /* Get a socket (only so that we get access to the INET subsystem) */ @@ -95,21 +96,29 @@ int ipmsfilter(FAR const char *ifname, FAR const struct in_addr *multiaddr, { struct ip_msfilter imsf; - /* Put the driver name into the request */ - - strncpy(imsf.imsf_name, ifname, IMSFNAMSIZ); - - /* Put the new address into the request */ + /* Put the multicast group address into the request */ imsf.imsf_multiaddr.s_addr = multiaddr->s_addr; - /* Perforom the ioctl to set the MAC address */ + /* Put the address of the local interface into the request */ + + imsf.imsf_interface.s_addr = interface->s_addr; + + /* Put the filter mode into the request */ imsf.imsf_fmode = fmode; + + /* No source address */ + + imsf.imsf_numsrc = 0; + + /* Perform the ioctl to set the MAC address */ + ret = ioctl(sockfd, SIOCSIPMSFILTER, (unsigned long)&imsf); close(sockfd); } } + return ret; }