apps/netutils/netlib and apps/examples/igmp: Adapt to use the corrected, semi-standard version of struct ip_msfilter.

This commit is contained in:
Gregory Nutt 2018-10-29 06:51:56 -06:00
parent 3a4faf944a
commit a26a7f9767
3 changed files with 33 additions and 20 deletions

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/igmp/igmp.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -90,6 +90,7 @@ int igmp_main(int argc, char *argv[])
#endif #endif
{ {
struct in_addr addr; struct in_addr addr;
struct in_addr mcast;
#if defined(CONFIG_EXAMPLES_IGMP_NOMAC) #if defined(CONFIG_EXAMPLES_IGMP_NOMAC)
uint8_t mac[IFHWADDRLEN]; uint8_t mac[IFHWADDRLEN];
#endif #endif
@ -130,11 +131,14 @@ int igmp_main(int argc, char *argv[])
netlib_ifup("eth0"); netlib_ifup("eth0");
/* Not much of a test for now */ /* 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 */ /* Join the group */
printf("Join group...\n"); printf("Join group...\n");
addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_GRPADDR); ipmsfilter(&addr, &mcast, MCAST_INCLUDE);
ipmsfilter("eth0", &addr, MCAST_INCLUDE);
/* Wait a while */ /* Wait a while */
@ -144,7 +148,7 @@ int igmp_main(int argc, char *argv[])
/* Leave the group */ /* Leave the group */
printf("Leave group...\n"); printf("Leave group...\n");
ipmsfilter("eth0", &addr, MCAST_EXCLUDE); ipmsfilter(&addr, &mcast, MCAST_EXCLUDE);
/* Wait a while */ /* Wait a while */

View File

@ -2,7 +2,7 @@
* apps/include/netutils/ipmsfilter.h * apps/include/netutils/ipmsfilter.h
* User interface to add/remove IP multicast address * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -76,11 +76,10 @@ extern "C"
* *
* Description: * Description:
* Add or remove an IP address from a multicast filter set. * Add or remove an IP address from a multicast filter set.
* (See netutils/netlib/netlib_ipmsfilter.c)
* *
* Parameters: * 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 * multiaddr Multicast group address to add/remove (network byte order)
* fmode MCAST_INCLUDE: Add multicast address * fmode MCAST_INCLUDE: Add multicast address
* MCAST_EXCLUDE: Remove 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); uint32_t fmode);
#undef EXTERN #undef EXTERN

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* netutils/netlib/netlib_setipmsfilter.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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. * Add or remove an IP address from a multicast filter set.
* *
* Parameters: * 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) * multiaddr Multicast group address to add/remove (network byte order)
* fmode MCAST_INCLUDE: Add multicast address * fmode MCAST_INCLUDE: Add multicast address
* MCAST_EXCLUDE: Remove 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) uint32_t fmode)
{ {
int ret = ERROR; int ret = ERROR;
ninfo("ifname: %s muliaddr: %08x fmode: %ld\n", ifname, *multiaddr, fmode); ninfo("interface: %08x muliaddr: %08x fmode: %ld\n", interface, *multiaddr, fmode);
if (ifname && multiaddr) if (interface != NULL && multiaddr != NULL)
{ {
/* Get a socket (only so that we get access to the INET subsystem) */ /* 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; struct ip_msfilter imsf;
/* Put the driver name into the request */ /* Put the multicast group address into the request */
strncpy(imsf.imsf_name, ifname, IMSFNAMSIZ);
/* Put the new address into the request */
imsf.imsf_multiaddr.s_addr = multiaddr->s_addr; 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; 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); ret = ioctl(sockfd, SIOCSIPMSFILTER, (unsigned long)&imsf);
close(sockfd); close(sockfd);
} }
} }
return ret; return ret;
} }