Debian Codegraph @

src/apps/sctp_darn.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2001, 2003
3 * Copyright (c) 1999 Cisco
4 * Copyright (c) 1999, 2000, 2001 Motorola
5 * Copyright (c) 2001 Nokia
6 * Copyright (c) 2001 La Monte H.P. Yarroll
7 *
8 * The SCTP implementation is free software;
9 * you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * The SCTP implementation is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * ************************
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
24 *
25 * Please send any bug reports or fixes you make to the
26 * email address(es):
27 * lksctp developers <[email protected]>
28 *
29 * Or submit a bug report through the following website:
30 * https://github.com/sctp/lksctp-tools/
31 *
32 * Any bugs reported to us we will try to fix... any fixes shared will
33 * be incorporated into the next SCTP release.
34 *
35 * Written or modified by:
36 * La Monte H.P. Yarroll <[email protected]>
37 * Karl Knutson <[email protected]>
38 * Hui Huang <[email protected]>
39 * Daisy Chang <[email protected]>
40 * Sridhar Samudrala <[email protected]>
41 */
42
43 /* This is a userspace test application for the SCTP kernel
44 * implementation state machine. It is vaguely inspired by Stevens'
45 * program "sock".
46 *
47 * It has the limited ability to send messages and to listen for messages
48 * sent via SCTP.
49 */
50
51 #include <stdio.h>
52 #include <fcntl.h>
53 #include <stdlib.h>
54 //#define _GNU_SOURCE
55 #include <getopt.h>
56 #include <netdb.h>
57 #include <inttypes.h>
58 #include <ctype.h>
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <sys/uio.h>
62 #include <netinet/in.h>
63 #include <sys/param.h>
64 #include <sys/poll.h>
65 #include <arpa/inet.h>
66 #include <errno.h>
67 #include <net/if.h>
68 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
69 #include <unistd.h>
70 #include <string.h>
71 #include <signal.h>
72 #include "sctp_darn.h"cxx . . $ `<file>/src/apps/sctp_darn.h`/
73
74 char *TCIDcxx . . $ TCID. = __FILE__;
75 int TST_TOTALcxx . . $ TST_TOTAL. = 1;
76 int TST_CNTcxx . . $ TST_CNT. = 0;
77
78 #define GEN_DATA_FIRSTcxx . . $ `src/apps/sctp_darn.c:78:9`! 0x21
79 #define GEN_DATA_LASTcxx . . $ `src/apps/sctp_darn.c:79:9`! 0x7e
80
81 /* Display an IPv4 address in readable format. */
82 #define NIPQUADcxx . . $ `src/apps/sctp_darn.c:82:9`!(addr) \
83 ((unsigned char *)&addr)[0], \
84 ((unsigned char *)&addr)[1], \
85 ((unsigned char *)&addr)[2], \
86 ((unsigned char *)&addr)[3]
87
88 /* Display an IPv6 address in readable format. */
89 #define NIP6cxx . . $ `src/apps/sctp_darn.c:89:9`!(addr) \
90 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![0]), \
91 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![1]), \
92 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![2]), \
93 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![3]), \
94 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![4]), \
95 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![5]), \
96 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![6]), \
97 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!((addr).s6_addr16cxx . . $ `<external>/9581057695539925927/in.h:233:10`![7])
98
99 /* These are the global options. */
100 char *local_hostcxx . . $ local_host. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
101 int local_portcxx . . $ local_port. = 0;
102 char *remote_hostcxx . . $ remote_host. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
103 int remote_portcxx . . $ remote_port. = 0;
104 command_tcxx . . $ command_t# commandcxx . . $ command. = COMMAND_NONEcxx . . $ COMMAND_NONE.;
105 struct sockaddrcxx . . $ sockaddr# *bindx_add_addrscxx . . $ bindx_add_addrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
106 int bindx_add_countcxx . . $ bindx_add_count. = 0;
107 struct sockaddrcxx . . $ sockaddr# *bindx_rem_addrscxx . . $ bindx_rem_addrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
108 int bindx_rem_countcxx . . $ bindx_rem_count. = 0;
109 struct sockaddrcxx . . $ sockaddr# *connectx_addrscxx . . $ connectx_addrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
110 int connectx_countcxx . . $ connectx_count. = 0;
111 int interactive_modecxx . . $ interactive_mode. = 0;
112 int poll_skncxx . . $ poll_skn. = 0;
113 int nonblockingcxx . . $ nonblocking. = 0;
114 int opt_spacecxx . . $ opt_space. = 0;
115 char gen_datacxx . . $ gen_data. = GEN_DATA_FIRSTcxx . . $ `src/apps/sctp_darn.c:78:9`!;
116 char *inter_outbufcxx . . $ inter_outbuf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
117 int inter_outlencxx . . $ inter_outlen. = 0;
118 int inter_skcxx . . $ inter_sk. = 0;
119 int poll_snd_sizecxx . . $ poll_snd_size. = 0;
120 int use_pollcxx . . $ use_poll. = 0;
121 int socket_typecxx . . $ socket_type. = SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!;
122 sctp_assoc_tcxx . . $ sctp_assoc_t# associdcxx . . $ associd. = 0;
123 int echocxx . . $ echo. = 0;
124 char *interfacecxx . . $ interface. = "eth0";
125 int if_indexcxx . . $ if_index. = 0;
126 sockaddr_storage_tcxx . . $ sockaddr_storage_t# remote_addrcxx . . $ remote_addr.;
127 sa_family_tcxx . . $ sa_family_t# ra_familycxx . . $ ra_family.; /* What family is remote_addr? */
128 int ra_lencxx . . $ ra_len. = 0; /* How long is remote_addr? */
129 int new_connectioncxx . . $ new_connection. = 1;
130
131 enum inter_cmd_numcxx . . $ inter_cmd_num# {
132 INTER_SNDcxx . . $ INTER_SND. = 0,
133 INTER_RCVcxx . . $ INTER_RCV.,
134 INTER_SNDBUFcxx . . $ INTER_SNDBUF.,
135 INTER_RCVBUFcxx . . $ INTER_RCVBUF.,
136 INTER_BINDX_ADDcxx . . $ INTER_BINDX_ADD.,
137 INTER_BINDX_REMcxx . . $ INTER_BINDX_REM.,
138 INTER_SET_PRIMcxx . . $ INTER_SET_PRIM.,
139 INTER_SET_PEER_PRIMcxx . . $ INTER_SET_PEER_PRIM.,
140 INTER_SHUTDOWNcxx . . $ INTER_SHUTDOWN.,
141 INTER_ABORTcxx . . $ INTER_ABORT.,
142 INTER_NODELAYcxx . . $ INTER_NODELAY.,
143 INTER_MAXSEGcxx . . $ INTER_MAXSEG.,
144 INTER_HEARTBEATcxx . . $ INTER_HEARTBEAT.,
145 INTER_GET_STATScxx . . $ INTER_GET_STATS.
146 };
147
148 enum shutdown_typecxx . . $ shutdown_type# {
149 SHUTDOWN_ABORTcxx . . $ SHUTDOWN_ABORT. = 0,
150 SHUTDOWN_SHUTDOWNcxx . . $ SHUTDOWN_SHUTDOWN.
151 };
152
153 struct inter_entrycxx . . $ inter_entry# {
154 char *cmdcxx . . $ inter_entry#cmd.;
155 int cmd_numcxx . . $ inter_entry#cmd_num.;
156 };
157
158 struct inter_entrycxx . . $ inter_entry# inter_commandscxx . . $ inter_commands.[] = {
159 {"snd", INTER_SNDcxx . . $ INTER_SND.},
160 {"rcv", INTER_RCVcxx . . $ INTER_RCV.},
161 {"sndbuf", INTER_SNDBUFcxx . . $ INTER_SNDBUF.},
162 {"rcvbuf", INTER_RCVBUFcxx . . $ INTER_RCVBUF.},
163 {"bindx-add", INTER_BINDX_ADDcxx . . $ INTER_BINDX_ADD.},
164 {"bindx-rem", INTER_BINDX_REMcxx . . $ INTER_BINDX_REM.},
165 {"primary", INTER_SET_PRIMcxx . . $ INTER_SET_PRIM.},
166 {"peer_primary", INTER_SET_PEER_PRIMcxx . . $ INTER_SET_PEER_PRIM.},
167 {"shutdown", INTER_SHUTDOWNcxx . . $ INTER_SHUTDOWN.},
168 {"abort", INTER_ABORTcxx . . $ INTER_ABORT.},
169 {"nodelay", INTER_NODELAYcxx . . $ INTER_NODELAY.},
170 {"maxseg", INTER_MAXSEGcxx . . $ INTER_MAXSEG.},
171 {"heartbeat", INTER_HEARTBEATcxx . . $ INTER_HEARTBEAT.},
172 {"stats", INTER_GET_STATScxx . . $ INTER_GET_STATS.},
173 {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, -1},
174 };
175
176 #define POLL_SK_MAXcxx . . $ `src/apps/sctp_darn.c:176:9`! 256 /* The max number of sockets to select/poll. */
177 int poll_skscxx . . $ poll_sks.[POLL_SK_MAXcxx . . $ `src/apps/sctp_darn.c:176:9`!]; /* The array for using select(). */
178 struct pollfdcxx . . $ pollfd# poll_fdscxx . . $ poll_fds.[POLL_SK_MAXcxx . . $ `src/apps/sctp_darn.c:176:9`!]; /* The array for using poll(). */
179 #define POLL_SND_SIZEcxx . . $ `src/apps/sctp_darn.c:179:9`! 16384 /* Default message size in the poll mode. */
180
181
182 struct sockaddrcxx . . $ sockaddr# *append_addrcxx . . $ append_addr(739737ae76601d7b).(const char *parm, struct sockaddrcxx . . $ sockaddr# *addrs,
183 int *ret_count) ;
184 int build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(char *argv0, int portnum);
185 static int parse_inter_commandscxx . . $ parse_inter_commands(60b24ab836da28f5).(char *, char *, int);
186 static void snd_funccxx . . $ snd_func(fda57c8427c60377).(char *);
187 static void sndbuf_funccxx . . $ sndbuf_func(51648a5edc2089b5).(char *, int, int, int);
188 static void rcvbuf_funccxx . . $ rcvbuf_func(51648a5edc2089b5).(char *, int, int, int);
189 static struct sockaddrcxx . . $ sockaddr# *get_bindx_addrcxx . . $ get_bindx_addr(521cf95a28fabae7).(char *, int *);
190 static int bindx_funccxx . . $ bindx_func(fb084d643e22d309).(char *, int, struct sockaddrcxx . . $ sockaddr# *, int, int, int);
191 static int connectx_funccxx . . $ connectx_func(73b07b87c343dc96).(char *, int, struct sockaddrcxx . . $ sockaddr# *, int);
192 static void primary_funccxx . . $ primary_func(7c7b1413e571f034).(char *, int, char *, int);
193 static void peer_primary_funccxx . . $ peer_primary_func(7c7b1413e571f034).(char *, int, char *, int);
194 static void spp_hb_demand_funccxx . . $ spp_hb_demand_func(7c7b1413e571f034).(char *, int, char *, int);
195 static int nodelay_funccxx . . $ nodelay_func(cd0c04d3624ba1ca).(char *, int, int val, int set);
196 static int maxseg_funccxx . . $ maxseg_func(cd0c04d3624ba1ca).(char *, int, int val, int set);
197 static int shutdown_funccxx . . $ shutdown_func(be750502182deecd).(char *argv0, int *skp, int shutdown_type);
198 static int get_assocstats_funccxx . . $ get_assocstats_func(9b79fb6aee4c0440).(int, sctp_assoc_tcxx . . $ sctp_assoc_t#);
199 static int test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(int sk, sctp_assoc_tcxx . . $ sctp_assoc_t# assoc_id);
200 static char * gen_messagecxx . . $ gen_message(ff224f080444ee45).(int);
201 static sctp_assoc_tcxx . . $ sctp_assoc_t# test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(int);
202 static sctp_assoc_tcxx . . $ sctp_assoc_t# test_verify_assoc_changecxx . . $ test_verify_assoc_change(615209a3b05c63a0).(struct msghdrcxx . . $ msghdr# *);
203 void print_addr_bufcxx . . $ print_addr_buf(d0320739773070f2).(void * laddrs, int n_laddrs);
204 int print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).(struct sockaddrcxx . . $ sockaddr# *sa_addr);
205
206 int
207 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) {
208 int sk = -1;
209 int error = 0;
210 int i;
211
212 signalcxx . . $ signal(c2d516773f91faf8).(SIGPIPEcxx . . $ `<external>/11773118241360591791/signum-generic.h:60:9`!, SIG_IGNcxx . . $ `<external>/11773118241360591791/signum-generic.h:30:9`!);
213
214 parse_argumentscxx . . $ parse_arguments(c759356ac01a31e7).(argc, argv);
215
216 switch(commandcxx . . $ command.) {
217 case COMMAND_NONEcxx . . $ COMMAND_NONE.:
218 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Please specify a command.\n",
219 argv[0]);
220 exitcxx . . $ exit(3ca292c338df9bb3).(1);
221 break;
222 case COMMAND_LISTENcxx . . $ COMMAND_LISTEN.:
223 sk = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv[0], local_portcxx . . $ local_port.);
224 error = command_listencxx . . $ command_listen(6abd07ddb1a912f0).(argv[0], sk);
225 break;
226 case COMMAND_SENDcxx . . $ COMMAND_SEND.:
227 sk = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv[0], local_portcxx . . $ local_port.);
228 error = command_sendcxx . . $ command_send(b0a0d720b596a511).(argv[0], &sk);
229 break;
230 case COMMAND_POLLcxx . . $ COMMAND_POLL.:
231 if (use_pollcxx . . $ use_poll.) {
232 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
233 poll_fdscxx . . $ poll_fds.[i].fdcxx . . $ pollfd#fd. = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv[0],
234 local_portcxx . . $ local_port. + i);
235 }
236 } else {
237 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
238 poll_skscxx . . $ poll_sks.[i] = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv[0],
239 local_portcxx . . $ local_port. + i);
240 }
241 }
242 error = command_pollcxx . . $ command_poll(1ef8e6ec083aabb9).(argv[0]);
243 break;
244 default:
245 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: illegal command %d\n",
246 argv[0], commandcxx . . $ command.);
247 exitcxx . . $ exit(3ca292c338df9bb3).(1);
248 }
249
250 /* Shut down the link. */
251 if (COMMAND_POLLcxx . . $ COMMAND_POLL. != commandcxx . . $ command.) {
252 closecxx . . $ close(7864480464b09eea).(sk);
253 } else {
254 /* Shutdown all links. */
255 if (use_pollcxx . . $ use_poll.) {
256 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
257 closecxx . . $ close(7864480464b09eea).(poll_fdscxx . . $ poll_fds.[i].fdcxx . . $ pollfd#fd.);
258 }
259 } else {
260 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
261 closecxx . . $ close(7864480464b09eea).(poll_skscxx . . $ poll_sks.[i]);
262 }
263 }
264 }
265
266 exitcxx . . $ exit(3ca292c338df9bb3).(error);
267 }
268
269 /********************************************************************
270 * 2nd Level Abstractions
271 ********************************************************************/
272
273 void
274 parse_argumentscxx . . $ parse_arguments(c759356ac01a31e7).(int argc, char *argv[]) {
275 int option_index = 0;
276 int c;
277 struct sockaddrcxx . . $ sockaddr# *tmp_addrs = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
278
279 static struct optioncxx . . $ option# long_options[] = {
280 {"local", 1, 0, 1},
281 {"local-port", 1, 0, 2},
282 {"remote", 1, 0, 3},
283 {"remote-port", 1, 0, 4},
284 {"listen", 0, 0, 10},
285 {"send", 0, 0, 11},
286 {"bindx-add", 1, 0, 15},
287 {"bindx-rem", 1, 0, 16},
288 {"use-poll", 0, 0, 20},
289 {"echo", 0, 0, 'e'},
290 {"interface", optional_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:64:9`!, 0, 5,},
291 {"connectx", 1, 0, 17},
292 {0, 0, 0, 0}
293 };
294
295 /* Parse the arguments. */
296 while (1) {
297 c = getopt_longcxx . . $ getopt_long(41f665c090816971). (argc, argv, "B:H:IP:b:h:i:p:lm:nstz:ec:",
298 long_options, &option_index);
299 if (c == -1)
300 break;
301
302 switch (c) {
303 case 0:
304 printfcxx . . $ printf(581fddd72a8db8fc).("option %s", long_options[option_index].namecxx . . $ option#name.);
305 if (optargcxx . . $ optarg.) {
306 printfcxx . . $ printf(581fddd72a8db8fc).(" with arg %s", optargcxx . . $ optarg.);
307 }
308 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
309 break;
310 case 1: /* local host */
311 case 'H':
312 local_hostcxx . . $ local_host. = optargcxx . . $ optarg.;
313 break;
314 case 2: /* local port */
315 case 'P':
316 local_portcxx . . $ local_port. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
317 break;
318 case 3: /* remote host */
319 case 'h':
320 remote_hostcxx . . $ remote_host. = optargcxx . . $ optarg.;
321 break;
322 case 4: /* remote port */
323 case 'p':
324 remote_portcxx . . $ remote_port. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
325 break;
326 case 5: /* interface for sin6_scope_id */
327 if (optargcxx . . $ optarg.)
328 interfacecxx . . $ interface. = optargcxx . . $ optarg.;
329 if_indexcxx . . $ if_index. = if_nametoindexcxx . . $ if_nametoindex(c61c63047ce273de).(interfacecxx . . $ interface.);
330 if (!if_indexcxx . . $ if_index.) {
331 printfcxx . . $ printf(581fddd72a8db8fc).("Interface %s unknown\n", interfacecxx . . $ interface.);
332 exitcxx . . $ exit(3ca292c338df9bb3).(1);
333 }
334 break;
335 /* COMMANDS */
336 case 10: /* listen */
337 case 'l':
338 if (commandcxx . . $ command.) {
339 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
340 "%s: pick ONE of listen or send\n",
341 argv[0]);
342 exitcxx . . $ exit(3ca292c338df9bb3).(1);
343 } else {
344 commandcxx . . $ command. = COMMAND_LISTENcxx . . $ COMMAND_LISTEN.;
345 }
346 break;
347
348 case 11: /* send */
349 case 's':
350 if (commandcxx . . $ command.) {
351 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
352 "%s: pick ONE of listen or send\n",
353 argv[0]);
354 exitcxx . . $ exit(3ca292c338df9bb3).(1);
355 } else {
356 commandcxx . . $ command. = COMMAND_SENDcxx . . $ COMMAND_SEND.;
357 }
358 break;
359
360 case 15: /* bindx_add */
361 case 'B':
362 tmp_addrs =
363 append_addrcxx . . $ append_addr(739737ae76601d7b).(optargcxx . . $ optarg., bindx_add_addrscxx . . $ bindx_add_addrs.,
364 &bindx_add_countcxx . . $ bindx_add_count.);
365 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == tmp_addrs) {
366 /* We have no memory, so keep fprintf()
367 * from trying to allocate more.
368 */
369 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "No memory to add ");
370 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n", optargcxx . . $ optarg.);
371 exitcxx . . $ exit(3ca292c338df9bb3).(2);
372 }
373 bindx_add_addrscxx . . $ bindx_add_addrs. = tmp_addrs;
374
375 break;
376
377 case 16: /* bindx_rem */
378 case 'b':
379 tmp_addrs =
380 append_addrcxx . . $ append_addr(739737ae76601d7b).(optargcxx . . $ optarg., bindx_rem_addrscxx . . $ bindx_rem_addrs.,
381 &bindx_rem_countcxx . . $ bindx_rem_count.);
382 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == tmp_addrs) {
383 /* We have no memory, so keep fprintf()
384 * from trying to allocate more.
385 */
386 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "No memory to add ");
387 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n", optargcxx . . $ optarg.);
388 exitcxx . . $ exit(3ca292c338df9bb3).(2);
389 }
390 bindx_rem_addrscxx . . $ bindx_rem_addrs. = tmp_addrs;
391 break;
392 case 17: /* connectx */
393 case 'c':
394 tmp_addrs =
395 append_addrcxx . . $ append_addr(739737ae76601d7b).(optargcxx . . $ optarg., connectx_addrscxx . . $ connectx_addrs.,
396 &connectx_countcxx . . $ connectx_count.);
397 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == tmp_addrs) {
398 /* We have no memory, so keep fprintf()
399 * from trying to allocate more.
400 */
401 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "No memory to add ");
402 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n", optargcxx . . $ optarg.);
403 exitcxx . . $ exit(3ca292c338df9bb3).(2);
404 }
405 connectx_addrscxx . . $ connectx_addrs. = tmp_addrs;
406 break;
407 case 20: /* use-poll */
408 use_pollcxx . . $ use_poll. = 1;
409 break;
410 case 'I':
411 interactive_modecxx . . $ interactive_mode. = 1;
412 break;
413 case 'i':
414 commandcxx . . $ command. = COMMAND_POLLcxx . . $ COMMAND_POLL.;
415 poll_skncxx . . $ poll_skn. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
416 if (poll_skncxx . . $ poll_skn. <= 0 || poll_skncxx . . $ poll_skn. > POLL_SK_MAXcxx . . $ `src/apps/sctp_darn.c:176:9`!) {
417 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Too many sockets for ");
418 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "for polling\n");
419 exitcxx . . $ exit(3ca292c338df9bb3).(2);
420 }
421 break;
422 case 'm':
423 opt_spacecxx . . $ opt_space. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
424 break;
425 case 'n':
426 nonblockingcxx . . $ nonblocking. = 1;
427 break;
428 case 't':
429 socket_typecxx . . $ socket_type. = SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!;
430 break;
431 case 'z':
432 poll_snd_sizecxx . . $ poll_snd_size. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
433 if (poll_snd_sizecxx . . $ poll_snd_size. <= 0) {
434 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Bad message size.\n");
435 exitcxx . . $ exit(3ca292c338df9bb3).(2);
436 }
437 break;
438 case 'e':
439 echocxx . . $ echo. = 1;
440 break;
441 case '?':
442 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
443 exitcxx . . $ exit(3ca292c338df9bb3).(1);
444
445 default:
446 printfcxx . . $ printf(581fddd72a8db8fc). ("%s: unrecognized option 0%c\n",
447 argv[0], c);
448 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
449 exitcxx . . $ exit(3ca292c338df9bb3).(1);
450 }
451 }
452
453 if (optindcxx . . $ optind. < argc)
454 {
455 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: non-option arguments are illegal: ",
456 argv[0]);
457 while (optindcxx . . $ optind. < argc)
458 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s ", argv[optindcxx . . $ optind.++]);
459 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n");
460 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
461 exitcxx . . $ exit(3ca292c338df9bb3).(1);
462 }
463
464
465 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == local_hostcxx . . $ local_host.) {
466 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: You MUST provide a local host.\n",
467 argv[0]);
468 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
469 exitcxx . . $ exit(3ca292c338df9bb3).(1);
470 }
471
472 if (commandcxx . . $ command. == COMMAND_SENDcxx . . $ COMMAND_SEND. && NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == remote_hostcxx . . $ remote_host.
473 && connectx_countcxx . . $ connectx_count. == 0) {
474 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: You MUST provide a remote host for sending.\n",
475 argv[0]);
476 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
477 exitcxx . . $ exit(3ca292c338df9bb3).(1);
478 }
479
480 if (remote_hostcxx . . $ remote_host. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && connectx_countcxx . . $ connectx_count. != 0) {
481 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: You can not provide both -h and -c options.\n",
482 argv[0]);
483 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
484 exitcxx . . $ exit(3ca292c338df9bb3).(1);
485 }
486 } /* parse_arguments() */
487
488 /* Set up the local endpoint. */
489 int
490 build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(char *argv0, int portnum)
491 {
492 int retval;
493 struct addrinfocxx . . $ addrinfo# hints, *rp;
494 sockaddr_storage_tcxx . . $ sockaddr_storage_t# local_addr;
495 int error;
496 struct sctp_event_subscribecxx . . $ sctp_event_subscribe# subscribe;
497
498 /* Get the transport address for the local host name. */
499 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#));
500 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
501 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
502 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_hostcxx . . $ local_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
503 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
504 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_hostcxx . . $ local_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
505 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n", argv0, local_hostcxx . . $ local_host.);
506 exitcxx . . $ exit(3ca292c338df9bb3).(1);
507 }
508 }
509 memcpycxx . . $ memcpy(cc817cb175f282d).(&local_addr, rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
510 local_addr.v4cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(portnum); /* equal to v6.sin6_port */
511 if (rp->ai_familycxx . . $ addrinfo#ai_family. == AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!)
512 local_addr.v6cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v6..sin6_scope_idcxx . . $ sockaddr_in6#sin6_scope_id. = if_indexcxx . . $ if_index.;
513
514 /* Create the local endpoint. */
515 retval = socketcxx . . $ socket(2326284602b0bb2d).(rp->ai_familycxx . . $ addrinfo#ai_family., socket_typecxx . . $ socket_type., IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
516 if (retval < 0) {
517 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: failed to create socket: %s.\n",
518 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
519 exitcxx . . $ exit(3ca292c338df9bb3).(1);
520 }
521
522 if (SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type.) {
523 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&subscribe, 0, sizeof(subscribe));
524 subscribe.sctp_data_io_eventcxx . . $ sctp_event_subscribe#sctp_data_io_event. = 1;
525 subscribe.sctp_association_eventcxx . . $ sctp_event_subscribe#sctp_association_event. = 1;
526 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(retval, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_EVENTScxx . . $ `<external>/17169092326581286071/sctp.h:80:9`!,
527 (char *)&subscribe, sizeof(subscribe));
528 if (error) {
529 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "SCTP_EVENTS: error: %d\n", error);
530 exitcxx . . $ exit(3ca292c338df9bb3).(1);
531 }
532 }
533
534 /* Bind this socket to the test port. */
535 error = bindcxx . . $ bind(1ce9971e209c3c95).(retval, &local_addr.sacxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#sa., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
536 if (error != 0) {
537 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: can not bind to %s:%d: %s.\n",
538 argv0, local_hostcxx . . $ local_host., portnum,
539 strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
540 exitcxx . . $ exit(3ca292c338df9bb3).(1);
541 }
542
543 /* Do we need to do bindx() to add any additional addresses? */
544 if (bindx_add_addrscxx . . $ bindx_add_addrs.) {
545 if (0 != bindx_funccxx . . $ bindx_func(fb084d643e22d309).(argv0, retval, bindx_add_addrscxx . . $ bindx_add_addrs.,
546 bindx_add_countcxx . . $ bindx_add_count., SCTP_BINDX_ADD_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:1061:9`!, portnum)) {
547 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "bindx_func (add) failed.\n");
548 exitcxx . . $ exit(3ca292c338df9bb3).(1);
549 }
550 } /* if (bindx_add_addrs) */
551
552 /* Do we need to do bindx() to remove any bound addresses? */
553 if (bindx_rem_addrscxx . . $ bindx_rem_addrs.) {
554 if (0 != bindx_funccxx . . $ bindx_func(fb084d643e22d309).(argv0, retval, bindx_rem_addrscxx . . $ bindx_rem_addrs.,
555 bindx_rem_countcxx . . $ bindx_rem_count., SCTP_BINDX_REM_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:1062:9`!, portnum)) {
556 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "bindx_func (remove) failed.\n");
557 exitcxx . . $ exit(3ca292c338df9bb3).(1);
558 }
559 } /* if (bindx_rem_addrs) */
560
561 /* Do we want to run in the non-blocking mode? */
562 if (nonblockingcxx . . $ nonblocking.) {
563 error = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(retval, F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
564 if (error != 0) {
565 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error fcntl: %s.\n",
566 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
567 exitcxx . . $ exit(3ca292c338df9bb3).(1);
568 }
569 }
570
571 if (opt_spacecxx . . $ opt_space.) {
572 sndbuf_funccxx . . $ sndbuf_func(51648a5edc2089b5).(argv0, retval, opt_spacecxx . . $ opt_space., 1);
573 rcvbuf_funccxx . . $ rcvbuf_func(51648a5edc2089b5).(argv0, retval, opt_spacecxx . . $ opt_space., 1);
574 }
575
576 return retval;
577
578 } /* build_endpoint() */
579
580 /* Convenience structure to determine space needed for cmsg. */
581 typedef unioncxx . . $ $anonymous_type_7f7fe7ccbe27aa93_0# {
582 struct sctp_initmsgcxx . . $ sctp_initmsg# initcxx . . $ $anonymous_type_7f7fe7ccbe27aa93_0#init.;
583 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# sndrcvinfocxx . . $ $anonymous_type_7f7fe7ccbe27aa93_0#sndrcvinfo.;
584 } _sctp_cmsg_data_tcxx . . $ _sctp_cmsg_data_t#;
585
586
587 /* Listen on the socket, printing out anything that arrives. */
588 int
589 command_listencxx . . $ command_listen(6abd07ddb1a912f0).(char *argv0, int sk)
590 {
591 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(_sctp_cmsg_data_t))];
592 struct ioveccxx . . $ iovec# iov;
593 struct msghdrcxx . . $ msghdr# inmessage;
594 sockaddr_storage_tcxx . . $ sockaddr_storage_t# msgname;
595 char message[REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!];
596 int done = 0;
597 int error;
598 int c;
599 int recvsk = 0;
600
601 /* Mark sk as being able to accept new associations */
602 error = listencxx . . $ listen(9b79fb6aee4c0440).(sk, 5);
603 if (error != 0) {
604 printfcxx . . $ printf(581fddd72a8db8fc).("\n\n\t\tlisten Failure: %s.\n\n\n",
605 strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
606 exitcxx . . $ exit(3ca292c338df9bb3).(1);
607 }
608
609 if (nonblockingcxx . . $ nonblocking.) {
610 if (!interactive_modecxx . . $ interactive_mode.) {
611 printfcxx . . $ printf(581fddd72a8db8fc).("Use -I for interactive mode with");
612 printfcxx . . $ printf(581fddd72a8db8fc).(" -n nonblocking\n");
613 exitcxx . . $ exit(3ca292c338df9bb3).(1);
614 }
615 }
616
617 /* Initialize the global value for interactive mode functions. */
618 if (interactive_modecxx . . $ interactive_mode.) {
619 inter_skcxx . . $ inter_sk. = sk;
620 }
621
622 /* Initialize inmessage with enough space for DATA... */
623 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
624 if ((iov.iov_basecxx . . $ iovec#iov_base. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
625 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", argv0);
626 exitcxx . . $ exit(3ca292c338df9bb3).(1);
627 }
628 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!;
629 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
630 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
631 /* or a control message. */
632 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
633 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
634 inmessage.msg_namecxx . . $ msghdr#msg_name. = &msgname;
635 inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(msgname);
636
637 printfcxx . . $ printf(581fddd72a8db8fc).("%s listening...\n", argv0);
638 /* Get the messages sent */
639 done = 0;
640 while (!done) {
641 if (interactive_modecxx . . $ interactive_mode.) {
642 /* Read from the user. */
643 if (remote_hostcxx . . $ remote_host.) {
644 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d-%s:%d Interactive mode> ",
645 local_hostcxx . . $ local_host., local_portcxx . . $ local_port., remote_hostcxx . . $ remote_host.,
646 remote_portcxx . . $ remote_port.);
647 } else {
648 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d-", local_hostcxx . . $ local_host., local_portcxx . . $ local_port.);
649 if (associdcxx . . $ associd.) {
650 print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).(&remote_addrcxx . . $ remote_addr..sacxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#sa.);
651 } else {
652 printfcxx . . $ printf(581fddd72a8db8fc).("?:%d", remote_portcxx . . $ remote_port.);
653 }
654 printfcxx . . $ printf(581fddd72a8db8fc).(" Interactive mode> ");
655 }
656 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
657 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == fgetscxx . . $ fgets(efb0aaba7ac866ae).(message, REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!, stdincxx . . $ `<external>/232824719582829767/stdio.h:157:9`!)) {
658 if (socket_typecxx . . $ socket_type. == SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`! && recvsk) {
659 closecxx . . $ close(7864480464b09eea).(recvsk);
660 recvsk = 0;
661 }
662 done = 1;
663 continue;
664 }
665
666 if (0 <= (c = parse_inter_commandscxx . . $ parse_inter_commands(60b24ab836da28f5).(argv0, message,
667 0))) {
668 if (INTER_RCVcxx . . $ INTER_RCV. != c) {
669 continue;
670 }
671 } else {
672 continue;
673 }
674 }
675
676 if (socket_typecxx . . $ socket_type. == SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!) {
677 socklen_tcxx . . $ socklen_t# len = 0;
678
679 if (!recvsk) {
680 if ((recvsk = acceptcxx . . $ accept(46fcd054f4a4d98b).(sk, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &len)) < 0) {
681 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error: %s.\n",
682 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
683 exitcxx . . $ exit(3ca292c338df9bb3).(1);
684 }
685 }
686
687 } else {
688 recvsk = sk;
689 }
690
691 error = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(recvsk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
692 if (error < 0) {
693 if (nonblockingcxx . . $ nonblocking. && (EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! == errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)) {
694 error = 0;
695 continue;
696 }
697
698 if (socket_typecxx . . $ socket_type. == SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!) {
699 if (ENOTCONNcxx . . $ `<external>/17922322188510340118/errno.h:91:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
700 break;
701 printfcxx . . $ printf(581fddd72a8db8fc).("No association is present now!!\n");
702 closecxx . . $ close(7864480464b09eea).(recvsk);
703 recvsk = 0;
704 continue;
705 }
706 break;
707 }
708
709 /* Update the associd when a notification is received on a
710 * UDP-style socket.
711 */
712 if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!)
713 associdcxx . . $ associd. = test_verify_assoc_changecxx . . $ test_verify_assoc_change(615209a3b05c63a0).(&inmessage);
714
715 if (echocxx . . $ echo.) {
716 if( !(MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`! & inmessage.msg_flagscxx . . $ msghdr#msg_flags.)) {
717 if (sendtocxx . . $ sendto(5d9c589195de390a).(recvsk, inmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base.,
718 error, 0,
719 (struct sockaddrcxx . . $ sockaddr# *)&msgname,
720 sizeof(msgname)) == -1) {
721 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error: %s.\n",
722 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
723 exitcxx . . $ exit(3ca292c338df9bb3).(1);
724 }
725 }
726 }
727
728 test_print_messagecxx . . $ test_print_message(3755aa3826476a13).(sk, &inmessage, error);
729
730 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
731 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
732 inmessage.msg_namecxx . . $ msghdr#msg_name. = &msgname;
733 inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(msgname);
734 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!;
735
736 /* Verify that the association is no longer present. */
737 if (0 != test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(recvsk, associdcxx . . $ associd.)) {
738 printfcxx . . $ printf(581fddd72a8db8fc).("No association is present now!!\n");
739 if (socket_typecxx . . $ socket_type. == SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!) {
740 closecxx . . $ close(7864480464b09eea).(recvsk);
741 recvsk = 0;
742 }
743 }
744 }
745
746 if (error < 0) {
747 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error: %s.\n",
748 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
749 exitcxx . . $ exit(3ca292c338df9bb3).(1);
750 }
751
752 return error;
753
754 } /* command_listen() */
755
756 /* Read lines from stdin and send them to the socket. */
757 int
758 command_sendcxx . . $ command_send(b0a0d720b596a511).(char *argv0, int *skp)
759 {
760 struct msghdrcxx . . $ msghdr# outmsg;
761 struct ioveccxx . . $ iovec# iov;
762 int done = 0;
763 char message[REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!];
764 struct addrinfocxx . . $ addrinfo# hints, *rp;
765 int c;
766 struct sockaddrcxx . . $ sockaddr# *addrs;
767 int msglen;
768 int error = 0;
769 int sk = *skp;
770
771 /* Set up the destination. */
772 if (remote_hostcxx . . $ remote_host. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
773 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#));
774 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
775 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
776 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
777 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
778 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
779 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n", argv0, remote_hostcxx . . $ remote_host.);
780 exitcxx . . $ exit(3ca292c338df9bb3).(1);
781 }
782 }
783 memcpycxx . . $ memcpy(cc817cb175f282d).(&remote_addrcxx . . $ remote_addr., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
784 remote_addrcxx . . $ remote_addr..v4cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port); /* equal to v6.sin6_port */
785 if (rp->ai_familycxx . . $ addrinfo#ai_family. == AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!)
786 remote_addrcxx . . $ remote_addr..v6cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v6..sin6_scope_idcxx . . $ sockaddr_in6#sin6_scope_id. = if_indexcxx . . $ if_index.;
787 ra_lencxx . . $ ra_len. = rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.;
788 }
789
790 /* Initialize the global value for interactive mode functions. */
791 if (interactive_modecxx . . $ interactive_mode.) {
792 inter_skcxx . . $ inter_sk. = sk;
793 }
794
795 printfcxx . . $ printf(581fddd72a8db8fc).("%s ready to send...\n", argv0);
796 while (!done) {
797 /* Read from the user. */
798 if (remote_hostcxx . . $ remote_host.) {
799 if (interactive_modecxx . . $ interactive_mode.) {
800 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d-%s:%d Interactive mode> ",
801 local_hostcxx . . $ local_host., local_portcxx . . $ local_port., remote_hostcxx . . $ remote_host.,
802 remote_portcxx . . $ remote_port.);
803 } else {
804 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d-%s:%d> ",
805 local_hostcxx . . $ local_host., local_portcxx . . $ local_port.,
806 remote_hostcxx . . $ remote_host., remote_portcxx . . $ remote_port.);
807 }
808 } else {
809 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d-", local_hostcxx . . $ local_host., local_portcxx . . $ local_port.);
810 if (associdcxx . . $ associd.) {
811 print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).(&remote_addrcxx . . $ remote_addr..sacxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#sa.);
812 } else {
813 printfcxx . . $ printf(581fddd72a8db8fc).("XXXXXX:%d", remote_portcxx . . $ remote_port.);
814 }
815 if (interactive_modecxx . . $ interactive_mode.) {
816 printfcxx . . $ printf(581fddd72a8db8fc).(" Interactive mode> ");
817 } else {
818 printfcxx . . $ printf(581fddd72a8db8fc).("> ");
819 }
820 }
821 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
822 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == fgetscxx . . $ fgets(efb0aaba7ac866ae).(message, REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!, stdincxx . . $ `<external>/232824719582829767/stdio.h:157:9`!)) {
823 done = 1;
824 continue;
825 }
826
827 if (interactive_modecxx . . $ interactive_mode.) {
828 /* This is the send only agent. */
829 if (0 <= (c = parse_inter_commandscxx . . $ parse_inter_commands(60b24ab836da28f5).(argv0, message,
830 1))) {
831 if (INTER_SNDcxx . . $ INTER_SND. == c) {
832 iov.iov_basecxx . . $ iovec#iov_base. = inter_outbufcxx . . $ inter_outbuf.;
833 msglen = inter_outlencxx . . $ inter_outlen.;
834 iov.iov_lencxx . . $ iovec#iov_len. = msglen;
835
836 } else {
837 continue;
838 }
839
840 } else {
841 continue;
842 }
843 } else {
844 /* Send to our neighbor. */
845 msglen = strlencxx . . $ strlen(751346f8406fd082).(message) + 1;
846 iov.iov_lencxx . . $ iovec#iov_len. = msglen;
847 }
848
849 /* For a UDP-style socket, verify if an existing association
850 * has gone. If so, receive the pending SCTP_ASSOC_CHANGE
851 * notification.
852 */
853 if ((SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type.) && associdcxx . . $ associd. &&
854 (0 != test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(sk, associdcxx . . $ associd.))) {
855 associdcxx . . $ associd. = test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(sk);
856 printfcxx . . $ printf(581fddd72a8db8fc).("Old association gone, Starting a new one!\n");
857 new_connectioncxx . . $ new_connection. = 1;
858 }
859
860 if (new_connectioncxx . . $ new_connection. && connectx_countcxx . . $ connectx_count. != 0) {
861 /* Do a sctp_connectx() to establish a connection. */
862 error = connectx_funccxx . . $ connectx_func(73b07b87c343dc96).(argv0, sk, connectx_addrscxx . . $ connectx_addrs.,
863 connectx_countcxx . . $ connectx_count.);
864 if (0 != error) {
865 if (error == -2) {
866 printfcxx . . $ printf(581fddd72a8db8fc).("Connection refused\n");
867 if (SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type.) {
868 associdcxx . . $ associd. = test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(sk);
869 }
870 continue;
871 }
872 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "connectx failed.\n");
873 exitcxx . . $ exit(3ca292c338df9bb3).(1);
874 }
875 if (SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type.) {
876 associdcxx . . $ associd. = test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(sk);
877 } else {
878 associdcxx . . $ associd. = 1;
879 }
880 int rc = sctp_getpaddrscxx . . $ sctp_getpaddrs(481df579f251e854).(sk, associdcxx . . $ associd., &addrs);
881 if (0 >= rc) {
882 if (rc == 0) {
883 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "sctp_getpaddrs failed, no peers.\n");
884 } else {
885 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "sctp_getpaddrs failed %s(%d).\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
886 }
887 exitcxx . . $ exit(3ca292c338df9bb3).(1);
888 }
889 printfcxx . . $ printf(581fddd72a8db8fc).("New connection, peer addresses\n");
890 print_addr_bufcxx . . $ print_addr_buf(d0320739773070f2).(addrs, rc);
891 ra_familycxx . . $ ra_family. = addrs[0].sa_familycxx . . $ sockaddr#sa_family.;
892 switch (ra_familycxx . . $ ra_family.) {
893 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
894 ra_lencxx . . $ ra_len. = sizeof(remote_addrcxx . . $ remote_addr..v4cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v4.);
895 break;
896 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
897 ra_lencxx . . $ ra_len. = sizeof(remote_addrcxx . . $ remote_addr..v6cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v6.);
898 break;
899 default:
900 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Invalid address type.\n");
901 exitcxx . . $ exit(3ca292c338df9bb3).(1);
902 }
903 memcpycxx . . $ memcpy(cc817cb175f282d).(&remote_addrcxx . . $ remote_addr., &addrs[0], ra_lencxx . . $ ra_len.);
904 sctp_freepaddrscxx . . $ sctp_freepaddrs(10d3a1a0427e771a).(addrs);
905 new_connectioncxx . . $ new_connection. = 0;
906 }
907
908 do {
909 if (SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type. ||
910 (connectx_countcxx . . $ connectx_count. == 0 && new_connectioncxx . . $ new_connection.)) {
911 /* Initialize the message struct we use to pass
912 * messages to the remote socket.
913 */
914 if (!interactive_modecxx . . $ interactive_mode.) {
915 iov.iov_basecxx . . $ iovec#iov_base. = message;
916 iov.iov_lencxx . . $ iovec#iov_len. = msglen;
917 }
918 outmsg.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
919 outmsg.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
920 outmsg.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
921 outmsg.msg_controllencxx . . $ msghdr#msg_controllen. = 0;
922 outmsg.msg_namecxx . . $ msghdr#msg_name. = &remote_addrcxx . . $ remote_addr.;
923 outmsg.msg_namelencxx . . $ msghdr#msg_namelen. = ra_lencxx . . $ ra_len.;
924 outmsg.msg_flagscxx . . $ msghdr#msg_flags. = 0;
925
926 error = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(sk, &outmsg, 0);
927 } else {
928 error = sendcxx . . $ send(4e364047dcdcb5ca).(sk, message, msglen, 0);
929 if (error == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EPIPEcxx . . $ `<external>/8987895939074593727/errno-base.h:36:9`!) {
930 error = closecxx . . $ close(7864480464b09eea).(sk);
931 if (error != 0) {
932 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "close failed %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
933 exitcxx . . $ exit(3ca292c338df9bb3).(1);
934 }
935 *skp = sk = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv0, local_portcxx . . $ local_port.);
936 break;
937 }
938 }
939
940 if (error != msglen) {
941 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error: %s.\n",
942 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
943 if (nonblockingcxx . . $ nonblocking. && EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! == errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) {
944 if (interactive_modecxx . . $ interactive_mode.) {
945 break;
946 }
947 continue;
948 }
949 exitcxx . . $ exit(3ca292c338df9bb3).(1);
950 } else {
951 break;
952 }
953 } while (error != msglen);
954
955 /* If this is the first message sent over a UDP-style socket,
956 * get the associd from the SCTP_ASSOC_CHANGE notification.
957 */
958 if ((SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`! == socket_typecxx . . $ socket_type.) && (0 == associdcxx . . $ associd.))
959 associdcxx . . $ associd. = test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(sk);
960
961 /* Verify there is no association. */
962 if (0 != test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(sk, associdcxx . . $ associd.)) {
963 printfcxx . . $ printf(581fddd72a8db8fc).("No association is present now!!\n");
964 new_connectioncxx . . $ new_connection. = 1;
965 } else {
966 if (new_connectioncxx . . $ new_connection.) {
967 int rc = sctp_getpaddrscxx . . $ sctp_getpaddrs(481df579f251e854).(sk, associdcxx . . $ associd., &addrs);
968 if (0 >= rc) {
969 if (rc == 0) {
970 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "sctp_getpaddrs failed, no peers.\n");
971 } else {
972 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "sctp_getpaddrs failed %s(%d).\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
973 }
974 exitcxx . . $ exit(3ca292c338df9bb3).(1);
975 }
976 printfcxx . . $ printf(581fddd72a8db8fc).("New connection, peer addresses\n");
977 print_addr_bufcxx . . $ print_addr_buf(d0320739773070f2).(addrs, rc);
978 sctp_freepaddrscxx . . $ sctp_freepaddrs(10d3a1a0427e771a).(addrs);
979 new_connectioncxx . . $ new_connection. = 0;
980 }
981 }
982
983 /* Clean up. */
984 if (interactive_modecxx . . $ interactive_mode.) {
985 freecxx . . $ free(5d22bdacc48458e8).(inter_outbufcxx . . $ inter_outbuf.);
986 inter_outbufcxx . . $ inter_outbuf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
987 }
988 } /* while(!done) */
989
990 return error;
991
992 } /* command_send() */
993
994 /* Listen on the array of sockets, printing out anything that arrives. */
995 int
996 command_pollcxx . . $ command_poll(1ef8e6ec083aabb9).(char *argv0)
997 {
998 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(_sctp_cmsg_data_t))];
999 struct ioveccxx . . $ iovec# iov;
1000 struct msghdrcxx . . $ msghdr# inmessage;
1001 int done = 0;
1002 int error = 0;
1003 int max_fd, i, ret;
1004 int size;
1005 fd_setcxx . . $ fd_set# *ibitsp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1006 fd_setcxx . . $ fd_set# *obitsp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1007 fd_setcxx . . $ fd_set# *xbitsp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1008
1009 struct msghdrcxx . . $ msghdr# outmsg;
1010 struct addrinfocxx . . $ addrinfo# hints, *rp;
1011 int msglen;
1012 int temp_fd, temp_set;
1013
1014
1015
1016 /* If a remote host is specified, initialize the destination. */
1017 if (remote_hostcxx . . $ remote_host.) {
1018 /* Set up the destination. */
1019 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#));
1020 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
1021 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
1022 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
1023 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
1024 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
1025 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n", argv0, remote_hostcxx . . $ remote_host.);
1026 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1027 }
1028 }
1029 memcpycxx . . $ memcpy(cc817cb175f282d).(&remote_addrcxx . . $ remote_addr., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
1030 remote_addrcxx . . $ remote_addr..v4cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port); /* equal to v6.sin6_port */
1031 if (rp->ai_familycxx . . $ addrinfo#ai_family. == AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!)
1032 remote_addrcxx . . $ remote_addr..v6cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v6..sin6_scope_idcxx . . $ sockaddr_in6#sin6_scope_id. = if_indexcxx . . $ if_index.;
1033
1034 /* Initialize the message struct we use to pass messages to
1035 * the remote socket.
1036 */
1037 outmsg.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
1038 outmsg.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
1039 outmsg.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1040 outmsg.msg_controllencxx . . $ msghdr#msg_controllen. = 0;
1041 outmsg.msg_namecxx . . $ msghdr#msg_name. = &remote_addrcxx . . $ remote_addr.;
1042 outmsg.msg_namelencxx . . $ msghdr#msg_namelen. = rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.;
1043 outmsg.msg_flagscxx . . $ msghdr#msg_flags. = 0;
1044 }
1045
1046
1047 max_fd = -1;
1048
1049 /* Set all of the sockets to be ready for listening. */
1050 if (use_pollcxx . . $ use_poll.) {
1051 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
1052 error = listencxx . . $ listen(9b79fb6aee4c0440).(poll_fdscxx . . $ poll_fds.[i].fdcxx . . $ pollfd#fd., 1);
1053 if (error != 0) {
1054 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Listen failed on socket number ",
1055 argv0);
1056 printfcxx . . $ printf(581fddd72a8db8fc).("%d: %s.\n", i, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1057 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1058 }
1059 }
1060 printfcxx . . $ printf(581fddd72a8db8fc).("%s listening...\n", argv0);
1061 } else {
1062 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
1063 error = listencxx . . $ listen(9b79fb6aee4c0440).(poll_skscxx . . $ poll_sks.[i], 1);
1064 if (error != 0) {
1065 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Listen failed on socket number ",
1066 argv0);
1067 printfcxx . . $ printf(581fddd72a8db8fc).("%d: %s.\n", i, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1068 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1069 }
1070 if (poll_skscxx . . $ poll_sks.[i] > max_fd) {
1071 max_fd = poll_skscxx . . $ poll_sks.[i];
1072 }
1073 }
1074 printfcxx . . $ printf(581fddd72a8db8fc).("%s listening...\n", argv0);
1075
1076 size = howmanycxx . . $ `<external>/1231830743887005719/param.h:90:10`!(max_fd + 1, NFDBITScxx . . $ `<external>/946878812840035423/select.h:80:10`!) * sizeof(fd_maskcxx . . $ fd_mask#);
1077 if ((ibitsp = (fd_setcxx . . $ fd_set# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
1078 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", argv0);
1079 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1080 }
1081 if ((obitsp = (fd_setcxx . . $ fd_set# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
1082 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", argv0);
1083 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1084 }
1085 if ((xbitsp = (fd_setcxx . . $ fd_set# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
1086 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", argv0);
1087 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1088 }
1089 memsetcxx . . $ memset(d1de1e4fb215f1c6).(ibitsp, 0, size);
1090 memsetcxx . . $ memset(d1de1e4fb215f1c6).(obitsp, 0, size);
1091 memsetcxx . . $ memset(d1de1e4fb215f1c6).(xbitsp, 0, size);
1092 }
1093
1094
1095 /* Initialize inmessage with enough space for DATA... */
1096 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
1097 if ((iov.iov_basecxx . . $ iovec#iov_base. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
1098 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", argv0);
1099 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1100 }
1101 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!;
1102 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
1103 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
1104 /* or a control message. */
1105 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
1106 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
1107
1108
1109 done = 0;
1110 /* Set the default send message size. */
1111 if (!poll_snd_sizecxx . . $ poll_snd_size.) {
1112 poll_snd_sizecxx . . $ poll_snd_size. = POLL_SND_SIZEcxx . . $ `src/apps/sctp_darn.c:179:9`!;
1113 }
1114
1115 while (!done) {
1116
1117 if (use_pollcxx . . $ use_poll.) {
1118 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
1119 poll_fdscxx . . $ poll_fds.[i].eventscxx . . $ pollfd#events. = POLLINcxx . . $ `<external>/17223861378049612178/poll.h:25:9`!;
1120 }
1121 if (remote_hostcxx . . $ remote_host.) {
1122 /* Poll output on the first socket. */
1123 poll_fdscxx . . $ poll_fds.[0].eventscxx . . $ pollfd#events. |= POLLOUTcxx . . $ `<external>/17223861378049612178/poll.h:27:9`!;
1124 }
1125
1126 if ((ret = pollcxx . . $ poll(bc0744c797f613bd).(poll_fdscxx . . $ poll_fds., poll_skncxx . . $ poll_skn., -1))) {
1127 if (ret == -1) {
1128 break;
1129 }
1130 }
1131 } else {
1132 for (i = 0; i < poll_skncxx . . $ poll_skn.; i++) {
1133 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(poll_sks[i], ibitsp);
1134 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(poll_sks[i], xbitsp);
1135 }
1136 if (remote_hostcxx . . $ remote_host.) {
1137 /* Only select output on the first socket. */
1138 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(poll_sks[0], obitsp);
1139 }
1140
1141
1142 if ((ret = selectcxx . . $ select(6d24c7514c8a5b88).(max_fd + 1, ibitsp, obitsp, xbitsp,
1143 (struct timevalcxx . . $ timeval# *)0)) < 0) {
1144 if (ret == -1) {
1145 break;
1146 }
1147 }
1148
1149 }
1150
1151 if (remote_hostcxx . . $ remote_host.) {
1152 if (use_pollcxx . . $ use_poll.) {
1153 temp_set = poll_fdscxx . . $ poll_fds.[0].reventscxx . . $ pollfd#revents. & POLLOUTcxx . . $ `<external>/17223861378049612178/poll.h:27:9`!;
1154 temp_fd = poll_fdscxx . . $ poll_fds.[0].fdcxx . . $ pollfd#fd.;
1155 } else {
1156 temp_set = FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(poll_sks[0], obitsp);
1157 temp_fd = poll_skscxx . . $ poll_sks.[0];
1158 }
1159
1160 if (temp_set) {
1161 inter_outbufcxx . . $ inter_outbuf. = gen_messagecxx . . $ gen_message(ff224f080444ee45).(poll_snd_sizecxx . . $ poll_snd_size.);
1162 if (!inter_outbufcxx . . $ inter_outbuf.) {
1163 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
1164 "Cannot allocate out message.\n");
1165 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1166 }
1167 iov.iov_basecxx . . $ iovec#iov_base. = inter_outbufcxx . . $ inter_outbuf.;
1168 msglen = poll_snd_sizecxx . . $ poll_snd_size.;
1169 iov.iov_lencxx . . $ iovec#iov_len. = msglen;
1170
1171 error = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(temp_fd, &outmsg, 0);
1172 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
1173 "sent a message, msglen = %d\n",
1174 msglen);
1175
1176 if (error != msglen) {
1177 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error: %s.\n",
1178 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1179 if ((!nonblockingcxx . . $ nonblocking.) ||
1180 (EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)) {
1181 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1182 }
1183 }
1184
1185 /* Clean up. */
1186 freecxx . . $ free(5d22bdacc48458e8).(inter_outbufcxx . . $ inter_outbuf.);
1187 inter_outbufcxx . . $ inter_outbuf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1188 }
1189
1190 } /* while(!done) */
1191
1192 for (i = 0; !done && (i < poll_skncxx . . $ poll_skn.); i++) {
1193 if (use_pollcxx . . $ use_poll.) {
1194 temp_set = poll_fdscxx . . $ poll_fds.[i].reventscxx . . $ pollfd#revents. & POLLINcxx . . $ `<external>/17223861378049612178/poll.h:25:9`!;
1195 temp_fd = poll_fdscxx . . $ poll_fds.[i].fdcxx . . $ pollfd#fd.;
1196 } else {
1197 temp_set = FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(poll_sks[i], ibitsp);
1198 temp_fd = poll_skscxx . . $ poll_sks.[i];
1199 }
1200 if (temp_set) {
1201 error = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(temp_fd, &inmessage,
1202 MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
1203 if (error < 0) {
1204 if ((EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! == errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)) {
1205 error = 0;
1206 continue;
1207 }
1208 else {
1209 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
1210 "%s: error: %s.\n",
1211 argv0,
1212 strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1213 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1214 }
1215 }
1216 test_print_messagecxx . . $ test_print_message(3755aa3826476a13).(temp_fd, &inmessage, error);
1217 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
1218 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
1219 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!;
1220 }
1221
1222 /* Update the associd when a notification is received
1223 * on a UDP-style socket.
1224 */
1225 if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!)
1226 associdcxx . . $ associd. = test_verify_assoc_changecxx . . $ test_verify_assoc_change(615209a3b05c63a0).(&inmessage);
1227
1228 /* Verify there is no association. */
1229 if (0 != test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(poll_skscxx . . $ poll_sks.[i], associdcxx . . $ associd.)) {
1230 printfcxx . . $ printf(581fddd72a8db8fc).("No association is present in sk "
1231 "No.%d now!!\n",i);
1232 }
1233 }
1234
1235 }
1236
1237 if (!use_pollcxx . . $ use_poll.) {
1238 freecxx . . $ free(5d22bdacc48458e8).(ibitsp);
1239 freecxx . . $ free(5d22bdacc48458e8).(obitsp);
1240 freecxx . . $ free(5d22bdacc48458e8).(xbitsp);
1241 }
1242
1243 return error;
1244
1245 } /* command_poll() */
1246
1247 /********************************************************************
1248 * 3rd Level Abstractions
1249 ********************************************************************/
1250
1251 #define FPScxx . . $ `src/apps/sctp_darn.c:1251:9`!(arg) fprintf(stderr, arg)
1252
1253 void
1254 usagecxx . . $ usage(fda57c8427c60377).(char *argv0)
1255 {
1256 /*
1257 * The bindx options, --bindx-add and --bindx-rem, are added to
1258 *
1259 * 1. provide first testcases for the new bindx system call
1260 *
1261 * 2. continue to grow sctp_darn with more functions and
1262 * features so it will be equivalent to the "sock" tool for
1263 * TCP as for SCTP.
1264 *
1265 * FIXME -
1266 *
1267 * It is not very effective to use these two options in the
1268 * current command line mode of sctp_darn. For example, the
1269 * --bindx-rem option can only be used in conjunction with the
1270 * --bindx-add simply to test the function in the kernel
1271 * path. Ideally, bindx needs to be tested by a tool which
1272 * provides an interactive mode for users to change parameters
1273 * and configuration dynamically with existing endpoints and
1274 * associations.
1275 */
1276 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Usage: %s -H <localhost> -P <localport> "
1277 "[-h <remotehost>] [-p <remoteport>] -l|s\n"
1278 " -H, --local\t\tspecify one of the local addresses,\n"
1279 " -P, --local-port\tspecify the port number for local addresses,\n"
1280 " -h, --remote\t\tspecify the peer address,\n"
1281 " -p, --remote-port\tspecify the port number for the peer address,\n"
1282 " -l, --listen\t\tprint messages received from the peer,\n"
1283 " -s, --send\t\tsend messages to the peer,\n"
1284 " -B, --bindx-add"
1285 "\tadd the specified address(es) as additional bind\n"
1286 "\t\t\taddresses to the local socket. Multiple addresses can\n"
1287 "\t\t\tbe specified by using this argument multiple times.\n"
1288 "\t\t\tFor example, '-B 10.0.0.1 -B 20.0.0.2'.\n"
1289 " -b, --bindx-rem"
1290 "\tremove the specified address(es) from the bind\n"
1291 "\t\t\taddresses of the local socket. Multiple addresses can\n"
1292 "\t\t\tbe specified by using this argument multiple times.\n"
1293 "\t\t\tFor example, '-b 10.0.0.1 -b 20.0.0.2'.\n"
1294 " -c, --connectx"
1295 "\t\tuse the specified address(es) for connection to the\n"
1296 "\t\t\tpeer socket. Multiple addresses can be specified by\n"
1297 "\t\t\tusing this argument multiple times.\n"
1298 "\t\t\tFor example, '-c 10.0.0.1 -c 20.0.0.2'.\n"
1299 "\t\t\tThis option is incompatible with the -h option.\n"
1300 " -I\t\t\tuse the interactive mode.\n"
1301 " -i\t\t\tsetup the specified number of endpoints by using the\n"
1302 "\t\t\tspecified local host (-H) and local port (-P). The port\n"
1303 "\t\t\tnumber will be incremented by one for each additional\n"
1304 "\t\t\tendpoint. All of these endpoints will be listening.\n"
1305 "\t\t\tIf a remote host (-h) and a remote port are also\n"
1306 "\t\t\tspecified, the first endpoint will start sending fixed\n"
1307 "\t\t\tsized messages to the remote host.\n"
1308 " -m\t\t\tspecify the sockopt sndbuf/rcvbuf size.\n"
1309 " -n\t\t\tset the socket(s) to be in the non-blocking mode.\n"
1310 "\t\t\tcollect messages from stdin and deliver them to the\n"
1311 "\t\t\tpeer,\n"
1312 "--use-poll\t\tuse system call poll() for polling among the\n"
1313 "\t\t\tnumber of endpoints specified by the -i option. Without\n"
1314 "\t\t\tthis option, select() would be used as default.\n"
1315 " -t\t\t\tuse SOCK_STREAM tcp-style sockets.\n"
1316 " -z\t\t\tspecify the message size to be sent. The default\n"
1317 "\t\t\tmessage size generated would be 16K.\n"
1318 " --interface=\"ifname\"\tselect interface for sin6_scope_id.\n",
1319 argv0);
1320 }
1321
1322
1323 /* This function checks messages to see if they are of type 'event'
1324 * and if they are well-formed.
1325 */
1326 int
1327 user_test_check_messagecxx . . $ user_test_check_message(6d75b6af741cd7ac).(struct msghdrcxx . . $ msghdr# *msg,
1328 int controllen,
1329 sctp_cmsg_tcxx . . $ sctp_cmsg_t# event)
1330 {
1331
1332
1333 if (msg->msg_controllencxx . . $ msghdr#msg_controllen. != controllen) {
1334 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
1335 "Got control structure of length %zu, not %d\n",
1336 msg->msg_controllencxx . . $ msghdr#msg_controllen., controllen);
1337 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1338 }
1339 if (controllen > 0 && event != CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(msg)->cmsg_typecxx . . $ cmsghdr#cmsg_type.) {
1340 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Wrong kind of event: %d, not %d\n",
1341 CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(msg)->cmsg_typecxx . . $ cmsghdr#cmsg_type., event);
1342 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1343 }
1344
1345 return 1;
1346
1347 } /* user_test_check_message() */
1348
1349 /* Add another address represented as the string 'parm' to the list
1350 * addrs. The argument count is the number of addrs on input and is
1351 * adjusted for output.
1352 */
1353 struct sockaddrcxx . . $ sockaddr# *
1354 append_addrcxx . . $ append_addr(739737ae76601d7b).(const char *parm, struct sockaddrcxx . . $ sockaddr# *addrs, int *ret_count)
1355 {
1356 struct sockaddrcxx . . $ sockaddr# *new_addrs = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1357 struct addrinfocxx . . $ addrinfo# hints, *res, *rp;
1358 void *aptr;
1359 struct sockaddrcxx . . $ sockaddr# *sa_addr;
1360 struct sockaddr_incxx . . $ sockaddr_in# *b4ap;
1361 struct sockaddr_in6cxx . . $ sockaddr_in6# *b6ap;
1362 int j;
1363 int orig_count = *ret_count;
1364 int count = orig_count;
1365
1366
1367 if (!parm)
1368 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1369
1370 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#));
1371 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_UNSPECcxx . . $ `<external>/8962547315054503424/socket.h:93:9`!;
1372 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
1373 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(parm, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &res) != 0) {
1374 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "bad hostname: %s\n", parm);
1375 goto finally;
1376 }
1377
1378 for (rp = res; rp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; rp = rp->ai_nextcxx . . $ addrinfo#ai_next.)
1379 count++;
1380
1381 /* Expand memory for the new addresses. Assume all the addresses
1382 * are v6 addresses.
1383 */
1384 new_addrs = (struct sockaddrcxx . . $ sockaddr# *)
1385 realloccxx . . $ realloc(417ab160f6baadc6).(addrs, sizeof(struct sockaddr_in6cxx . . $ sockaddr_in6#) * count);
1386
1387 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == new_addrs) {
1388 count = *ret_count;
1389 goto finally;
1390 }
1391
1392 /* Skip the existing addresses. */
1393 aptr = new_addrs;
1394 for (j = 0; j < orig_count; j++) {
1395 sa_addr = (struct sockaddrcxx . . $ sockaddr# *)aptr;
1396 switch(sa_addr->sa_familycxx . . $ sockaddr#sa_family.) {
1397 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
1398 aptr += sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
1399 break;
1400 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
1401 aptr += sizeof(struct sockaddr_in6cxx . . $ sockaddr_in6#);
1402 break;
1403 default:
1404 count = orig_count;
1405 goto finally;
1406 }
1407 }
1408
1409 /* Put the new addresses away. */
1410 for (rp = res; rp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; rp = rp->ai_nextcxx . . $ addrinfo#ai_next.) {
1411 b4ap = (struct sockaddr_incxx . . $ sockaddr_in# *)aptr;
1412 b6ap = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)aptr;
1413 bcopycxx . . $ bcopy(5af7fc07d59c1858).(rp->ai_addrcxx . . $ addrinfo#ai_addr., aptr, rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
1414 b4ap->sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(local_port); /* equal to b6ap.v6.sin6_port */
1415 if (rp->ai_familycxx . . $ addrinfo#ai_family. == AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!)
1416 b6ap->sin6_scope_idcxx . . $ sockaddr_in6#sin6_scope_id. = if_indexcxx . . $ if_index.;
1417 aptr += rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.;
1418 }
1419
1420 finally:
1421
1422 *ret_count = count;
1423
1424 return new_addrs;
1425
1426 } /* append_addr() */
1427
1428 static int
1429 parse_inter_commandscxx . . $ parse_inter_commands(60b24ab836da28f5).(char *argv0, char *input, int snd_only)
1430 {
1431 int i;
1432 char *p;
1433 int len;
1434 int set = 0;
1435 int val;
1436 struct sockaddrcxx . . $ sockaddr# *tmp_addrs = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1437
1438
1439 p = input;
1440 if (*p == '?' || *p == '\n') {
1441 printfcxx . . $ printf(581fddd72a8db8fc).("Interactive commands:\n");
1442 printfcxx . . $ printf(581fddd72a8db8fc).("snd=<int> - Do a sendmsg with the specified");
1443 printfcxx . . $ printf(581fddd72a8db8fc).(" length.\n");
1444 printfcxx . . $ printf(581fddd72a8db8fc).("rcv=<int> - Do a recvmsg.");
1445 printfcxx . . $ printf(581fddd72a8db8fc).("The length is ignored for now.\n");
1446 printfcxx . . $ printf(581fddd72a8db8fc).("bindx-add=<addr> - Add a local address");
1447 printfcxx . . $ printf(581fddd72a8db8fc).(" with bindx. \n");
1448 printfcxx . . $ printf(581fddd72a8db8fc).("bindx-rem=<addr> - Remove a local address");
1449 printfcxx . . $ printf(581fddd72a8db8fc).(" with bindx. \n");
1450 printfcxx . . $ printf(581fddd72a8db8fc).("rcvbuf=<int> - Get/Set receive buffer size\n");
1451 printfcxx . . $ printf(581fddd72a8db8fc).("sndbuf=<int> - Get/Set send buffer size.\n");
1452 printfcxx . . $ printf(581fddd72a8db8fc).("primary=<addr> - Get/Set association's primary\n");
1453 printfcxx . . $ printf(581fddd72a8db8fc).("peer_primary=addr- Set association's peer_primary\n");
1454 printfcxx . . $ printf(581fddd72a8db8fc).("heartbeat=<addr> - Request a user initiated heartbeat\n");
1455 printfcxx . . $ printf(581fddd72a8db8fc).("maxseg=<int> - Get/Set Maximum fragment size.\n");
1456 printfcxx . . $ printf(581fddd72a8db8fc).("nodelay=<0|1> - Get/Set NODELAY option.\n");
1457 printfcxx . . $ printf(581fddd72a8db8fc).("shutdown - Shutdown the association.\n");
1458 printfcxx . . $ printf(581fddd72a8db8fc).("abort - Abort the association.\n");
1459 printfcxx . . $ printf(581fddd72a8db8fc).("stats - Print GET_ASSOC_STATS (if available in kernel).\n");
1460 printfcxx . . $ printf(581fddd72a8db8fc).("? - Help. Display this message.\n");
1461 return -1;
1462 }
1463
1464 for (i = 0; i < REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!; i++) {
1465 if (('=' == *p) ||
1466 ('?' == *p) ||
1467 ('\n' == *p)) {
1468 if ('=' == *p) {
1469 set = 1;
1470 }
1471 *p++ = '\0';
1472 break;
1473 }
1474 p++;
1475 }
1476 if (i >= REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!) {
1477 printfcxx . . $ printf(581fddd72a8db8fc).("Invalid input.\n");
1478 return -1;
1479 }
1480
1481 i = 0;
1482 while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != inter_commandscxx . . $ inter_commands.[i].cmdcxx . . $ inter_entry#cmd.) {
1483 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(input, inter_commandscxx . . $ inter_commands.[i].cmdcxx . . $ inter_entry#cmd.)) {
1484 switch (i) {
1485 case INTER_SNDcxx . . $ INTER_SND.:
1486 if (snd_only) {
1487 if (*p < '0' || *p > '9') {
1488 goto err_input;
1489 }
1490 snd_funccxx . . $ snd_func(fda57c8427c60377).(p);
1491 } else {
1492 goto err_input;
1493 }
1494 break;
1495 case INTER_RCVcxx . . $ INTER_RCV.:
1496 if (snd_only) {
1497 goto err_input;
1498 }
1499 break;
1500 case INTER_SNDBUFcxx . . $ INTER_SNDBUF.:
1501 if (set) {
1502 if (*p < '0' || *p > '9') {
1503 goto err_input;
1504 }
1505 }
1506 len = (set) ? atoicxx . . $ atoi(5c4306d8553b3696).(p) : 0;
1507 sndbuf_funccxx . . $ sndbuf_func(51648a5edc2089b5).(argv0, inter_skcxx . . $ inter_sk., len, set);
1508 break;
1509 case INTER_RCVBUFcxx . . $ INTER_RCVBUF.:
1510 if (set) {
1511 if (*p < '0' || *p > '9') {
1512 goto err_input;
1513 }
1514 }
1515 len = (set) ? atoicxx . . $ atoi(5c4306d8553b3696).(p) : 0;
1516 rcvbuf_funccxx . . $ rcvbuf_func(51648a5edc2089b5).(argv0, inter_skcxx . . $ inter_sk., len, set);
1517 break;
1518 case INTER_BINDX_ADDcxx . . $ INTER_BINDX_ADD.:
1519 tmp_addrs = get_bindx_addrcxx . . $ get_bindx_addr(521cf95a28fabae7).(p, &len);
1520 bindx_funccxx . . $ bindx_func(fb084d643e22d309).(argv0, inter_skcxx . . $ inter_sk., tmp_addrs, len,
1521 SCTP_BINDX_ADD_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:1061:9`!, local_portcxx . . $ local_port.);
1522 freecxx . . $ free(5d22bdacc48458e8).(tmp_addrs);
1523 break;
1524 case INTER_BINDX_REMcxx . . $ INTER_BINDX_REM.:
1525 tmp_addrs = get_bindx_addrcxx . . $ get_bindx_addr(521cf95a28fabae7).(p, &len);
1526 bindx_funccxx . . $ bindx_func(fb084d643e22d309).(argv0, inter_skcxx . . $ inter_sk., tmp_addrs, len,
1527 SCTP_BINDX_REM_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:1062:9`!, local_portcxx . . $ local_port.);
1528 freecxx . . $ free(5d22bdacc48458e8).(tmp_addrs);
1529 break;
1530 case INTER_SET_PRIMcxx . . $ INTER_SET_PRIM.:
1531 primary_funccxx . . $ primary_func(7c7b1413e571f034).(argv0, inter_skcxx . . $ inter_sk., p, set);
1532 break;
1533 case INTER_SET_PEER_PRIMcxx . . $ INTER_SET_PEER_PRIM.:
1534 peer_primary_funccxx . . $ peer_primary_func(7c7b1413e571f034).(argv0, inter_skcxx . . $ inter_sk., p, set);
1535 break;
1536 case INTER_HEARTBEATcxx . . $ INTER_HEARTBEAT.:
1537 spp_hb_demand_funccxx . . $ spp_hb_demand_func(7c7b1413e571f034).(argv0, inter_skcxx . . $ inter_sk., p, set);
1538 break;
1539 case INTER_SHUTDOWNcxx . . $ INTER_SHUTDOWN.:
1540 shutdown_funccxx . . $ shutdown_func(be750502182deecd).(argv0, &inter_skcxx . . $ inter_sk., SHUTDOWN_SHUTDOWNcxx . . $ SHUTDOWN_SHUTDOWN.);
1541 break;
1542 case INTER_ABORTcxx . . $ INTER_ABORT.:
1543 shutdown_funccxx . . $ shutdown_func(be750502182deecd).(argv0, &inter_skcxx . . $ inter_sk., SHUTDOWN_ABORTcxx . . $ SHUTDOWN_ABORT.);
1544 break;
1545 case INTER_NODELAYcxx . . $ INTER_NODELAY.:
1546 if (set) {
1547 if (*p < '0' || *p > '9') {
1548 goto err_input;
1549 }
1550 }
1551 val = (set) ? atoicxx . . $ atoi(5c4306d8553b3696).(p) : 0;
1552 nodelay_funccxx . . $ nodelay_func(cd0c04d3624ba1ca).(argv0, inter_skcxx . . $ inter_sk., val, set);
1553 break;
1554 case INTER_MAXSEGcxx . . $ INTER_MAXSEG.:
1555 if (set) {
1556 if (*p < '0' || *p > '9') {
1557 goto err_input;
1558 }
1559 }
1560 val = (set) ? atoicxx . . $ atoi(5c4306d8553b3696).(p) : 0;
1561 maxseg_funccxx . . $ maxseg_func(cd0c04d3624ba1ca).(argv0, inter_skcxx . . $ inter_sk., val, set);
1562 break;
1563 case INTER_GET_STATScxx . . $ INTER_GET_STATS.:
1564 get_assocstats_funccxx . . $ get_assocstats_func(9b79fb6aee4c0440).(inter_skcxx . . $ inter_sk., associdcxx . . $ associd.);
1565 break;
1566 default:
1567 goto err_input;
1568 break;
1569 }
1570
1571 return i;
1572 }
1573 i++;
1574 }
1575
1576 err_input:
1577 printfcxx . . $ printf(581fddd72a8db8fc).("Invalid input.\n");
1578 return -1;
1579
1580 } /* parse_inter_commands() */
1581
1582 static char *
1583 gen_messagecxx . . $ gen_message(ff224f080444ee45).(int len)
1584 {
1585
1586 char *buf;
1587 char *p;
1588 int i;
1589
1590 buf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len);
1591
1592 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != buf) {
1593 for (i = 0, p = buf; i < len; i++, p++) {
1594 if (gen_datacxx . . $ gen_data. > GEN_DATA_LASTcxx . . $ `src/apps/sctp_darn.c:79:9`!) {
1595 gen_datacxx . . $ gen_data. = GEN_DATA_FIRSTcxx . . $ `src/apps/sctp_darn.c:78:9`!;
1596 }
1597 *p = gen_datacxx . . $ gen_data.++;
1598 }
1599 }
1600
1601 return(buf);
1602
1603 } /* gen_message() */
1604
1605 static void
1606 snd_funccxx . . $ snd_func(fda57c8427c60377).(char *input)
1607 {
1608
1609 int len;
1610
1611 len = atoicxx . . $ atoi(5c4306d8553b3696).(input);
1612 if (!(inter_outbufcxx . . $ inter_outbuf. = gen_messagecxx . . $ gen_message(ff224f080444ee45).(len))) {
1613 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot allocate out message.\n");
1614 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1615 }
1616 inter_outlencxx . . $ inter_outlen. = len;
1617
1618 } /* snd_func() */
1619
1620 static void
1621 sndbuf_funccxx . . $ sndbuf_func(51648a5edc2089b5).(char *argv0, int sk, int len, int set)
1622 {
1623 int error;
1624 socklen_tcxx . . $ socklen_t# optlen;
1625
1626 if (set) {
1627 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_SNDBUFcxx . . $ `<external>/9030916627833342711/socket.h:17:9`!,
1628 (char *)&len, sizeof(len));
1629 } else {
1630 optlen = sizeof(len);
1631 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_SNDBUFcxx . . $ `<external>/9030916627833342711/socket.h:17:9`!,
1632 (char *)&len, &optlen);
1633 }
1634 if (error != 0) {
1635 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Error setting/getting sndbuf: %s.\n",
1636 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1637 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1638 }
1639
1640 if (!set) {
1641 printfcxx . . $ printf(581fddd72a8db8fc).("sndbuf is %d.\n", len);
1642 }
1643
1644 } /* sndbuf_func() */
1645
1646 static void
1647 rcvbuf_funccxx . . $ rcvbuf_func(51648a5edc2089b5).(char *argv0, int sk, int len, int set)
1648 {
1649 int error;
1650 socklen_tcxx . . $ socklen_t# optlen;
1651
1652 if (set) {
1653 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_RCVBUFcxx . . $ `<external>/9030916627833342711/socket.h:18:9`!,
1654 (char *)&len, sizeof(len));
1655 } else {
1656 optlen = sizeof(len);
1657 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_RCVBUFcxx . . $ `<external>/9030916627833342711/socket.h:18:9`!,
1658 (char *)&len, &optlen);
1659 }
1660 if (error != 0) {
1661 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Error setting/getting rcvbuf: %s.\n",
1662 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1663 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1664 }
1665
1666 if (!set) {
1667 printfcxx . . $ printf(581fddd72a8db8fc).("rcvbuf is %d.\n", len);
1668 }
1669
1670 } /* rcvbuf_func() */
1671
1672
1673 static struct sockaddrcxx . . $ sockaddr# *
1674 get_bindx_addrcxx . . $ get_bindx_addr(521cf95a28fabae7).(char *in, int *count)
1675 {
1676
1677 struct sockaddrcxx . . $ sockaddr# *tmp_addrs = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1678 char *p = in;
1679
1680 /* Set the buffer for address parsing. */
1681 while ('\n' != *p) {
1682 p++;
1683 }
1684 *p = '\0';
1685
1686 *count = 0;
1687
1688 tmp_addrs = append_addrcxx . . $ append_addr(739737ae76601d7b).(in, tmp_addrs, count);
1689 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == tmp_addrs) {
1690 /* We have no memory, so keep fprintf()
1691 * from trying to allocate more.
1692 */
1693 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "No memory to add ");
1694 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n", in);
1695 exitcxx . . $ exit(3ca292c338df9bb3).(2);
1696 }
1697 return tmp_addrs;
1698
1699 } /* get_bindx_addr() */
1700
1701 static int
1702 bindx_funccxx . . $ bindx_func(fb084d643e22d309).(char *argv0, int sk, struct sockaddrcxx . . $ sockaddr# *addrs, int count, int flag, int portnum)
1703 {
1704
1705 int error;
1706 int i;
1707 struct sockaddrcxx . . $ sockaddr# *sa_addr;
1708 void *aptr;
1709
1710
1711 if (0 == portnum) {
1712 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: A non-0 local port number is ", argv0);
1713 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "required for bindx to work!\n");
1714 return -1 ;
1715 }
1716
1717 /* Set the port in every address. */
1718 aptr = addrs;
1719 for (i = 0; i < count; i++) {
1720 sa_addr = (struct sockaddrcxx . . $ sockaddr# *)aptr;
1721
1722 switch(sa_addr->sa_familycxx . . $ sockaddr#sa_family.) {
1723 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
1724 ((struct sockaddr_incxx . . $ sockaddr_in# *)sa_addr)->sin_portcxx . . $ sockaddr_in#sin_port. =
1725 htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(portnum);
1726 aptr += sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
1727 break;
1728 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
1729 ((struct sockaddr_in6cxx . . $ sockaddr_in6# *)sa_addr)->sin6_portcxx . . $ sockaddr_in6#sin6_port. =
1730 htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(portnum);
1731 aptr += sizeof(struct sockaddr_in6cxx . . $ sockaddr_in6#);
1732 break;
1733 default:
1734 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Invalid address family\n");
1735 return -1;
1736 }
1737 }
1738
1739 error = sctp_bindxcxx . . $ sctp_bindx(8821f082d6785f9d).(sk, addrs, count, flag);
1740
1741 if (error != 0) {
1742 if (flag == SCTP_BINDX_ADD_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:1061:9`!) {
1743 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error adding addrs: %s.\n",
1744 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1745 return -1;
1746 } else {
1747 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error removing addrs: %s.\n",
1748 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1749 return -1;
1750 }
1751 }
1752
1753 return 0;
1754
1755 } /* bindx_func() */
1756
1757 static int
1758 connectx_funccxx . . $ connectx_func(73b07b87c343dc96).(char *argv0, int sk, struct sockaddrcxx . . $ sockaddr# *addrs, int count)
1759 {
1760
1761 int error;
1762 int i;
1763 struct sockaddrcxx . . $ sockaddr# *sa_addr;
1764 void *aptr;
1765
1766
1767 if (0 == remote_portcxx . . $ remote_port.) {
1768 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: A non-0 remote port number is ", argv0);
1769 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "required for connectx to work!\n");
1770 return -1 ;
1771 }
1772
1773 /* Set the port in every address. */
1774 aptr = addrs;
1775 for (i = 0; i < count; i++) {
1776 sa_addr = (struct sockaddrcxx . . $ sockaddr# *)aptr;
1777
1778 switch(sa_addr->sa_familycxx . . $ sockaddr#sa_family.) {
1779 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
1780 ((struct sockaddr_incxx . . $ sockaddr_in# *)sa_addr)->sin_portcxx . . $ sockaddr_in#sin_port. =
1781 htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1782 aptr += sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
1783 break;
1784 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
1785 ((struct sockaddr_in6cxx . . $ sockaddr_in6# *)sa_addr)->sin6_portcxx . . $ sockaddr_in6#sin6_port. =
1786 htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1787 aptr += sizeof(struct sockaddr_in6cxx . . $ sockaddr_in6#);
1788 break;
1789 default:
1790 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Invalid address family\n");
1791 return -1;
1792 }
1793 }
1794
1795 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(sk, addrs, count, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
1796
1797 if (error != 0) {
1798 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ECONNREFUSEDcxx . . $ `<external>/17922322188510340118/errno.h:95:9`!)
1799 return -2;
1800 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error connecting to addrs: %s.\n",
1801 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1802 return -1;
1803 }
1804
1805 return 0;
1806
1807 } /* connectx_func() */
1808
1809 static void
1810 primary_funccxx . . $ primary_func(7c7b1413e571f034).(char *argv0, int sk, char *cp, int set)
1811 {
1812 struct sctp_primcxx . . $ sctp_prim# prim;
1813 struct sockaddr_incxx . . $ sockaddr_in# *in_addr;
1814 struct sockaddr_in6cxx . . $ sockaddr_in6# *in6_addr;
1815 struct sockaddrcxx . . $ sockaddr# *saddr;
1816 socklen_tcxx . . $ socklen_t# prim_len;
1817 int ret;
1818 char *p = cp;
1819 char addr_buf[INET6_ADDRSTRLENcxx . . $ `<external>/9581057695539925927/in.h:245:9`!];
1820 const char *ap = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1821
1822 prim_len = sizeof(struct sctp_primcxx . . $ sctp_prim#);
1823 if (!set) {
1824 prim.ssp_assoc_idcxx . . $ sctp_prim#ssp_assoc_id. = associdcxx . . $ associd.;
1825 ret = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!, SCTP_PRIMARY_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:75:9`!,
1826 &prim, &prim_len);
1827 if (ret < 0)
1828 goto err;
1829
1830 saddr = (struct sockaddrcxx . . $ sockaddr# *)&prim.ssp_addrcxx . . $ sctp_prim#ssp_addr.;
1831 if (AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`! == saddr->sa_familycxx . . $ sockaddr#sa_family.) {
1832 in_addr = (struct sockaddr_incxx . . $ sockaddr_in# *)&prim.ssp_addrcxx . . $ sctp_prim#ssp_addr.;
1833 ap = inet_ntopcxx . . $ inet_ntop(6a923972b45bea03).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, &in_addr->sin_addrcxx . . $ sockaddr_in#sin_addr., addr_buf,
1834 INET6_ADDRSTRLENcxx . . $ `<external>/9581057695539925927/in.h:245:9`!);
1835 } else if (AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`! == saddr->sa_familycxx . . $ sockaddr#sa_family.) {
1836 in6_addr = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)&prim.ssp_addrcxx . . $ sctp_prim#ssp_addr.;
1837 ap = inet_ntopcxx . . $ inet_ntop(6a923972b45bea03).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, &in6_addr->sin6_addrcxx . . $ sockaddr_in6#sin6_addr., addr_buf,
1838 INET6_ADDRSTRLENcxx . . $ `<external>/9581057695539925927/in.h:245:9`!);
1839 }
1840 if (!ap)
1841 goto err;
1842 printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", ap);
1843 return;
1844 }
1845
1846 /* Set the buffer for address parsing. */
1847 while ('\n' != *p)
1848 p++;
1849 *p = '\0';
1850
1851 prim.ssp_assoc_idcxx . . $ sctp_prim#ssp_assoc_id. = associdcxx . . $ associd.;
1852 if (strchrcxx . . $ strchr(2050848944e00d54).(cp, '.')) {
1853 in_addr = (struct sockaddr_incxx . . $ sockaddr_in# *)&prim.ssp_addrcxx . . $ sctp_prim#ssp_addr.;
1854 in_addr->sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1855 in_addr->sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
1856 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812). (AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, cp, &in_addr->sin_addrcxx . . $ sockaddr_in#sin_addr.);
1857 if (ret <= 0)
1858 goto err;
1859 } else if (strchrcxx . . $ strchr(2050848944e00d54).(cp, ':')) {
1860 in6_addr = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)&prim.ssp_addrcxx . . $ sctp_prim#ssp_addr.;
1861 in6_addr->sin6_portcxx . . $ sockaddr_in6#sin6_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1862 in6_addr->sin6_familycxx . . $ sockaddr_in6#sin6_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
1863 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, cp, &in6_addr->sin6_addrcxx . . $ sockaddr_in6#sin6_addr.);
1864 if (ret <= 0)
1865 goto err;
1866 } else
1867 goto err;
1868
1869 ret = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!, SCTP_PRIMARY_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:75:9`!,
1870 &prim, sizeof(struct sctp_primcxx . . $ sctp_prim#));
1871 if (ret < 0)
1872 goto err;
1873
1874 return;
1875 err:
1876 if (!errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
1877 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1878 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error %s primary: %s.\n", argv0,
1879 (set)?"setting":"getting", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1880 }
1881
1882 static void
1883 peer_primary_funccxx . . $ peer_primary_func(7c7b1413e571f034).(char *argv0, int sk, char *cp, int set)
1884 {
1885 struct sctp_setpeerprimcxx . . $ sctp_setpeerprim# setpeerprim;
1886 struct sockaddr_incxx . . $ sockaddr_in# *in_addr;
1887 struct sockaddr_in6cxx . . $ sockaddr_in6# *in6_addr;
1888 int ret;
1889 char *p = cp;
1890
1891 if (!set) {
1892 goto err;
1893 }
1894
1895 /* Set the buffer for address parsing. */
1896 while ('\n' != *p)
1897 p++;
1898 *p = '\0';
1899
1900 setpeerprim.sspp_assoc_idcxx . . $ sctp_setpeerprim#sspp_assoc_id. = associdcxx . . $ associd.;
1901 if (strchrcxx . . $ strchr(2050848944e00d54).(cp, '.')) {
1902 in_addr = (struct sockaddr_incxx . . $ sockaddr_in# *)&setpeerprim.sspp_addrcxx . . $ sctp_setpeerprim#sspp_addr.;
1903 in_addr->sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(local_port);
1904 in_addr->sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
1905 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812). (AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, cp, &in_addr->sin_addrcxx . . $ sockaddr_in#sin_addr.);
1906 if (ret <= 0)
1907 goto err;
1908 } else if (strchrcxx . . $ strchr(2050848944e00d54).(cp, ':')) {
1909 in6_addr = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)&setpeerprim.sspp_addrcxx . . $ sctp_setpeerprim#sspp_addr.;
1910 in6_addr->sin6_portcxx . . $ sockaddr_in6#sin6_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(local_port);
1911 in6_addr->sin6_familycxx . . $ sockaddr_in6#sin6_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
1912 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, cp, &in6_addr->sin6_addrcxx . . $ sockaddr_in6#sin6_addr.);
1913 if (ret <= 0)
1914 goto err;
1915 } else
1916 goto err;
1917
1918 ret = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!, SCTP_SET_PEER_PRIMARY_ADDRcxx . . $ `<external>/17169092326581286071/sctp.h:74:9`!,
1919 &setpeerprim, sizeof(struct sctp_setpeerprimcxx . . $ sctp_setpeerprim#));
1920 if (ret < 0)
1921 goto err;
1922
1923 return;
1924 err:
1925 if (!errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
1926 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1927 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error %s peer_primary: %s.\n", argv0,
1928 (set)?"setting":"getting", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1929 }
1930
1931 static void
1932 spp_hb_demand_funccxx . . $ spp_hb_demand_func(7c7b1413e571f034).(char *argv0, int sk, char *cp, int set)
1933 {
1934 struct sctp_paddrparamscxx . . $ sctp_paddrparams# params;
1935 struct sockaddr_incxx . . $ sockaddr_in# *in_addr;
1936 struct sockaddr_in6cxx . . $ sockaddr_in6# *in6_addr;
1937 int ret;
1938 char *p = cp;
1939
1940 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&params, 0, sizeof(struct sctp_paddrparamscxx . . $ sctp_paddrparams#));
1941 params.spp_assoc_idcxx . . $ sctp_paddrparams#spp_assoc_id. = associdcxx . . $ associd.;
1942 params.spp_flagscxx . . $ sctp_paddrparams#spp_flags. = SPP_HB_DEMANDcxx . . $ SPP_HB_DEMAND.;
1943
1944 if (set) {
1945 /* Set the buffer for address parsing. */
1946 while ('\n' != *p)
1947 p++;
1948 *p = '\0';
1949
1950 if (strchrcxx . . $ strchr(2050848944e00d54).(cp, '.')) {
1951 in_addr = (struct sockaddr_incxx . . $ sockaddr_in# *)&params.spp_addresscxx . . $ sctp_paddrparams#spp_address.;
1952 in_addr->sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1953 in_addr->sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
1954 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, cp, &in_addr->sin_addrcxx . . $ sockaddr_in#sin_addr.);
1955 if (ret <= 0)
1956 goto err;
1957 } else if (strchrcxx . . $ strchr(2050848944e00d54).(cp, ':')) {
1958 in6_addr = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)&params.spp_addresscxx . . $ sctp_paddrparams#spp_address.;
1959 in6_addr->sin6_portcxx . . $ sockaddr_in6#sin6_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port);
1960 in6_addr->sin6_familycxx . . $ sockaddr_in6#sin6_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
1961 ret = inet_ptoncxx . . $ inet_pton(8d303d671d73812).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, cp, &in6_addr->sin6_addrcxx . . $ sockaddr_in6#sin6_addr.);
1962 if (ret <= 0)
1963 goto err;
1964 } else
1965 goto err;
1966 }
1967
1968 ret = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!, SCTP_PEER_ADDR_PARAMScxx . . $ `<external>/17169092326581286071/sctp.h:78:9`!,
1969 &params, sizeof(struct sctp_paddrparamscxx . . $ sctp_paddrparams#));
1970 if (ret < 0)
1971 goto err;
1972
1973 return;
1974 err:
1975 if (!errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
1976 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1977 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: error %s peer_addr_params: %s.\n", argv0,
1978 (set)?"setting":"getting", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1979 }
1980
1981 static int
1982 nodelay_funccxx . . $ nodelay_func(cd0c04d3624ba1ca).(char *argv0, int sk, int val, int set)
1983 {
1984 socklen_tcxx . . $ socklen_t# optlen;
1985 int error;
1986
1987 if (set) {
1988 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_NODELAYcxx . . $ `<external>/17169092326581286071/sctp.h:72:9`!,
1989 (char *)&val, sizeof(val));
1990 } else {
1991 optlen = sizeof(val);
1992 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_NODELAYcxx . . $ `<external>/17169092326581286071/sctp.h:72:9`!,
1993 (char *)&val, &optlen);
1994 }
1995 if (error != 0) {
1996 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Error setting/getting nodelay: %s.\n",
1997 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
1998 exitcxx . . $ exit(3ca292c338df9bb3).(1);
1999 }
2000
2001 if (!set) {
2002 printfcxx . . $ printf(581fddd72a8db8fc).("nodelay is %d.\n", val);
2003 }
2004
2005 return error;
2006 }
2007
2008 static int
2009 maxseg_funccxx . . $ maxseg_func(cd0c04d3624ba1ca).(char *argv0, int sk, int val, int set)
2010 {
2011 socklen_tcxx . . $ socklen_t# optlen;
2012 int error;
2013
2014 if (set) {
2015 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_MAXSEGcxx . . $ `<external>/17169092326581286071/sctp.h:82:9`!,
2016 (char *)&val, sizeof(val));
2017 } else {
2018 optlen = sizeof(val);
2019 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_MAXSEGcxx . . $ `<external>/17169092326581286071/sctp.h:82:9`!,
2020 (char *)&val, &optlen);
2021 }
2022 if (error != 0) {
2023 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Error setting/getting maxseg: %s.\n",
2024 argv0, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2025 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2026 }
2027
2028 if (!set) {
2029 printfcxx . . $ printf(581fddd72a8db8fc).("maxseg is %d.\n", val);
2030 }
2031
2032 return error;
2033 }
2034
2035 static int
2036 shutdown_funccxx . . $ shutdown_func(be750502182deecd).(char *argv0, int *skp, int shutdown_type)
2037 {
2038 struct msghdrcxx . . $ msghdr# outmessage;
2039 char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))];
2040 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
2041 int error=0, bytes_sent;
2042 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo;
2043 struct addrinfocxx . . $ addrinfo# hints, *rp;
2044 char *sd_type;
2045 int sk = *skp;
2046
2047 if (shutdown_type == SHUTDOWN_ABORTcxx . . $ SHUTDOWN_ABORT.)
2048 sd_type = "ABORT";
2049 else
2050 sd_type = "SHUTDOWN";
2051
2052 /* Verify that the association is present. */
2053 error = test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(sk, associdcxx . . $ associd.);
2054 if (error != 0) {
2055 printfcxx . . $ printf(581fddd72a8db8fc).("The association isn't present yet! Cannot %s!\n", sd_type);
2056 return -1;
2057 }
2058
2059 if (socket_typecxx . . $ socket_type. == SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!) {
2060 /* Set up the destination. */
2061 if (remote_hostcxx . . $ remote_host.) {
2062 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#));
2063 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
2064 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
2065 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
2066 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!;
2067 if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hints, &rp) != 0) {
2068 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n",
2069 argv0, remote_hostcxx . . $ remote_host.);
2070 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2071 }
2072 }
2073 memcpycxx . . $ memcpy(cc817cb175f282d).(&remote_addrcxx . . $ remote_addr., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
2074 remote_addrcxx . . $ remote_addr..v4cxx . . $ $anonymous_type_a9fe5f604ee7eb6c_1#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(remote_port); /* equal to v6.sin6_port */
2075 ra_lencxx . . $ ra_len. = rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.;
2076 }
2077
2078 /* Initialize the message struct we use to pass messages to
2079 * the remote socket.
2080 */
2081 outmessage.msg_namecxx . . $ msghdr#msg_name. = &remote_addrcxx . . $ remote_addr.;
2082 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = ra_lencxx . . $ ra_len.;
2083
2084 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2085 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 0;
2086 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
2087 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
2088 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
2089
2090 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
2091 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
2092 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
2093 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
2094 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.;
2095 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
2096 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
2097 if (shutdown_type == SHUTDOWN_ABORTcxx . . $ SHUTDOWN_ABORT.)
2098 sinfo->sinfo_flagscxx . . $ sctp_sndrcvinfo#sinfo_flags. |= SCTP_ABORTcxx . . $ SCTP_ABORT.;
2099 else
2100 sinfo->sinfo_flagscxx . . $ sctp_sndrcvinfo#sinfo_flags. |= SCTP_EOFcxx . . $ SCTP_EOF.;
2101
2102 sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id. = associdcxx . . $ associd.;
2103
2104 bytes_sent = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(sk, &outmessage, 0);
2105 if (bytes_sent != 0) {
2106 printfcxx . . $ printf(581fddd72a8db8fc).("Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2107 return -1;
2108 }
2109
2110 /* Receive the COMM_LOST or SHUTDOWN_COMP event. */
2111 test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(sk);
2112 } else {
2113 if (shutdown_type == SHUTDOWN_ABORTcxx . . $ SHUTDOWN_ABORT.) {
2114 struct lingercxx . . $ shutdown_func(be750502182deecd).linger# {
2115 int l_onoffcxx . . $ shutdown_func(be750502182deecd).linger#l_onoff.;
2116 int l_lingercxx . . $ shutdown_func(be750502182deecd).linger#l_linger.;
2117 } data = {1, 0};
2118 error = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(sk, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_LINGERcxx . . $ `<external>/9030916627833342711/socket.h:25:9`!,
2119 (char *)&data, sizeof(data));
2120 if (error != 0) {
2121 printfcxx . . $ printf(581fddd72a8db8fc).("setsockopt failed %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2122 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2123 }
2124 }
2125 error = closecxx . . $ close(7864480464b09eea).(sk);
2126 if (error != 0) {
2127 printfcxx . . $ printf(581fddd72a8db8fc).("close failed %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2128 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2129 }
2130 *skp = sk = build_endpointcxx . . $ build_endpoint(6abd07ddb1a912f0).(argv0, local_portcxx . . $ local_port.);
2131 }
2132
2133 /* Verify that the association is no longer present. */
2134 error = test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(sk, associdcxx . . $ associd.);
2135 if (error != 0) {
2136 printfcxx . . $ printf(581fddd72a8db8fc).("Successfully %s the original association\n", sd_type);
2137 associdcxx . . $ associd. = 0;
2138 new_connectioncxx . . $ new_connection. = 1;
2139 } else {
2140 printfcxx . . $ printf(581fddd72a8db8fc).("%s failed\n", sd_type);
2141 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2142 }
2143
2144 return 0;
2145 }
2146
2147 static int
2148 get_assocstats_funccxx . . $ get_assocstats_func(9b79fb6aee4c0440).(int sk, sctp_assoc_tcxx . . $ sctp_assoc_t# assoc_id)
2149 {
2150 int error = 0;
2151 struct sctp_assoc_statscxx . . $ sctp_assoc_stats# stats;
2152 socklen_tcxx . . $ socklen_t# len;
2153
2154 if (assoc_id == 0) {
2155 printfcxx . . $ printf(581fddd72a8db8fc).("No association present yet\n");
2156 return -1;
2157 }
2158
2159 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&stats, 0, sizeof(struct sctp_assoc_statscxx . . $ sctp_assoc_stats#));
2160 stats.sas_assoc_idcxx . . $ sctp_assoc_stats#sas_assoc_id. = assoc_id;
2161 len = sizeof(struct sctp_assoc_statscxx . . $ sctp_assoc_stats#);
2162 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_GET_ASSOC_STATScxx . . $ `<external>/17169092326581286071/sctp.h:122:9`!,
2163 (char *)&stats, &len);
2164 if (error != 0) {
2165 printfcxx . . $ printf(581fddd72a8db8fc).("get_assoc_stats() failed %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2166 return error;
2167 }
2168
2169 printfcxx . . $ printf(581fddd72a8db8fc).("Retransmitted Chunks: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_rtxchunkscxx . . $ sctp_assoc_stats#sas_rtxchunks.);
2170 printfcxx . . $ printf(581fddd72a8db8fc).("Gap Acknowledgements Received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_gapcntcxx . . $ sctp_assoc_stats#sas_gapcnt.);
2171 printfcxx . . $ printf(581fddd72a8db8fc).("TSN received > next expected: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_outofseqtsnscxx . . $ sctp_assoc_stats#sas_outofseqtsns.);
2172 printfcxx . . $ printf(581fddd72a8db8fc).("SACKs sent: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_osackscxx . . $ sctp_assoc_stats#sas_osacks.);
2173 printfcxx . . $ printf(581fddd72a8db8fc).("SACKs received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_isackscxx . . $ sctp_assoc_stats#sas_isacks.);
2174 printfcxx . . $ printf(581fddd72a8db8fc).("Control chunks sent: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_octrlchunkscxx . . $ sctp_assoc_stats#sas_octrlchunks.);
2175 printfcxx . . $ printf(581fddd72a8db8fc).("Control chunks received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_ictrlchunkscxx . . $ sctp_assoc_stats#sas_ictrlchunks.);
2176 printfcxx . . $ printf(581fddd72a8db8fc).("Ordered data chunks sent: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_oodchunkscxx . . $ sctp_assoc_stats#sas_oodchunks.);
2177 printfcxx . . $ printf(581fddd72a8db8fc).("Ordered data chunks received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_iodchunkscxx . . $ sctp_assoc_stats#sas_iodchunks.);
2178 printfcxx . . $ printf(581fddd72a8db8fc).("Unordered data chunks sent: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_ouodchunkscxx . . $ sctp_assoc_stats#sas_ouodchunks.);
2179 printfcxx . . $ printf(581fddd72a8db8fc).("Unordered data chunks received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_iuodchunkscxx . . $ sctp_assoc_stats#sas_iuodchunks.);
2180 printfcxx . . $ printf(581fddd72a8db8fc).("Dups received (ordered+unordered): %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_idupchunkscxx . . $ sctp_assoc_stats#sas_idupchunks.);
2181 printfcxx . . $ printf(581fddd72a8db8fc).("Packets sent: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_opacketscxx . . $ sctp_assoc_stats#sas_opackets.);
2182 printfcxx . . $ printf(581fddd72a8db8fc).("Packets received: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! "\n", (uint64_tcxx . . $ uint64_t#) stats.sas_ipacketscxx . . $ sctp_assoc_stats#sas_ipackets.);
2183 printfcxx . . $ printf(581fddd72a8db8fc).("Maximum Observed RTO this period: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! " - Transport: ", (uint64_tcxx . . $ uint64_t#) stats.sas_maxrtocxx . . $ sctp_assoc_stats#sas_maxrto.);
2184 print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).((struct sockaddrcxx . . $ sockaddr# *)&stats.sas_obs_rto_ipaddrcxx . . $ sctp_assoc_stats#sas_obs_rto_ipaddr.);
2185 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
2186
2187 return 0;
2188 }
2189
2190 static int
2191 test_sk_for_assoccxx . . $ test_sk_for_assoc(9b79fb6aee4c0440).(int sk, sctp_assoc_tcxx . . $ sctp_assoc_t# assoc_id)
2192 {
2193 int error = 0;
2194 struct sctp_statuscxx . . $ sctp_status# status;
2195 socklen_tcxx . . $ socklen_t# status_len;
2196
2197 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&status, 0, sizeof(status));
2198 if (assoc_id)
2199 status.sstat_assoc_idcxx . . $ sctp_status#sstat_assoc_id. = assoc_id;
2200 status_len = sizeof(struct sctp_statuscxx . . $ sctp_status#);
2201 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_STATUScxx . . $ `<external>/17169092326581286071/sctp.h:83:9`!,
2202 (char *)&status, &status_len);
2203 return error;
2204 }
2205
2206 /* Receive a notification and return the corresponding associd if the event is
2207 * SCTP_COMM_UP. Return 0 for any other event.
2208 */
2209 static sctp_assoc_tcxx . . $ sctp_assoc_t#
2210 test_recv_assoc_changecxx . . $ test_recv_assoc_change(7864480464b09eea).(int sk)
2211 {
2212 struct msghdrcxx . . $ msghdr# inmessage;
2213 struct ioveccxx . . $ iovec# iov;
2214 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(_sctp_cmsg_data_t))];
2215 int error;
2216
2217 /* Initialize inmessage with enough space for DATA... */
2218 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
2219 if ((iov.iov_basecxx . . $ iovec#iov_base. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
2220 printfcxx . . $ printf(581fddd72a8db8fc).("%s: Can't allocate memory.\n", __FUNCTION__);
2221 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2222 }
2223 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/apps/sctp_darn.h:4:9`!;
2224 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
2225 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
2226 /* or a control message. */
2227 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
2228 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
2229
2230 error = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
2231 if (error < 0) {
2232 printfcxx . . $ printf(581fddd72a8db8fc).("%s: recvmsg: %s\n", __FUNCTION__, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
2233 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2234 }
2235
2236 return test_verify_assoc_changecxx . . $ test_verify_assoc_change(615209a3b05c63a0).(&inmessage);
2237 }
2238
2239 /* Verify a notification and return the corresponding associd if the event is
2240 * SCTP_COMM_UP. Return 0 for any other event.
2241 */
2242 static sctp_assoc_tcxx . . $ sctp_assoc_t#
2243 test_verify_assoc_changecxx . . $ test_verify_assoc_change(615209a3b05c63a0).(struct msghdrcxx . . $ msghdr# *msg)
2244 {
2245 union sctp_notificationcxx . . $ sctp_notification# *sn;
2246
2247 if (!(msg->msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!)) {
2248 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Received data when notification is expected\n",
2249 __FUNCTION__);
2250 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2251 }
2252
2253 sn = (union sctp_notificationcxx . . $ sctp_notification# *)msg->msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base.;
2254 if (SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`! != sn->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type.) {
2255 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Received unexpected notification: %d",
2256 __FUNCTION__, sn->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type.);
2257 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2258 }
2259
2260 switch(sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_statecxx . . $ sctp_assoc_change#sac_state.)
2261 {
2262 case SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.:
2263 printfcxx . . $ printf(581fddd72a8db8fc).("Received SCTP_COMM_UP\n");
2264 break;
2265 case SCTP_COMM_LOSTcxx . . $ SCTP_COMM_LOST.:
2266 printfcxx . . $ printf(581fddd72a8db8fc).("Received SCTP_COMM_LOST\n");
2267 break;
2268 case SCTP_RESTARTcxx . . $ SCTP_RESTART.:
2269 printfcxx . . $ printf(581fddd72a8db8fc).("Received SCTP_RESTART\n");
2270 break;
2271 case SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.:
2272 printfcxx . . $ printf(581fddd72a8db8fc).("Received SCTP_SHUTDOWN_COMP\n");
2273 break;
2274 case SCTP_CANT_STR_ASSOCcxx . . $ SCTP_CANT_STR_ASSOC.:
2275 printfcxx . . $ printf(581fddd72a8db8fc).("Received SCTP_CANT_STR_ASSOC\n");
2276 break;
2277 }
2278
2279 if (SCTP_COMM_UPcxx . . $ SCTP_COMM_UP. == sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_statecxx . . $ sctp_assoc_change#sac_state.)
2280 return sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_assoc_idcxx . . $ sctp_assoc_change#sac_assoc_id.;
2281 else
2282 return 0;
2283 }
2284
2285 void print_addr_bufcxx . . $ print_addr_buf(d0320739773070f2).(void * laddrs, int n_laddrs)
2286 {
2287 void *addr_buf = laddrs;
2288 int i;
2289
2290 for (i = 0; i < n_laddrs; i++) {
2291 addr_buf += print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).((struct sockaddrcxx . . $ sockaddr# *)addr_buf);
2292 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
2293 }
2294 }
2295
2296 int print_sockaddrcxx . . $ print_sockaddr(10d3a1a0427e771a).(struct sockaddrcxx . . $ sockaddr# *sa_addr)
2297 {
2298 struct sockaddr_incxx . . $ sockaddr_in# *in_addr;
2299 struct sockaddr_in6cxx . . $ sockaddr_in6# *in6_addr;
2300
2301 if (AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`! == sa_addr->sa_familycxx . . $ sockaddr#sa_family.) {
2302 in_addr = (struct sockaddr_incxx . . $ sockaddr_in# *)sa_addr;
2303 printfcxx . . $ printf(581fddd72a8db8fc).("%d.%d.%d.%d:%d",
2304 NIPQUADcxx . . $ `src/apps/sctp_darn.c:82:9`!(in_addr->sin_addr),
2305 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(in_addr->sin_port));
2306 return sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
2307 } else {
2308 in6_addr = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)sa_addr;
2309 printfcxx . . $ printf(581fddd72a8db8fc).("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%d",
2310 NIP6cxx . . $ `src/apps/sctp_darn.c:89:9`!(in6_addr->sin6_addr),
2311 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(in6_addr->sin6_port));
2312 return sizeof(struct sockaddr_in6cxx . . $ sockaddr_in6#);
2313 }
2314 }