diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-22 15:30:23 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-22 15:30:23 -0600 |
commit | 2cc14127f8d9c90c14a369d0ba935b3643e254da (patch) | |
tree | ccc333f97cb6bbc925ad2f9a2216cbfb8205e4c0 /apps/examples | |
parent | 421a14767a16b25a4bd7c6cda472cb1f3e0204aa (diff) | |
download | nuttx-2cc14127f8d9c90c14a369d0ba935b3643e254da.tar.gz nuttx-2cc14127f8d9c90c14a369d0ba935b3643e254da.tar.bz2 nuttx-2cc14127f8d9c90c14a369d0ba935b3643e254da.zip |
apps/examples/udp: The UDP test example has been extend to support IPv6 domain sockets
Diffstat (limited to 'apps/examples')
-rw-r--r-- | apps/examples/nettest/Kconfig | 16 | ||||
-rw-r--r-- | apps/examples/nettest/Makefile | 13 | ||||
-rw-r--r-- | apps/examples/udp/Kconfig | 403 | ||||
-rw-r--r-- | apps/examples/udp/Makefile | 22 | ||||
-rw-r--r-- | apps/examples/udp/host.c | 1 | ||||
-rw-r--r-- | apps/examples/udp/target.c | 66 | ||||
-rw-r--r-- | apps/examples/udp/udp-client.c | 41 | ||||
-rw-r--r-- | apps/examples/udp/udp-internal.h | 14 | ||||
-rw-r--r-- | apps/examples/udp/udp-server.c | 45 |
9 files changed, 577 insertions, 44 deletions
diff --git a/apps/examples/nettest/Kconfig b/apps/examples/nettest/Kconfig index 152912f3e..d5cd9b610 100644 --- a/apps/examples/nettest/Kconfig +++ b/apps/examples/nettest/Kconfig @@ -167,7 +167,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_1 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the first of the 8-values. The default for all eight values is fc00::1. @@ -177,7 +177,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_2 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the second of the 8-values. The default for all eight values is fc00::1. @@ -187,7 +187,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_3 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the third of the 8-values. The default for all eight values is fc00::1. @@ -197,7 +197,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_4 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the fourth of the 8-values. The default for all eight values is fc00::1. @@ -207,7 +207,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_5 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the fifth of the 8-values. The default for all eight values is fc00::1. @@ -217,7 +217,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_6 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the sixth of the 8-values. The default for all eight values is fc00::1. @@ -227,7 +227,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_7 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the seventh of the 8-values. The default for all eight values is fc00::1. @@ -237,7 +237,7 @@ config EXAMPLES_NETTEST_DRIPv6ADDR_8 range 0x0 0xffff ---help--- Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP + value in host order. Each of the eight values forming the full IP address must be specified individually. This is the last of the 8-values. The default for all eight values is fc00::1. diff --git a/apps/examples/nettest/Makefile b/apps/examples/nettest/Makefile index e4fb76a23..3b79a8f35 100644 --- a/apps/examples/nettest/Makefile +++ b/apps/examples/nettest/Makefile @@ -121,18 +121,19 @@ $(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c $(HOST_OBJS): %$(HOSTOBJEXT): %.c @echo "CC: $<" - @$(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ + $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ + +config.h: $(TOPDIR)/include/nuttx/config.h + @echo "CP: $<" + $(Q) cp $< $@ $(HOST_BIN): config.h $(HOST_OBJS) @echo "LD: $@" - @$(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ - -config.h: $(TOPDIR)/include/nuttx/config.h - @cp $< $@ + $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ .built: config.h $(TARG_OBJS) $(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS)) - @touch .built + $(Q) touch .built ifeq ($(CONFIG_BUILD_KERNEL),y) $(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(TARG_MAINOBJ) diff --git a/apps/examples/udp/Kconfig b/apps/examples/udp/Kconfig index fd64d5290..eecd937b0 100644 --- a/apps/examples/udp/Kconfig +++ b/apps/examples/udp/Kconfig @@ -6,6 +6,7 @@ config EXAMPLES_UDP bool "UDP example" default n + depends on NET_UDP ---help--- Enable the UDP example @@ -15,6 +16,25 @@ config EXAMPLES_UDP_SERVER bool "Target is the server" default n +choice + prompt "IP Domain" + default EXAMPLES_UDP_IPv4 if NET_IPv4 + default EXAMPLES_UDP_IPv6 if NET_IPv6 && !NET_IPv4 + +config EXAMPLES_UDP_IPv4 + bool "IPv4" + depends on NET_IPv4 + +config EXAMPLES_UDP_IPv6 + bool "IPv6" + depends on NET_IPv6 + +endchoice # IP Domain + +if EXAMPLES_UDP_IPv4 + +comment "IPv4 addresses" + config EXAMPLES_UDP_IPADDR hex "Target IP address" default 0x0a000002 @@ -32,4 +52,387 @@ config EXAMPLES_UDP_SERVERIP default 0x0a000001 if !EXAMPLES_UDP_SERVER default 0x0a000002 if EXAMPLES_UDP_SERVER + +endif # EXAMPLES_UDP_IPv4 + +if EXAMPLES_UDP_IPv6 + +comment "Target IPv6 address" + +config EXAMPLES_UDP_IPv6ADDR_1 + hex "[0]" + default 0xfc00 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the first of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_2 + hex "[1]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the second of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_3 + hex "[2]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the third of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_4 + hex "[3]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the fourth of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_5 + hex "[4]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the fifth of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_6 + hex "[5]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the sixth of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_7 + hex "[6]" + default 0x0000 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the seventh of the 8-values. The + default for all eight values is fc00::2. + +config EXAMPLES_UDP_IPv6ADDR_8 + hex "[7]" + default 0x0002 + range 0x0 0xffff + ---help--- + Target IPv6 address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the last of the 8-values. The + default for all eight values is fc00::2. + +comment "Router IPv6 address" + +config EXAMPLES_UDP_DRIPv6ADDR_1 + hex "[0]" + default 0xfc00 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the first of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_2 + hex "[1]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the second of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_3 + hex "[2]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the third of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_4 + hex "[3]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the fourth of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_5 + hex "[4]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the fifth of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_6 + hex "[5]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the sixth of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_7 + hex "[6]" + default 0x0000 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the seventh of the + 8-values. The default for all eight values is fc00::1. + +config EXAMPLES_UDP_DRIPv6ADDR_8 + hex "[7]" + default 0x0001 + range 0x0 0xffff + ---help--- + Default router IP address (aka, Gateway). This is a 16-bit integer + value in host order. Each of the eight values forming the full IP + address must be specified individually. This is the last of the + 8-values. The default for all eight values is fc00::1. + +comment "IPv6 Network mask" + +config EXAMPLES_UDP_IPv6NETMASK_1 + hex "[0]" + default 0xfe00 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the first of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_2 + hex "[1]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the second of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_3 + hex "[2]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the third of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_4 + hex "[3]" + default 0x0000 + range 0x0 0x0000 + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the fourth of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_5 + hex "[4]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the fifth of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_6 + hex "[5]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the sixth of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_7 + hex "[6]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the seventh of the 8-values. The default for + all eight values is fe00::0. + +config EXAMPLES_UDP_IPv6NETMASK_8 + hex "[7]" + default 0x0000 + range 0x0 0xffff + ---help--- + Network mask. This is a 16-bit integer value in host order. Each + of the eight values forming the full IP address must be specified + individually. This is the eighth of the 8-values. The default for + all eight values is fe00::0. + +comment "Client IPv6 address" + +config EXAMPLES_UDP_SERVERIPv6ADDR_1 + hex "[0]" + default 0xfc00 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the first of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_2 + hex "[1]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the second of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_3 + hex "[2]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the Third of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_4 + hex "[3]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the fourth of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_5 + hex "[4]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the fifth of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_6 + hex "[5]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the sixth of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_7 + hex "[6]" + default 0x0000 + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the seventh of the 8-values. + +config EXAMPLES_UDP_SERVERIPv6ADDR_8 + hex "[7]" + default 0x0001 if !EXAMPLES_UDP_SERVER + default 0x0002 if EXAMPLES_UDP_SERVER + range 0x0 0xffff + ---help--- + IP address of the server. If the target is the server, then + EXAMPLES_UDP_SERVERIP should be the same as + EXAMPLES_UDP_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_UDP_SERVERIP is set to the + host PC IP address (possibly the gateway address, + EXAMPLES_UDP_DRIPADDR?). + + This is a 16-bit integer value in host order. Each of the eight + values forming the full IP address must be specified individually. + This is the last of the 8-values. + +endif # EXAMPLES_UDP_IPv6 endif # EXAMPLES_UDP diff --git a/apps/examples/udp/Makefile b/apps/examples/udp/Makefile index 91e34ba73..156164ee4 100644 --- a/apps/examples/udp/Makefile +++ b/apps/examples/udp/Makefile @@ -70,11 +70,7 @@ else endif endif -HOSTCFLAGS += -DCONFIG_EXAMPLES_UDP_HOST=1 -ifeq ($(CONFIG_EXAMPLES_UDP_SERVER),y) -HOSTCFLAGS += -DCONFIG_EXAMPLES_UDP_SERVER=1 \ - -DCONFIG_EXAMPLES_UDP_SERVERIP="$(CONFIG_EXAMPLES_UDP_SERVERIP)" -endif +HOSTCFLAGS += -DEXAMPLES_UDP_HOST=1 HOST_SRCS = host.c ifeq ($(CONFIG_EXAMPLES_UDP_SERVER),y) @@ -114,13 +110,18 @@ $(TARG_BIN): $(TARG_OBJS) $(HOST_BIN) $(call ARCHIVE, $@, $(TARG_OBJS)) $(HOST_OBJS): %.o: %.c - $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ + @echo "CC: $<" + $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ + +config.h: $(TOPDIR)/include/nuttx/config.h + @echo "CP: $<" + $(Q) cp $< $@ -$(HOST_BIN): $(HOST_OBJS) - $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ +$(HOST_BIN): config.h $(HOST_OBJS) + $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ -.built: $(TARG_BIN) $(HOST_BIN) - @touch .built +.built: config.h $(TARG_BIN) $(HOST_BIN) + $(Q) touch .built ifeq ($(CONFIG_BUILD_KERNEL),y) $(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(TARG_MAINOBJ) @@ -148,6 +149,7 @@ clean: $(call DELFILE, $(TARG_BIN)) $(call DELFILE, $(HOST_BIN)) $(call DELFILE, *.dSYM) + $(call DELFILE, config.h) $(call CLEAN) distclean: clean diff --git a/apps/examples/udp/host.c b/apps/examples/udp/host.c index e103acd8c..6ea487712 100644 --- a/apps/examples/udp/host.c +++ b/apps/examples/udp/host.c @@ -37,6 +37,7 @@ * Included Files ****************************************************************************/ +#include "config.h" #include "udp-internal.h" /**************************************************************************** diff --git a/apps/examples/udp/target.c b/apps/examples/udp/target.c index 8b72978f3..711fe0d02 100644 --- a/apps/examples/udp/target.c +++ b/apps/examples/udp/target.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udp/target.c * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -37,7 +37,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> +#include "config.h" + #include <stdio.h> #include <debug.h> @@ -56,6 +57,50 @@ * Private Data ****************************************************************************/ +#ifdef CONFIG_EXAMPLES_UDP_IPv6 +/* Our host IPv6 address */ + +static const uint16_t g_ipv6_hostaddr[8] = +{ + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_1), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_2), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_3), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_4), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_5), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_6), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_7), + HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_8), +}; + +/* Default routine IPv6 address */ + +static const uint16_t g_ipv6_draddr[8] = +{ + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_1), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_2), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_3), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_4), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_5), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_6), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_7), + HTONS(CONFIG_EXAMPLES_UDP_DRIPv6ADDR_8), +}; + +/* IPv6 netmask */ + +static const uint16_t g_ipv6_netmask[8] = +{ + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_1), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_2), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_3), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_4), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_5), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_6), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_7), + HTONS(CONFIG_EXAMPLES_UDP_IPv6NETMASK_8), +}; +#endif /* CONFIG_EXAMPLES_UDP_IPv6 */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,6 +115,22 @@ int main(int argc, FAR char *argv[]) int udp_main(int argc, char *argv[]) #endif { +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + /* Set up our host address */ + + netlib_set_ipv6addr("eth0", + (FAR const struct in6_addr *)g_ipv6_hostaddr); + + /* Set up the default router address */ + + netlib_set_dripv6addr("eth0", + (FAR const struct in6_addr *)g_ipv6_draddr); + + /* Setup the subnet mask */ + + netlib_set_ipv6netmask("eth0", + (FAR const struct in6_addr *)g_ipv6_netmask); +#else struct in_addr addr; /* Set up our host address */ @@ -86,6 +147,7 @@ int udp_main(int argc, char *argv[]) addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_NETMASK); netlib_set_ipv4netmask("eth0", &addr); +#endif #ifdef CONFIG_EXAMPLES_UDP_SERVER recv_server(); diff --git a/apps/examples/udp/udp-client.c b/apps/examples/udp/udp-client.c index d705baf16..416a2b4ea 100644 --- a/apps/examples/udp/udp-client.c +++ b/apps/examples/udp/udp-client.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udp/udp-client.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -37,6 +37,8 @@ * Included Files ****************************************************************************/ +#include "config.h" + #include <sys/types.h> #include <sys/socket.h> @@ -77,15 +79,20 @@ static inline void fill_buffer(unsigned char *buf, int offset) void send_client(void) { +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + struct sockaddr_in6 server; +#else struct sockaddr_in server; +#endif unsigned char outbuf[SENDSIZE]; + socklen_t addrlen; int sockfd; int nbytes; int offset; /* Create a new UDP socket */ - sockfd = socket(PF_INET, SOCK_DGRAM, 0); + sockfd = socket(PF_INETX, SOCK_DGRAM, 0); if (sockfd < 0) { printf("client socket failure %d\n", errno); @@ -100,15 +107,35 @@ void send_client(void) fill_buffer(outbuf, offset); - /* Send the message */ + /* Set up the server address */ + +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + server.sin6_family = AF_INET6; + server.sin6_port = HTONS(PORTNO); + + server.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_1); + server.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_2); + server.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_3); + server.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_4); + server.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_5); + server.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_6); + server.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_7); + server.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_8); - server.sin_family = AF_INET; - server.sin_port = HTONS(PORTNO); - server.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_SERVERIP); + addrlen = sizeof(struct sockaddr_in6); +#else + server.sin_family = AF_INET; + server.sin_port = HTONS(PORTNO); + server.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_SERVERIP); + + addrlen = sizeof(struct sockaddr_in); +#endif + + /* Send the message */ printf("client: %d. Sending %d bytes\n", offset, SENDSIZE); nbytes = sendto(sockfd, outbuf, SENDSIZE, 0, - (struct sockaddr*)&server, sizeof(struct sockaddr_in)); + (struct sockaddr*)&server, addrlen); printf("client: %d. Sent %d bytes\n", offset, nbytes); if (nbytes < 0) diff --git a/apps/examples/udp/udp-internal.h b/apps/examples/udp/udp-internal.h index 9dee4162d..909d5091c 100644 --- a/apps/examples/udp/udp-internal.h +++ b/apps/examples/udp/udp-internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udp/udp-internal.h * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ * Included Files ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_UDP_HOST +#ifdef EXAMPLES_UDP_HOST #else # include <debug.h> #endif @@ -51,13 +51,21 @@ * Definitions ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_UDP_HOST +#ifdef EXAMPLES_UDP_HOST /* HTONS/L macros are unique to uIP */ # define HTONS(a) htons(a) # define HTONL(a) htonl(a) #endif +#ifdef CONFIG_EXAMPLES_UDP_IPv6 +# define AF_INETX AF_INET6 +# define PF_INETX PF_INET6 +#else +# define AF_INETX AF_INET +# define PF_INETX PF_INET +#endif + #define PORTNO 5471 #define ASCIISIZE (0x7f - 0x20) diff --git a/apps/examples/udp/udp-server.c b/apps/examples/udp/udp-server.c index f06e67593..03c44e184 100644 --- a/apps/examples/udp/udp-server.c +++ b/apps/examples/udp/udp-server.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udp/udp-server.c * - * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -37,12 +37,15 @@ * Included Files ****************************************************************************/ +#include "config.h" + #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <string.h> #include <errno.h> #include <arpa/inet.h> @@ -73,6 +76,7 @@ static inline int check_buffer(unsigned char *buf) ret = 0; } } + return ret; } @@ -82,19 +86,25 @@ static inline int check_buffer(unsigned char *buf) void recv_server(void) { +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + struct sockaddr_in6 server; + struct sockaddr_in6 client; +#else struct sockaddr_in server; struct sockaddr_in client; in_addr_t tmpaddr; +#endif unsigned char inbuf[1024]; + socklen_t addrlen; + socklen_t recvlen; int sockfd; int nbytes; int optval; int offset; - socklen_t addrlen; /* Create a new UDP socket */ - sockfd = socket(PF_INET, SOCK_DGRAM, 0); + sockfd = socket(PF_INETX, SOCK_DGRAM, 0); if (sockfd < 0) { printf("server: socket failure: %d\n", errno); @@ -112,11 +122,21 @@ void recv_server(void) /* Bind the socket to a local address */ +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + server.sin6_family = AF_INET6; + server.sin6_port = HTONS(PORTNO); + memset(&server.sin6_addr, 0, sizeof(struct in6_addr)); + + addrlen = sizeof(struct sockaddr_in6); +#else server.sin_family = AF_INET; server.sin_port = HTONS(PORTNO); - server.sin_addr.s_addr = HTONL(INADDR_ANY); + server.sin_addr.s_addr = HTONL(INADDR_ANY);; + + addrlen = sizeof(struct sockaddr_in); +#endif - if (bind(sockfd, (struct sockaddr*)&server, sizeof(struct sockaddr_in)) < 0) + if (bind(sockfd, (struct sockaddr*)&server, addrlen) < 0) { printf("server: bind failure: %d\n", errno); exit(1); @@ -127,17 +147,26 @@ void recv_server(void) for (offset = 0; offset < 256; offset++) { printf("server: %d. Receiving up 1024 bytes\n", offset); - addrlen = sizeof(struct sockaddr_in); + recvlen = addrlen; nbytes = recvfrom(sockfd, inbuf, 1024, 0, - (struct sockaddr*)&client, &addrlen); + (struct sockaddr*)&client, &recvlen); +#ifdef CONFIG_EXAMPLES_UDP_IPv6 + printf("server: %d. Received %d bytes from %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x port %d\n", + offset, nbytes, + client.sin6_addr.s6_addr16[0], client.sin6_addr.s6_addr16[1], + client.sin6_addr.s6_addr16[2], client.sin6_addr.s6_addr16[3], + client.sin6_addr.s6_addr16[4], client.sin6_addr.s6_addr16[5], + client.sin6_addr.s6_addr16[6], client.sin6_addr.s6_addr16[7], + ntohs(client.sin6_port)); +#else tmpaddr = ntohl(client.sin_addr.s_addr); printf("server: %d. Received %d bytes from %d.%d.%d.%d:%d\n", offset, nbytes, tmpaddr >> 24, (tmpaddr >> 16) & 0xff, (tmpaddr >> 8) & 0xff, tmpaddr & 0xff, ntohs(client.sin_port)); - +#endif if (nbytes < 0) { printf("server: %d. recv failed: %d\n", offset, errno); |