1 //==========================================================================
5 // Await an order from the target, and print it out...
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //####BSDCOPYRIGHTBEGIN####
40 // -------------------------------------------
42 // Portions of this software may have been derived from OpenBSD or other sources,
43 // and are covered by the appropriate copyright disclaimers included herein.
45 // -------------------------------------------
47 //####BSDCOPYRIGHTEND####
48 //==========================================================================
49 //#####DESCRIPTIONBEGIN####
51 // Author(s): hmt,gthomas
52 // Contributors: hmt,gthomas
55 //####DESCRIPTIONEND####
57 //==========================================================================
62 #include <netinet/in.h>
63 #include <netinet/ip.h>
64 #include <netinet/ip_icmp.h>
65 #include <net/route.h>
74 #define SOURCE_PORT 9980
76 int main( int argc, char **argv )
78 int s_source, e_source;
79 struct sockaddr_in e_source_addr, local;
83 char ack[] = "Acknowledged\n";
88 fprintf( stderr, "usage: %s [once|many]\n", argv[0] );
93 if ( !strcmp( "once", argv[1] ) )
95 else if ( !strcmp( "many", argv[1] ) )
101 s_source = socket(AF_INET, SOCK_STREAM, 6 /* TCP */ );
103 pexit("stream socket");
107 memset(&local, 0, sizeof(local));
108 local.sin_family = AF_INET;
109 local.sin_len = sizeof(local);
110 local.sin_port = ntohs(SOURCE_PORT);
111 local.sin_addr.s_addr = INADDR_ANY;
112 if(bind(s_source, (struct sockaddr *) &local, sizeof(local)) < 0) {
113 pexit("bind /source/ error");
115 if (setsockopt(s_source, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
116 pexit("setsockopt /source/ SO_REUSEADDR");
119 if (setsockopt(s_source, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) {
120 pexit("setsockopt /source/ SO_REUSEPORT");
124 listen(s_source, SOMAXCONN);
127 len = sizeof(e_source_addr);
128 if ((e_source = accept(s_source,
129 (struct sockaddr *)&e_source_addr, &len)) < 0) {
130 pexit("accept /source/");
132 fprintf( stderr, "awaitorder: connection from %s:%d\n",
133 inet_ntoa(e_source_addr.sin_addr), ntohs(e_source_addr.sin_port));
135 // Wait for "source" to tell us the orders
136 if ( 0 >= (len = read(e_source, orders, sizeof(orders)))) {
137 pexit("Can't read orders");
139 if ( sizeof(ack) != write(e_source, ack, sizeof( ack ) ) ) {
140 pexit("Can't write ACK");
145 printf( "ORDERS: %s\n", orders );