apps/examples/mld: Add a test of MLD. Not much of a test, but it does provide a mechansim for some low-level bring-up operations.
This commit is contained in:
parent
7b56c9c336
commit
44e2505038
@ -11,20 +11,20 @@ config EXAMPLES_IGMP
|
||||
|
||||
if EXAMPLES_IGMP
|
||||
|
||||
config EXAMPLES_IGMP_IPADDR
|
||||
hex "Target IP address"
|
||||
default 0xc0a80a10
|
||||
config EXAMPLES_IGMP_IPADDR
|
||||
hex "Target IP address"
|
||||
default 0xc0a80a10
|
||||
|
||||
config EXAMPLES_IGMP_DRIPADDR
|
||||
hex "Default Router IP address (Gateway)"
|
||||
default 0xc0a80aFA
|
||||
config EXAMPLES_IGMP_DRIPADDR
|
||||
hex "Default Router IP address (Gateway)"
|
||||
default 0xc0a80aFA
|
||||
|
||||
config EXAMPLES_IGMP_GRPADDR
|
||||
hex "Group address"
|
||||
default 0xE0000181
|
||||
config EXAMPLES_IGMP_GRPADDR
|
||||
hex "Group address"
|
||||
default 0xE0000181
|
||||
|
||||
config EXAMPLES_IGMP_NETMASK
|
||||
hex "Network Mask"
|
||||
default 0xffffff00
|
||||
config EXAMPLES_IGMP_NETMASK
|
||||
hex "Network Mask"
|
||||
default 0xffffff00
|
||||
|
||||
endif
|
||||
|
@ -33,8 +33,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __EXAMPLES_IGMP_H
|
||||
#define __EXAMPLES_IGMP_H
|
||||
#ifndef __APPS_EXAMPLES_IGMP_IGMP_H
|
||||
#define __APPS_EXAMPLES_IGMP_IGMP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -50,4 +50,4 @@
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __EXAMPLES_IGMP_H */
|
||||
#endif /* __APPS_EXAMPLES_IGMP_IGMP_H */
|
||||
|
13
examples/mld/.gitignore
vendored
Normal file
13
examples/mld/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/host
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
||||
/*.exe
|
91
examples/mld/Kconfig
Normal file
91
examples/mld/Kconfig
Normal file
@ -0,0 +1,91 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_MLD
|
||||
tristate "MLD example"
|
||||
default n
|
||||
depends on NET_UDP && NET_MLD
|
||||
---help---
|
||||
Enable the MLD example
|
||||
|
||||
if EXAMPLES_MLD
|
||||
|
||||
config EXAMPLES_MLD_PROGNAME
|
||||
string "Program name"
|
||||
default "mld"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_MLD_APPNAME
|
||||
string "NSH builtin name"
|
||||
default "mld"
|
||||
depends on CONFIG_NSH_BUILTIN_APPS
|
||||
---help---
|
||||
This is the name of the application that will be use when running
|
||||
from the NSH command line
|
||||
|
||||
config EXAMPLES_MLD_PRIORITY
|
||||
int "MLD example task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_MLD_STACKSIZE
|
||||
int "MLD example stack size"
|
||||
default 2048
|
||||
|
||||
config EXAMPLES_MLD_INIT
|
||||
bool "Initialize network"
|
||||
default n if NSH_BUILTIN_APPS
|
||||
default y if !NSH_BUILTIN_APPS
|
||||
depends on !BUILD_LOADABLE
|
||||
---help---
|
||||
Include logic to initialize the network. This should not be done if
|
||||
the network is already initialized when nettest runs. This is
|
||||
usually the case, for example, when nettest is run as an NSH built-
|
||||
in task.
|
||||
|
||||
if EXAMPLES_MLD_INIT
|
||||
|
||||
config EXAMPLES_MLD_IPADDR
|
||||
hex "Target Link-Local address"
|
||||
default 0x00000002
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
Last 16-bits of the target link-local, unicast in host order. Given
|
||||
|
||||
CONFIG_EXAMPLES_MLD_IPADDR=0xXXXX
|
||||
|
||||
the full IPv6 link local address will be fe80::00ff:fe00:XXXX (host order)
|
||||
|
||||
config EXAMPLES_MLD_DRIPADDR
|
||||
hex "Default Router IP address (Gateway)"
|
||||
default 0x00000001
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
Last 16-bits of the default link-local, unicast in host order. Given
|
||||
|
||||
CONFIG_EXAMPLES_MLD_DRIPADDR=0xXXXX
|
||||
|
||||
the full IPv6 link local address will be fe80::00ff:fe00:XXXX (host order)
|
||||
|
||||
config EXAMPLES_MLD_NOMAC
|
||||
bool "Use Canned MAC Address"
|
||||
default n
|
||||
|
||||
endif # EXAMPLES_MLD_INIT
|
||||
|
||||
config EXAMPLES_MLD_GRPADDR
|
||||
hex "Group address"
|
||||
default 0xE0000181
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
Last 16-bits of the group link-local, unicast in host order. Given
|
||||
|
||||
CONFIG_EXAMPLES_MLD_GRPADDR=0xXXXX
|
||||
|
||||
the full IPv6 link local address will be fe80::00ff:fe00:XXXX (host order)
|
||||
|
||||
endif
|
39
examples/mld/Make.defs
Normal file
39
examples/mld/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/mld/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_MLD),)
|
||||
CONFIGURED_APPS += examples/mld
|
||||
endif
|
57
examples/mld/Makefile
Normal file
57
examples/mld/Makefile
Normal file
@ -0,0 +1,57 @@
|
||||
############################################################################
|
||||
# apps/examples/mld/Makefile
|
||||
#
|
||||
# Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# MLD Networking Example
|
||||
|
||||
CONFIG_EXAMPLES_MLD_PROGNAME ?= mld$(EXEEXT)
|
||||
CONFIG_EXAMPLES_MLD_APPNAME ?= mld
|
||||
CONFIG_EXAMPLES_MLD_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_MLD_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = $(CONFIG_EXAMPLES_MLD_APPNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_MLD_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_MLD_STACKSIZE)
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = mld_main.c
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_MLD_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_MLD
|
||||
|
||||
include $(APPDIR)/Application.mk
|
53
examples/mld/mld.h
Normal file
53
examples/mld/mld.h
Normal file
@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
* examples/mld/mld.h
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_MLD_MLD_H
|
||||
#define __APPS_EXAMPLES_MLD_MLD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __APPS_EXAMPLES_MLD_MLD_H */
|
245
examples/mld/mld_main.c
Normal file
245
examples/mld/mld_main.c
Normal file
@ -0,0 +1,245 @@
|
||||
/****************************************************************************
|
||||
* examples/mld/mld_main.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MLD_INIT
|
||||
static const uint16_t g_host_addr[8] =
|
||||
{
|
||||
HTONS(0xfe80),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0x00ff),
|
||||
HTONS(0xfe00),
|
||||
HTONS(CONFIG_EXAMPLES_MLD_IPADDR)
|
||||
};
|
||||
|
||||
static const uint16_t g_dr_addr[8] =
|
||||
{
|
||||
HTONS(0xfe80),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0x00ff),
|
||||
HTONS(0xfe00),
|
||||
HTONS(CONFIG_EXAMPLES_MLD_DRIPADDR)
|
||||
};
|
||||
|
||||
static const uint16_t g_netmask[8] =
|
||||
{
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0xfffff),
|
||||
HTONS(0)
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint16_t g_grp_addr[8] =
|
||||
{
|
||||
HTONS(0xfc00),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(0),
|
||||
HTONS(CONFIG_EXAMPLES_MLD_GRPADDR)
|
||||
};
|
||||
|
||||
static const uint8_t g_garbage[] = "abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* mld_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int mld_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct sockaddr_in6 host;
|
||||
struct sockaddr_in6 mcast;
|
||||
struct ipv6_mreq mrec;
|
||||
int sockfd;
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MLD_INIT
|
||||
#ifdef CONFIG_EXAMPLES_MLD_NOMAC
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#endif
|
||||
|
||||
printf("Configuring Ethernet...\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MLD_NOMAC
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
|
||||
mac[0] = 0x00;
|
||||
mac[1] = 0xe0;
|
||||
mac[2] = 0xde;
|
||||
mac[3] = 0xad;
|
||||
mac[4] = 0xbe;
|
||||
mac[5] = 0xef;
|
||||
netlib_setmacaddr("eth0", mac);
|
||||
#endif
|
||||
|
||||
/* Set up our (fixed) host address */
|
||||
|
||||
netlib_set_ipv6addr("eth0", (FAR const struct in6_addr *)g_host_addr);
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
netlib_set_dripv6addr("eth0", (FAR const struct in6_addr *)g_dr_addr);
|
||||
|
||||
/* Setup the subnet mask */
|
||||
|
||||
netlib_set_ipv6netmask("eth0", (FAR const struct in6_addr *)g_netmask);
|
||||
|
||||
/* Bring the network up */
|
||||
|
||||
netlib_ifup("eth0");
|
||||
#endif /* CONFIG_EXAMPLES_MLD_INIT */
|
||||
|
||||
memset(&host, 0, sizeof(struct sockaddr_in6));
|
||||
host.sin6_family = AF_INET6;
|
||||
sockfd = socket(PF_INET6, SOCK_DGRAM, 0);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: socket() failed: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
/* Join the group */
|
||||
|
||||
printf("Join group...\n");
|
||||
|
||||
memcpy(mrec.ipv6mr_multiaddr.s6_addr16, g_grp_addr, sizeof(struct in6_addr));
|
||||
mrec.ipv6mr_interface = if_nametoindex("eth0");
|
||||
|
||||
ret = setsockopt(sockfd, SOL_IPV6, IPV6_JOIN_GROUP, (FAR void *)&mrec,
|
||||
sizeof(struct ipv6_mreq));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: setsockopt() failed: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
/* Wait a while */
|
||||
|
||||
printf("Wait a bit...\n");
|
||||
sleep(5);
|
||||
|
||||
/* Send a garbage packet */
|
||||
|
||||
memset(&mcast, 0, sizeof(struct sockaddr_in6));
|
||||
mcast.sin6_family = AF_INET6;
|
||||
mcast.sin6_port = HTONS(0x4321);
|
||||
memcpy(mcast.sin6_addr.s6_addr16, g_grp_addr, sizeof(struct in6_addr));
|
||||
|
||||
ret = sendto(sockfd, g_garbage, sizeof(g_garbage), 0,
|
||||
(FAR struct sockaddr *)&mcast, sizeof(struct sockaddr_in6));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sendto() failed: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
/* Wait a while */
|
||||
|
||||
printf("Wait a bit...\n");
|
||||
sleep(5);
|
||||
|
||||
/* Leave the group */
|
||||
|
||||
printf("Leave group...\n");
|
||||
ret = setsockopt(sockfd, SOL_IPV6, IPV6_LEAVE_GROUP, (FAR void *)&mrec,
|
||||
sizeof(struct ipv6_mreq));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: setsockopt() failed: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
/* Wait a while */
|
||||
|
||||
printf("Wait a bit...\n");
|
||||
sleep(5);
|
||||
printf("Exiting...\n");
|
||||
ret = EXIT_SUCCESS;
|
||||
|
||||
errout_with_socket:
|
||||
close(sockfd);
|
||||
return ret;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user