From 187c8ccafca5163c8e404e956632c09c0f3dbd6e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Nov 2014 08:20:25 -0600 Subject: apps/examples/bridge: Add host-side test driver --- apps/examples/bridge/.gitignore | 4 + apps/examples/bridge/Kconfig | 16 +++ apps/examples/bridge/Makefile | 90 ++++++++----- apps/examples/bridge/bridge_main.c | 17 ++- apps/examples/bridge/host_main.c | 253 +++++++++++++++++++++++++++++++++++++ apps/examples/bridge/host_net1.c | 96 ++++++++++++++ apps/examples/bridge/host_net2.c | 95 ++++++++++++++ 7 files changed, 537 insertions(+), 34 deletions(-) create mode 100644 apps/examples/bridge/host_main.c create mode 100644 apps/examples/bridge/host_net1.c create mode 100644 apps/examples/bridge/host_net2.c (limited to 'apps') diff --git a/apps/examples/bridge/.gitignore b/apps/examples/bridge/.gitignore index fa1ec7579..67b2dbc9d 100644 --- a/apps/examples/bridge/.gitignore +++ b/apps/examples/bridge/.gitignore @@ -1,6 +1,10 @@ /Make.dep /.depend /.built +/bridge_config.h +/host1 +/host2 +/*.exe /*.asm /*.obj /*.rel diff --git a/apps/examples/bridge/Kconfig b/apps/examples/bridge/Kconfig index bfcf9e7ed..facd5b185 100644 --- a/apps/examples/bridge/Kconfig +++ b/apps/examples/bridge/Kconfig @@ -74,6 +74,8 @@ config EXAMPLES_BRIDGE_NET1_IPADDR hex "IP address" default 0x0a000002 depends on !EXAMPLES_BRIDGE_NET1_DHCPC + ---help--- + IP address of network 1 for the target config EXAMPLES_BRIDGE_NET1_DRIPADDR hex "Default Router IP address (Gateway)" @@ -85,6 +87,12 @@ config EXAMPLES_BRIDGE_NET1_NETMASK endif # !NSH_BUILTIN_APPS +config EXAMPLES_BRIDGE_NET1_IPHOST + hex "Host IP address" + default 0x0a000001 + ---help--- + IP address of network 1 for the host + config EXAMPLES_BRIDGE_NET1_STACKSIZE int "Network 1 daemon stacksize" default 2048 @@ -148,6 +156,8 @@ config EXAMPLES_BRIDGE_NET2_IPADDR hex "IP address" default 0x0a000003 depends on !EXAMPLES_BRIDGE_NET2_DHCPC + ---help--- + IP address of network 2 for the target config EXAMPLES_BRIDGE_NET2_DRIPADDR hex "Default Router IP address (Gateway)" @@ -159,6 +169,12 @@ config EXAMPLES_BRIDGE_NET2_NETMASK endif # !NSH_BUILTIN_APPS +config EXAMPLES_BRIDGE_NET2_IPHOST + hex "Host IP address" + default 0x0a000001 + ---help--- + IP address of network 2 for the host + config EXAMPLES_BRIDGE_NET2_STACKSIZE int "Network 2 daemon stacksize" default 2048 diff --git a/apps/examples/bridge/Makefile b/apps/examples/bridge/Makefile index 62521e46c..c9fd5200c 100644 --- a/apps/examples/bridge/Makefile +++ b/apps/examples/bridge/Makefile @@ -40,43 +40,54 @@ include $(APPDIR)/Make.defs # Discover built-in application info -APPNAME = bridge -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +TARG_APPNAME = bridge +TARG_PRIORITY = SCHED_PRIORITY_DEFAULT +TARG_STACKSIZE = 2048 -ASRCS = -CSRCS = +TARG_ASRCS = +TARG_CSRCS = MAINSRC = bridge_main.c -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) -MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) +TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT)) +TARG_COBJS = $(TARG_CSRCS:.c=$(OBJEXT)) +TARG_MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) -OBJS = $(AOBJS) $(COBJS) +TARG_SRCS = $(TARG_ASRCS) $(TARG_CSRCS) $(MAINSRC) +TARG_OBJS = $(TARG_AOBJS) $(TARG_COBJS) ifneq ($(CONFIG_BUILD_KERNEL),y) - OBJS += $(MAINOBJ) + TARG_OBJS += $(TARG_MAINOBJ) endif +HOST_SRCS1 = host_net1.c +HOST_SRCS2 = host_net2.c +HOST_SRCS = $(HOST_SRCS1) $(HOST_SRCS2) + +HOST_OBJS1 = $(HOST_SRCS1:.c=.o) +HOST_OBJS2 = $(HOST_SRCS2:.c=.o) +HOST_OBJS = $(HOST_OBJS1) $(HOST_OBJS2) + +HOST_BIN1 = host1 +HOST_BIN2 = host2 + ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) + TARG_BIN = ..\..\libapps$(LIBEXT) else ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) + TARG_BIN = ..\\..\\libapps$(LIBEXT) else - BIN = ../../libapps$(LIBEXT) + TARG_BIN = ../../libapps$(LIBEXT) endif endif ifeq ($(WINTOOL),y) - INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" + TARG_INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" else - INSTALL_DIR = $(BIN_DIR) + TARG_INSTALL_DIR = $(BIN_DIR) endif CONFIG_EXAMPLE_BRIDGE_PROGNAME ?= bridge$(EXEEXT) -PROGNAME = $(CONFIG_EXAMPLE_BRIDGE_PROGNAME) +TARG_PROGNAME = $(CONFIG_EXAMPLE_BRIDGE_PROGNAME) ROOTDEPPATH = --dep-path . @@ -87,23 +98,37 @@ VPATH = all: .built .PHONY: clean depend distclean -$(AOBJS): %$(OBJEXT): %.S +$(TARG_AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) -$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c +$(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) +$(HOST_OBJS): %.o: %.c + $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ + +$(TARG_BIN): $(TARG_OBJS) + $(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS)) + +bridge_config.h: $(TOPDIR)/include/nuttx/config.h + cp $(TOPDIR)/include/nuttx/config.h bridge_config.h + +$(HOST_BIN1): bridge_config.h $(HOST_OBJS1) + $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS1) -o $@ + +$(HOST_BIN2): bridge_config.h $(HOST_OBJS2) + $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS2) -o $@ + +.built: $(TARG_BIN) $(HOST_BIN1) $(HOST_BIN2) @touch .built ifeq ($(CONFIG_BUILD_KERNEL),y) -$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) - @echo "LD: $(PROGNAME)" - $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) - $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) +$(BIN_DIR)$(DELIM)$(TARG_PROGNAME): $(TARG_OBJS) $(TARG_MAINOBJ) + @echo "LD: $(TARG_PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(TARG_INSTALL_DIR)$(DELIM)$(TARG_PROGNAME) $(ARCHCRT0OBJ) $(TARG_MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(TARG_INSTALL_DIR)$(DELIM)$(TARG_PROGNAME) -install: $(BIN_DIR)$(DELIM)$(PROGNAME) +install: $(BIN_DIR)$(DELIM)$(TARG_PROGNAME) else install: @@ -111,26 +136,29 @@ install: endif ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) +$(BUILTIN_REGISTRY)$(DELIM)$(TARG_APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(TARG_APPNAME),$(TARG_PRIORITY),$(TARG_STACKSIZE),$(TARG_APPNAME)_main) -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +context: $(BUILTIN_REGISTRY)$(DELIM)$(TARG_APPNAME)_main.bdat else context: endif -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep +.depend: Makefile $(TARG_SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(TARG_SRCS) >Make.dep @touch $@ depend: .depend clean: $(call DELFILE, .built) + $(call DELFILE, $(HOST_BIN1)) + $(call DELFILE, $(HOST_BIN2)) $(call CLEAN) distclean: clean $(call DELFILE, Make.dep) $(call DELFILE, .depend) + $(call DELFILE, bridge_config.h) -include Make.dep diff --git a/apps/examples/bridge/bridge_main.c b/apps/examples/bridge/bridge_main.c index b7062f643..7608b9a35 100644 --- a/apps/examples/bridge/bridge_main.c +++ b/apps/examples/bridge/bridge_main.c @@ -63,9 +63,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define BRIDGE_MAXLINE 64 -#define BRIDGE_POLLTIMEOUT 10000 - /**************************************************************************** * Private Data ****************************************************************************/ @@ -192,6 +189,13 @@ printf("NET1: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET1_IFNAME); g_net1_ipaddr = HTONL(CONFIG_EXAMPLES_BRIDGE_NET1_IPADDR); #endif /* CONFIG_EXAMPLES_BRIDGE_NET1_DHCPC */ + +#else /* CONFIG_NSH_BUILTIN_APPS */ + /* Hmmm.. there is an issue here. Where do we get the IP address if we + * are a builtin in application? + */ +# warning Missing logic + #endif /* CONFIG_NSH_BUILTIN_APPS */ return OK; @@ -310,6 +314,13 @@ printf("NET2: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET2_IFNAME); g_net2_ipaddr = HTONL(CONFIG_EXAMPLES_BRIDGE_NET2_IPADDR); #endif /* CONFIG_EXAMPLES_BRIDGE_NET2_DHCPC */ + +#else /* CONFIG_NSH_BUILTIN_APPS */ + /* Hmmm.. there is an issue here. Where do we get the IP address if we + * are a builtin in application? + */ +# warning Missing logic + #endif /* CONFIG_NSH_BUILTIN_APPS */ return OK; diff --git a/apps/examples/bridge/host_main.c b/apps/examples/bridge/host_main.c new file mode 100644 index 000000000..f1fa8c7ec --- /dev/null +++ b/apps/examples/bridge/host_main.c @@ -0,0 +1,253 @@ +/**************************************************************************** + * examples/bridge/host_main.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * + * Authors: Gregory Nutt + * + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint8_t g_sndmessage[] = MESSAGE; +static uint8_t g_rdbuffer[EXAMPLES_BRIDGE_SEND_IOBUFIZE]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * bridge_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + struct sockaddr_in recvaddr; + struct sockaddr_in listenaddr; + struct sockaddr_in sendaddr; + socklen_t addrlen; + in_addr_t tmpaddr; + ssize_t nrecvd; + ssize_t nsent; + int optval; + int recvsd; + int sndsd; + int i; + int j; + + /* Create a UDP send socket */ + + printf(LABEL "Create send socket\n"); + + sndsd = socket(PF_INET, SOCK_DGRAM, 0); + if (sndsd < 0) + { + fprintf(stderr, LABEL "ERROR: Failed to create send socket: %d\n", errno); + return EXIT_FAILURE; + } + + /* Set socket to reuse address */ + + optval = 1; + if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) + { + fprintf(stderr, LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); + goto errout_with_sendsd; + } + + /* Bind the socket to a local address */ + + sendaddr.sin_family = AF_INET; + sendaddr.sin_port = htons(EXAMPLES_BRIDGE_SEND_SNDPORT); + sendaddr.sin_addr.s_addr = htonl(EXAMPLES_BRIDGE_SEND_IPHOST); + + if (bind(sndsd, (struct sockaddr*)&sendaddr, sizeof(struct sockaddr_in)) < 0) + { + printf(LABEL "bind failure: %d\n", errno); + goto errout_with_sendsd; + } + + /* Create a UDP receive socket */ + + printf(LABEL "Create receive socket\n"); + + recvsd = socket(PF_INET, SOCK_DGRAM, 0); + if (recvsd < 0) + { + fprintf(stderr, LABEL "ERROR: Failed to create receive socket: %d\n", errno); + goto errout_with_sendsd; + } + + /* Set socket to reuse address */ + + optval = 1; + if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) + { + fprintf(stderr, LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); + goto errout_with_recvsd; + } + + /* Bind the socket to a local address */ + + listenaddr.sin_family = AF_INET; + listenaddr.sin_port = htons(EXAMPLES_BRIDGE_RECV_RECVPORT); + listenaddr.sin_addr.s_addr = htonl(EXAMPLES_BRIDGE_RECV_IPHOST); + + if (bind(recvsd, (struct sockaddr*)&listenaddr, sizeof(struct sockaddr_in)) < 0) + { + fprintf(stderr, LABEL "ERROR: bind failure: %d\n", errno); + goto errout_with_recvsd; + } + + /* Send a packet */ + + printf(LABEL "Sending %lu bytes\n", sizeof(g_sndmessage)); + nsent = sendto(sndsd, g_sndmessage, sizeof(g_sndmessage), 0, + (struct sockaddr*)&sendaddr, sizeof(struct sockaddr_in)); + + /* Check for send errors */ + + if (nsent < 0) + { + fprintf(stderr, LABEL "ERROR: sendto failed: %d\n", errno); + goto errout_with_recvsd; + } + else if (nsent != sizeof(g_sndmessage)) + { + fprintf(stderr, LABEL "ERROR: Bad send length: %ld Expected: %d\n", + (long)nsent, sizeof(g_sndmessage)); + goto errout_with_recvsd; + } + + printf(LABEL "Message sent successfully\n"); + + /* Read a packet */ + + printf(LABEL "Receiving up to %d bytes\n", EXAMPLES_BRIDGE_SEND_IOBUFIZE); + + addrlen = sizeof(struct sockaddr_in); + nrecvd = recvfrom(recvsd, g_rdbuffer, EXAMPLES_BRIDGE_SEND_IOBUFIZE, 0, + (struct sockaddr*)&recvaddr, &addrlen); + + tmpaddr = ntohl(recvaddr.sin_addr.s_addr); + printf(LABEL "Received %ld bytes from %d.%d.%d.%d:%d\n", + (long)nrecvd, + tmpaddr >> 24, (tmpaddr >> 16) & 0xff, + (tmpaddr >> 8) & 0xff, tmpaddr & 0xff, + ntohs(recvaddr.sin_port)); + + /* Check for a receive error or zero bytes received. The negative + * return value indicates a receive error; Zero would mean that the + * other side of the "connection" performed an "orderly" shutdown. + * This should not occur with a UDP socket and so must also be an + * error of some kind. + */ + + if (nrecvd <= 0) + { + if (nrecvd < 0) + { + fprintf(stderr, LABEL "ERROR: recvfrom failed: %d\n", errno); + } + else + { + fprintf(stderr, LABEL "ERROR: recvfrom returned zero\n"); + } + + goto errout_with_recvsd; + } + + if (nrecvd != nrecvd) + { + fprintf(stderr, LABEL "ERROR: Number of bytes received differs from number sent\n"); + } + + /* Dump the received packet */ + + for (i = 0, j = 0; i < nrecvd; i++) + { + if ( g_rdbuffer[i] == ' ' && j >= 64) + { + putchar('\n'); + j = 0; + } + else if (isprint(g_rdbuffer[i])) + { + putchar(g_rdbuffer[i]); + j++; + } + else if (g_rdbuffer[i] == '\n') + { + putchar('\n'); + j = 0; + } + else if (g_rdbuffer[i] != '\r') + { + printf("\%03o", g_rdbuffer[i]); + j += 4; + } + } + + close(recvsd); + close(recvsd); + return EXIT_SUCCESS; + +errout_with_recvsd: + close(recvsd); +errout_with_sendsd: + close(sndsd); + return EXIT_FAILURE; +} + diff --git a/apps/examples/bridge/host_net1.c b/apps/examples/bridge/host_net1.c new file mode 100644 index 000000000..8f9c85f29 --- /dev/null +++ b/apps/examples/bridge/host_net1.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * examples/bridge/host_net1.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * + * Authors: Gregory Nutt + * + * 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 "bridge_config.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Send on network 1 */ + +#define EXAMPLES_BRIDGE_SEND_IFNAME CONFIG_EXAMPLES_BRIDGE_NET1_IFNAME +#define EXAMPLES_BRIDGE_SEND_RECVPORT CONFIG_EXAMPLES_BRIDGE_NET1_RECVPORT +#define EXAMPLES_BRIDGE_SEND_SNDPORT CONFIG_EXAMPLES_BRIDGE_NET1_SNDPORT +#define EXAMPLES_BRIDGE_SEND_IOBUFIZE CONFIG_EXAMPLES_BRIDGE_NET1_IOBUFIZE +#ifdef CONFIG_EXAMPLES_BRIDGE_NET1_NOMAC +# define EXAMPLES_BRIDGE_SEND_NOMAC +#endif +#define EXAMPLES_BRIDGE_SEND_MACADDR CONFIG_EXAMPLES_BRIDGE_NET1_MACADDR +#define EXAMPLES_BRIDGE_SEND_IPADDR CONFIG_EXAMPLES_BRIDGE_NET1_IPADDR +#define EXAMPLES_BRIDGE_SEND_DRIPADDR CONFIG_EXAMPLES_BRIDGE_NET1_DRIPADDR +#define EXAMPLES_BRIDGE_SEND_NETMASK CONFIG_EXAMPLES_BRIDGE_NET1_NETMASK +#define EXAMPLES_BRIDGE_SEND_IPHOST CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST +#define EXAMPLES_BRIDGE_SEND_STACKSIZE CONFIG_EXAMPLES_BRIDGE_NET1_STACKSIZE +#define EXAMPLES_BRIDGE_SEND_PRIORITY CONFIG_EXAMPLES_BRIDGE_NET1_PRIORITY + +/* Receive on network 2 */ + +#define EXAMPLES_BRIDGE_RECV_IFNAME CONFIG_EXAMPLES_BRIDGE_NET2_IFNAME +#define EXAMPLES_BRIDGE_RECV_RECVPORT CONFIG_EXAMPLES_BRIDGE_NET2_RECVPORT +#define EXAMPLES_BRIDGE_RECV_SNDPORT CONFIG_EXAMPLES_BRIDGE_NET2_SNDPORT +#define EXAMPLES_BRIDGE_RECV_IOBUFIZE CONFIG_EXAMPLES_BRIDGE_NET2_IOBUFIZE +#ifdef CONFIG_EXAMPLES_BRIDGE_NET2_NOMAC +# define EXAMPLES_BRIDGE_RECV_NOMAC +#endif +#define EXAMPLES_BRIDGE_RECV_MACADDR CONFIG_EXAMPLES_BRIDGE_NET2_MACADDR +#define EXAMPLES_BRIDGE_RECV_IPADDR CONFIG_EXAMPLES_BRIDGE_NET2_IPADDR +#define EXAMPLES_BRIDGE_RECV_DRIPADDR CONFIG_EXAMPLES_BRIDGE_NET2_DRIPADDR +#define EXAMPLES_BRIDGE_RECV_NETMASK CONFIG_EXAMPLES_BRIDGE_NET2_NETMASK +#define EXAMPLES_BRIDGE_RECV_IPHOST CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST +#define EXAMPLES_BRIDGE_RECV_STACKSIZE CONFIG_EXAMPLES_BRIDGE_NET2_STACKSIZE +#define EXAMPLES_BRIDGE_RECV_PRIORITY CONFIG_EXAMPLES_BRIDGE_NET2_PRIORITY + +#define LABEL "NET1->2: " + +#define MESSAGE \ + "Great ambition is the passion of a great character. Those endowed" \ + "with it may perform very good or very bad acts. All depends on the" \ + "principles which direct them. -- Napoleon Bonaparte" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: main + ****************************************************************************/ + +#include "host_main.c" diff --git a/apps/examples/bridge/host_net2.c b/apps/examples/bridge/host_net2.c new file mode 100644 index 000000000..32fdaa6ed --- /dev/null +++ b/apps/examples/bridge/host_net2.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * examples/bridge/host_net2.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * + * Authors: Gregory Nutt + * + * 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 "bridge_config.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Send on network 1 */ + +#define EXAMPLES_BRIDGE_SEND_IFNAME CONFIG_EXAMPLES_BRIDGE_NET2_IFNAME +#define EXAMPLES_BRIDGE_SEND_RECVPORT CONFIG_EXAMPLES_BRIDGE_NET2_RECVPORT +#define EXAMPLES_BRIDGE_SEND_SNDPORT CONFIG_EXAMPLES_BRIDGE_NET2_SNDPORT +#define EXAMPLES_BRIDGE_SEND_IOBUFIZE CONFIG_EXAMPLES_BRIDGE_NET2_IOBUFIZE +#ifdef CONFIG_EXAMPLES_BRIDGE_NET2_NOMAC +# define EXAMPLES_BRIDGE_SEND_NOMAC +#endif +#define EXAMPLES_BRIDGE_SEND_MACADDR CONFIG_EXAMPLES_BRIDGE_NET2_MACADDR +#define EXAMPLES_BRIDGE_SEND_IPADDR CONFIG_EXAMPLES_BRIDGE_NET2_IPADDR +#define EXAMPLES_BRIDGE_SEND_DRIPADDR CONFIG_EXAMPLES_BRIDGE_NET2_DRIPADDR +#define EXAMPLES_BRIDGE_SEND_NETMASK CONFIG_EXAMPLES_BRIDGE_NET2_NETMASK +#define EXAMPLES_BRIDGE_SEND_IPHOST CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST +#define EXAMPLES_BRIDGE_SEND_STACKSIZE CONFIG_EXAMPLES_BRIDGE_NET2_STACKSIZE +#define EXAMPLES_BRIDGE_SEND_PRIORITY CONFIG_EXAMPLES_BRIDGE_NET2_PRIORITY + +/* Receive on network 2 */ + +#define EXAMPLES_BRIDGE_RECV_IFNAME CONFIG_EXAMPLES_BRIDGE_NET1_IFNAME +#define EXAMPLES_BRIDGE_RECV_RECVPORT CONFIG_EXAMPLES_BRIDGE_NET1_RECVPORT +#define EXAMPLES_BRIDGE_RECV_SNDPORT CONFIG_EXAMPLES_BRIDGE_NET1_SNDPORT +#define EXAMPLES_BRIDGE_RECV_IOBUFIZE CONFIG_EXAMPLES_BRIDGE_NET1_IOBUFIZE +#ifdef CONFIG_EXAMPLES_BRIDGE_NET1_NOMAC +# define EXAMPLES_BRIDGE_RECV_NOMAC +#endif +#define EXAMPLES_BRIDGE_RECV_MACADDR CONFIG_EXAMPLES_BRIDGE_NET1_MACADDR +#define EXAMPLES_BRIDGE_RECV_IPADDR CONFIG_EXAMPLES_BRIDGE_NET1_IPADDR +#define EXAMPLES_BRIDGE_RECV_DRIPADDR CONFIG_EXAMPLES_BRIDGE_NET1_DRIPADDR +#define EXAMPLES_BRIDGE_RECV_NETMASK CONFIG_EXAMPLES_BRIDGE_NET1_NETMASK +#define EXAMPLES_BRIDGE_RECV_IPHOST CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST +#define EXAMPLES_BRIDGE_RECV_STACKSIZE CONFIG_EXAMPLES_BRIDGE_NET1_STACKSIZE +#define EXAMPLES_BRIDGE_RECV_PRIORITY CONFIG_EXAMPLES_BRIDGE_NET1_PRIORITY + +#define LABEL "NET2->1: " + +#define MESSAGE \ + "Ideas are more powerful than guns. We would not let our enemies have" \ + "guns, why should we let them have ideas. -- Joseph Stalin" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: main + ****************************************************************************/ + +#include "host_main.c" -- cgit v1.2.3