apps/examples/nettest: Update test so that it can be used to test IPv6 TCP sockets

This commit is contained in:
Gregory Nutt 2015-01-20 18:12:27 -06:00
parent 27b3913c92
commit 8c02b30555
8 changed files with 545 additions and 24 deletions

View File

@ -2,6 +2,7 @@
/.depend /.depend
/.built /.built
/host /host
/config.h
/*.asm /*.asm
/*.obj /*.obj
/*.rel /*.rel

View File

@ -30,6 +30,25 @@ config EXAMPLES_NETTEST_NOMAC
bool "Use Canned MAC Address" bool "Use Canned MAC Address"
default n default n
choice
prompt "IP Domain"
default EXAMPLES_NETTEST_IPv4 if NET_IPv4
default EXAMPLES_NETTEST_IPv6 if NET_IPv6 && !NET_IPv4
config EXAMPLES_NETTEST_IPv4
bool "IPv4"
depends on NET_IPv4
config EXAMPLES_NETTEST_IPv6
bool "IPv6"
depends on NET_IPv6
endchoice # IP Domain
if EXAMPLES_NETTEST_IPv4
comment "IPv4 addresses"
config EXAMPLES_NETTEST_IPADDR config EXAMPLES_NETTEST_IPADDR
hex "Target IP address" hex "Target IP address"
default 0x0a000002 default 0x0a000002
@ -54,4 +73,386 @@ config EXAMPLES_NETTEST_CLIENTIP
host PC IP address (possibly the gateway address, host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_DRIPADDR?). EXAMPLES_NETTEST_DRIPADDR?).
endif endif # EXAMPLES_NETTEST_IPv4
if EXAMPLES_NETTEST_IPv6
comment "Target IPv6 address"
config EXAMPLES_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_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_NETTEST_CLIENTIPv6ADDR_1
hex "[0]"
default 0xfc00
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_2
hex "[1]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_3
hex "[2]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_4
hex "[3]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_5
hex "[4]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_6
hex "[5]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_7
hex "[6]"
default 0x0000
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_CLIENTIPv6ADDR_8
hex "[7]"
default 0x0001 if !EXAMPLES_NETTEST_SERVER
default 0x0002 if EXAMPLES_NETTEST_SERVER
range 0x0 0xffff
---help---
IP address of the client. If the target is the client, then
EXAMPLES_NETTEST_CLIENTIP should be the same as
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
host PC IP address (possibly the gateway address,
EXAMPLES_NETTEST_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_NETTEST_IPv6
endif # EXAMPLES_NETTEST

View File

@ -123,11 +123,14 @@ $(HOST_OBJS): %$(HOSTOBJEXT): %.c
@echo "CC: $<" @echo "CC: $<"
@$(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ @$(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
$(HOST_BIN): $(HOST_OBJS) $(HOST_BIN): config.h $(HOST_OBJS)
@echo "LD: $@" @echo "LD: $@"
@$(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ @$(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
.built: $(TARG_OBJS) config.h: $(TOPDIR)/include/nuttx/config.h
@cp $< $@
.built: config.h $(TARG_OBJS)
$(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS)) $(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS))
@touch .built @touch .built
@ -164,6 +167,7 @@ clean:
$(call DELFILE, $(HOST_BIN)) $(call DELFILE, $(HOST_BIN))
$(call DELFILE, .built) $(call DELFILE, .built)
$(call DELFILE, *.dSYM) $(call DELFILE, *.dSYM)
$(call DELFILE, config.h)
$(call CLEAN) $(call CLEAN)
distclean: clean distclean: clean

View File

@ -37,6 +37,7 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "config.h"
#include "nettest.h" #include "nettest.h"
/**************************************************************************** /****************************************************************************

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/nettest/nettest.c * examples/nettest/nettest.c
* *
* Copyright (C) 2007, 2009-2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009-2011, 2015 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
@ -37,7 +37,8 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include "config.h"
//#include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -59,6 +60,50 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
/* Our host IPv6 address */
static const uint16_t g_ipv6_hostaddr[8] =
{
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_1),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_2),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_3),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_4),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_5),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_6),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_7),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_8),
};
/* Default routine IPv6 address */
static const uint16_t g_ipv6_draddr[8] =
{
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_1),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_2),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_3),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_4),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_5),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_6),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_7),
HTONS(CONFIG_EXAMPLES_NETTEST_DRIPv6ADDR_8),
};
/* IPv6 netmask */
static const uint16_t g_ipv6_netmask[8] =
{
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_1),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_2),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_3),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_4),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_5),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_6),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_7),
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_8),
};
#endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -73,7 +118,9 @@ int main(int argc, FAR char *argv[])
int nettest_main(int argc, char *argv[]) int nettest_main(int argc, char *argv[])
#endif #endif
{ {
#ifdef CONFIG_EXAMPLES_NETTEST_IPv4
struct in_addr addr; struct in_addr addr;
#endif
#ifdef CONFIG_EXAMPLES_NETTEST_NOMAC #ifdef CONFIG_EXAMPLES_NETTEST_NOMAC
uint8_t mac[IFHWADDRLEN]; uint8_t mac[IFHWADDRLEN];
#endif #endif
@ -87,23 +134,40 @@ int nettest_main(int argc, char *argv[])
mac[3] = 0xad; mac[3] = 0xad;
mac[4] = 0xbe; mac[4] = 0xbe;
mac[5] = 0xef; mac[5] = 0xef;
netlib_setmacaddr("eth0", mac); netlib_setmacaddr(EXAMPLES_NETTEST_IPv6NETMASK_, mac);
#endif #endif
#ifdef CONFIG_EXAMPLES_NETTEST_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
/* Set up our host address */ /* Set up our host address */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR);
netlib_set_ipv4addr("eth0", &addr); netlib_set_ipv4addr(EXAMPLES_NETTEST_IPv6NETMASK_, &addr);
/* Set up the default router address */ /* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR);
netlib_set_dripv4addr("eth0", &addr); netlib_set_dripv4addr(EXAMPLES_NETTEST_IPv6NETMASK_, &addr);
/* Setup the subnet mask */ /* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK);
netlib_set_ipv4netmask("eth0", &addr); netlib_set_ipv4netmask(EXAMPLES_NETTEST_IPv6NETMASK_, &addr);
#endif
#ifdef CONFIG_EXAMPLES_NETTEST_SERVER #ifdef CONFIG_EXAMPLES_NETTEST_SERVER
recv_server(); recv_server();

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/nettest/nettest.h * examples/nettest/nettest.h
* *
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2015 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
@ -48,7 +48,7 @@
#endif #endif
/**************************************************************************** /****************************************************************************
* Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifdef NETTEST_HOST #ifdef NETTEST_HOST
@ -67,6 +67,14 @@
# else # else
# undef NETTEST_HAVE_SOLINGER # undef NETTEST_HAVE_SOLINGER
# endif # endif
#endif /* NETTEST_HOST */
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
# define AF_INETX AF_INET6
# define PF_INETX PF_INET6
#else
# define AF_INETX AF_INET
# define PF_INETX PF_INET
#endif #endif
#define PORTNO 5471 #define PORTNO 5471

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/nettest/nettest-client.c * examples/nettest/nettest-client.c
* *
* Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2011-2012, 2015 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
@ -37,6 +37,8 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "config.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -56,12 +58,17 @@
void send_client(void) void send_client(void)
{ {
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
struct sockaddr_in6 myaddr;
#else
struct sockaddr_in myaddr; struct sockaddr_in myaddr;
#endif
char *outbuf; char *outbuf;
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE #ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
char *inbuf; char *inbuf;
#endif #endif
int sockfd; int sockfd;
socklen_t addrlen;
int nbytessent; int nbytessent;
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE #ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
int nbytesrecvd; int nbytesrecvd;
@ -86,7 +93,7 @@ void send_client(void)
/* Create a new TCP socket */ /* Create a new TCP socket */
sockfd = socket(PF_INET, SOCK_STREAM, 0); sockfd = socket(PF_INETX, SOCK_STREAM, 0);
if (sockfd < 0) if (sockfd < 0)
{ {
printf("client socket failure %d\n", errno); printf("client socket failure %d\n", errno);
@ -95,20 +102,35 @@ void send_client(void)
/* Connect the socket to the server */ /* Connect the socket to the server */
myaddr.sin_family = AF_INET; #ifdef CONFIG_EXAMPLES_NETTEST_IPv6
myaddr.sin_port = HTONS(PORTNO); myaddr.sin6_family = AF_INET6;
#if 0 myaddr.sin6_port = HTONS(PORTNO);
myaddr.sin_addr.s_addr = HTONL(INADDR_LOOPBACK);
myaddr.sin6_addr.s6_addr16[0] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1);
myaddr.sin6_addr.s6_addr16[1] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2);
myaddr.sin6_addr.s6_addr16[2] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3);
myaddr.sin6_addr.s6_addr16[3] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_4);
myaddr.sin6_addr.s6_addr16[4] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5);
myaddr.sin6_addr.s6_addr16[5] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6);
myaddr.sin6_addr.s6_addr16[6] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7);
myaddr.sin6_addr.s6_addr16[7] = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8);
addrlen = sizeof(struct sockaddr_in6);
#else #else
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP); myaddr.sin_family = AF_INET;
myaddr.sin_port = HTONS(PORTNO);
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP);
addrlen = sizeof(struct sockaddr_in);
#endif #endif
printf("client: Connecting...\n"); printf("client: Connecting...\n");
if (connect( sockfd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0) if (connect( sockfd, (struct sockaddr*)&myaddr, addrlen) < 0)
{ {
printf("client: connect failure: %d\n", errno); printf("client: connect failure: %d\n", errno);
goto errout_with_socket; goto errout_with_socket;
} }
printf("client: Connected\n"); printf("client: Connected\n");
/* Initialize the buffer */ /* Initialize the buffer */
@ -140,6 +162,7 @@ void send_client(void)
nbytessent, SENDSIZE); nbytessent, SENDSIZE);
goto errout_with_socket; goto errout_with_socket;
} }
printf("Sent %d bytes\n", nbytessent); printf("Sent %d bytes\n", nbytessent);
} }
#else #else
@ -176,6 +199,7 @@ void send_client(void)
printf("client: The server closed the connection\n"); printf("client: The server closed the connection\n");
goto errout_with_socket; goto errout_with_socket;
} }
totalbytesrecvd += nbytesrecvd; totalbytesrecvd += nbytesrecvd;
printf("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE); printf("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE);
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/nettest/nettest-server.c * examples/nettest/nettest-server.c
* *
* Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2011-2012, 2015 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
@ -37,12 +37,15 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "config.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -56,7 +59,11 @@
void recv_server(void) void recv_server(void)
{ {
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
struct sockaddr_in6 myaddr;
#else
struct sockaddr_in myaddr; struct sockaddr_in myaddr;
#endif
#ifdef NETTEST_HAVE_SOLINGER #ifdef NETTEST_HAVE_SOLINGER
struct linger ling; struct linger ling;
#endif #endif
@ -82,10 +89,9 @@ void recv_server(void)
exit(1); exit(1);
} }
/* Create a new TCP socket */ /* Create a new TCP socket */
listensd = socket(PF_INET, SOCK_STREAM, 0); listensd = socket(PF_INETX, SOCK_STREAM, 0);
if (listensd < 0) if (listensd < 0)
{ {
printf("server: socket failure: %d\n", errno); printf("server: socket failure: %d\n", errno);
@ -103,11 +109,21 @@ void recv_server(void)
/* Bind the socket to a local address */ /* Bind the socket to a local address */
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
myaddr.sin6_family = AF_INET6;
myaddr.sin6_port = HTONS(PORTNO);
memset(&myaddr.sin6_addr, 0, sizeof(struct in6_addr));
addrlen = sizeof(struct sockaddr_in6);
#else
myaddr.sin_family = AF_INET; myaddr.sin_family = AF_INET;
myaddr.sin_port = HTONS(PORTNO); myaddr.sin_port = HTONS(PORTNO);
myaddr.sin_addr.s_addr = INADDR_ANY; myaddr.sin_addr.s_addr = INADDR_ANY;
if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0) addrlen = sizeof(struct sockaddr_in);
#endif
if (bind(listensd, (struct sockaddr*)&myaddr, addrlen) < 0)
{ {
printf("server: bind failure: %d\n", errno); printf("server: bind failure: %d\n", errno);
goto errout_with_listensd; goto errout_with_listensd;
@ -124,13 +140,13 @@ void recv_server(void)
/* Accept only one connection */ /* Accept only one connection */
printf("server: Accepting connections on port %d\n", PORTNO); printf("server: Accepting connections on port %d\n", PORTNO);
addrlen = sizeof(struct sockaddr_in);
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
if (acceptsd < 0) if (acceptsd < 0)
{ {
printf("server: accept failure: %d\n", errno); printf("server: accept failure: %d\n", errno);
goto errout_with_listensd; goto errout_with_listensd;
} }
printf("server: Connection accepted -- receiving\n"); printf("server: Connection accepted -- receiving\n");
/* Configure to "linger" until all data is sent when the socket is closed */ /* Configure to "linger" until all data is sent when the socket is closed */
@ -165,6 +181,7 @@ void recv_server(void)
printf("Received %d bytes\n", nbytesread); printf("Received %d bytes\n", nbytesread);
} }
#else #else
/* Receive canned message */ /* Receive canned message */
totalbytesread = 0; totalbytesread = 0;
@ -219,6 +236,7 @@ void recv_server(void)
printf("server: send failed: %d\n", errno); printf("server: send failed: %d\n", errno);
goto errout_with_acceptsd; goto errout_with_acceptsd;
} }
printf("server: Sent %d bytes\n", nbytessent); printf("server: Sent %d bytes\n", nbytessent);
/* If this platform only does abortive disconnects, then wait a bit to get the /* If this platform only does abortive disconnects, then wait a bit to get the