2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
21 #include <vppinfra/format.h>
23 #include <sys/ucontext.h>
25 volatile int signal_received;
28 unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
34 setup_signal_handler (void)
39 for (i = 1; i < 32; i++)
41 memset (&sa, 0, sizeof (sa));
42 sa.sa_sigaction = (void *) unix_signal_handler;
43 sa.sa_flags = SA_SIGINFO;
47 /* these signals take the default action */
55 /* ignore SIGPIPE, SIGCHLD */
58 sa.sa_sigaction = (void *) SIG_IGN;
61 /* catch and handle all other signals */
66 if (sigaction (i, &sa, 0) < 0)
67 clib_unix_warning ("sigaction %U", format_signal, i);
73 main (int argc, char *argv[])
75 int sockfd, portno, n, sent, accfd;
76 struct sockaddr_in serv_addr;
77 struct hostent *server;
82 fformat (stderr, "usage %s hostname port\n", argv[0]);
86 setup_signal_handler ();
88 portno = 1234; // atoi(argv[2]);
89 sockfd = socket (AF_INET, SOCK_STREAM, 0);
92 clib_unix_error ("socket");
95 server = gethostbyname ("6.0.1.1");
98 clib_unix_warning ("gethostbyname");
101 bzero ((char *) &serv_addr, sizeof (serv_addr));
102 serv_addr.sin_family = AF_INET;
103 bcopy ((char *) server->h_addr,
104 (char *) &serv_addr.sin_addr.s_addr, server->h_length);
105 serv_addr.sin_port = htons (portno);
106 if (bind (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
108 clib_unix_warning ("bind");
112 vec_validate (rx_buffer, 8999 /* jumbo mtu */ );
114 if (listen (sockfd, 5 /* backlog */ ) < 0)
116 clib_unix_warning ("listen");
126 accfd = accept (sockfd, 0 /* don't care */ , 0);
129 clib_unix_warning ("accept");
134 n = recv (accfd, rx_buffer, vec_len (rx_buffer), 0 /* flags */ );
143 clib_unix_warning ("recv");
151 sent = send (accfd, rx_buffer, n, 0 /* flags */ );
154 clib_unix_warning ("send");
161 clib_warning ("sent %d not %d", sent, n);
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")