| 1 | /* SCTP kernel Implementation |
| 2 | * (C) Copyright IBM Corp. 2003 |
| 3 | * |
| 4 | * The SCTP implementation is free software; |
| 5 | * you can redistribute it and/or modify it under the terms of |
| 6 | * the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2, or (at your option) |
| 8 | * any later version. |
| 9 | * |
| 10 | * The SCTP implementation is distributed in the hope that it |
| 11 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 12 | * ************************ |
| 13 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 | * See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU CC; see the file COPYING. If not, write to |
| 18 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | * |
| 21 | * Please send any bug reports or fixes you make to the |
| 22 | * email address(es): |
| 23 | * lksctp developers <[email protected]> |
| 24 | * |
| 25 | * Or submit a bug report through the following website: |
| 26 | * https://github.com/sctp/lksctp-tools/ |
| 27 | * |
| 28 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 29 | * be incorporated into the next SCTP release. |
| 30 | * |
| 31 | * Written or modified by: |
| 32 | * Ryan Layer <[email protected]> |
| 33 | */ |
| 34 | |
| 35 | #include <stdio.h> |
| 36 | #include <unistd.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <string.h> |
| 39 | #include <fcntl.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/socket.h> |
| 42 | #include <sys/uio.h> |
| 43 | #include <netinet/in.h> |
| 44 | #include <errno.h> |
| 45 | #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/ |
| 46 | #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/ |
| 47 | #include <netdb.h> |
| 48 | #include <getopt.h> |
| 49 | |
| 50 | char *TCIDcxx . . $ TCID. = __FILE__; |
| 51 | int TST_TOTALcxx . . $ TST_TOTAL. = 1; |
| 52 | int TST_CNTcxx . . $ TST_CNT. = 0; |
| 53 | |
| 54 | #define MAXHOSTNAMEcxx . . $ `src/apps/sctp_xconnect.c:54:9`! 64 |
| 55 | |
| 56 | #define MAXCLIENTNUMcxx . . $ `src/apps/sctp_xconnect.c:56:9`! 10000 |
| 57 | |
| 58 | #define TRUEcxx . . $ `src/apps/sctp_xconnect.c:58:9`! 1 |
| 59 | |
| 60 | #define SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`! 1 |
| 61 | #define CLIENTcxx . . $ `src/apps/sctp_xconnect.c:61:9`! 0 |
| 62 | #define NOT_DEFINEDcxx . . $ `src/apps/sctp_xconnect.c:62:9`! -1 |
| 63 | |
| 64 | int modecxx . . $ mode. = NOT_DEFINEDcxx . . $ `src/apps/sctp_xconnect.c:62:9`!; |
| 65 | |
| 66 | int assoc_numcxx . . $ assoc_num.; |
| 67 | int activecxx . . $ active. = 0; |
| 68 | |
| 69 | char *local_hostcxx . . $ local_host.; |
| 70 | char *remote_hostcxx . . $ remote_host.; |
| 71 | char *local_portcxx . . $ local_port.; |
| 72 | char *remote_portcxx . . $ remote_port.; |
| 73 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# client_loopcxx . . $ client_loop., |
| 74 | server_loopcxx . . $ server_loop.; |
| 75 | struct hostentcxx . . $ hostent# *hstcxx . . $ hst.; |
| 76 | char big_buffercxx . . $ big_buffer.[REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!]; |
| 77 | |
| 78 | void usagecxx . . $ usage(fda57c8427c60377).(char *argv0); |
| 79 | void parse_argumentscxx . . $ parse_arguments(c759356ac01a31e7).(int argc, char*argv[]); |
| 80 | void data_receivedcxx . . $ data_received(37ebd854955fd3c).(struct msghdrcxx . . $ msghdr# *inmessage, int len, int stream, |
| 81 | int server_socket); |
| 82 | int event_receivedcxx . . $ event_received(9f2402dc7c3b6a35).(struct msghdrcxx . . $ msghdr# *inmessage, int assoc_num); |
| 83 | void process_ready_socketscxx . . $ process_ready_sockets(aeb1eadf46fe1db1).(int client_socket[], int assoc_num, fd_setcxx . . $ fd_set# *rfds); |
| 84 | void server_modecxx . . $ server_mode(49f6e7a06ebc5aa8).(void); |
| 85 | void client_modecxx . . $ client_mode(49f6e7a06ebc5aa8).(void); |
| 86 | |
| 87 | /* Print the syntax/usage */ |
| 88 | void usagecxx . . $ usage(fda57c8427c60377).(char *argv0) |
| 89 | { |
| 90 | printfcxx . . $ printf(581fddd72a8db8fc).("usage: %s -H localhost -P localport -l|c [-h remotehost]\n" |
| 91 | "\t\t[-p remoteport] [-a] [-n <cnt>]\n" |
| 92 | " -H\t\tspecify a local address.\n" |
| 93 | " -P\t\tspecify the local port number to be used\n" |
| 94 | " -l\t\trun in server mode.\n" |
| 95 | " -c\t\trun in client mode.\n" |
| 96 | " -h\t\tspecify the peer address.\n" |
| 97 | " -p\t\tspecify the port number for the peer address.\n" |
| 98 | " -a\t\tactively generate traffic with the server.\n" |
| 99 | " -n\t\tspecify the number of associations to create.\n", |
| 100 | argv0); |
| 101 | } |
| 102 | |
| 103 | /* Parse command line options */ |
| 104 | void parse_argumentscxx . . $ parse_arguments(c759356ac01a31e7).(int argc, char*argv[]) { |
| 105 | struct addrinfocxx . . $ addrinfo# hints, *rp; |
| 106 | int c; |
| 107 | |
| 108 | while ((c = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, ":H:P:ach:ln:p:")) >= 0) { |
| 109 | switch (c) { |
| 110 | case 'H': |
| 111 | local_hostcxx . . $ local_host. = optargcxx . . $ optarg.; |
| 112 | break; |
| 113 | case 'P': |
| 114 | local_portcxx . . $ local_port. = optargcxx . . $ optarg.; |
| 115 | break; |
| 116 | case 'c': |
| 117 | if (modecxx . . $ mode. == NOT_DEFINEDcxx . . $ `src/apps/sctp_xconnect.c:62:9`!) |
| 118 | modecxx . . $ mode. = CLIENTcxx . . $ `src/apps/sctp_xconnect.c:61:9`!; |
| 119 | else { |
| 120 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 121 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 122 | } |
| 123 | break; |
| 124 | case 'a': |
| 125 | activecxx . . $ active. = 1; |
| 126 | break; |
| 127 | case 'h': |
| 128 | remote_hostcxx . . $ remote_host. = optargcxx . . $ optarg.; |
| 129 | break; |
| 130 | case 'l': |
| 131 | if (modecxx . . $ mode. == NOT_DEFINEDcxx . . $ `src/apps/sctp_xconnect.c:62:9`!) |
| 132 | modecxx . . $ mode. = SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`!; |
| 133 | else { |
| 134 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 135 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 136 | } |
| 137 | break; |
| 138 | case 'n': |
| 139 | assoc_numcxx . . $ assoc_num. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 140 | break; |
| 141 | case 'p': |
| 142 | remote_portcxx . . $ remote_port. = optargcxx . . $ optarg.; |
| 143 | break; |
| 144 | default: |
| 145 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 146 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 147 | } |
| 148 | } /* while() */ |
| 149 | |
| 150 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#)); |
| 151 | hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 152 | hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 153 | if (modecxx . . $ mode. == CLIENTcxx . . $ `src/apps/sctp_xconnect.c:61:9`!) { |
| 154 | if (assoc_numcxx . . $ assoc_num.) { |
| 155 | if (assoc_numcxx . . $ assoc_num. > MAXCLIENTNUMcxx . . $ `src/apps/sctp_xconnect.c:56:9`!) { |
| 156 | printfcxx . . $ printf(581fddd72a8db8fc).("The number of associations indicated " |
| 157 | "is greater than the"); |
| 158 | printfcxx . . $ printf(581fddd72a8db8fc).("max number of associations " |
| 159 | "allowed(%d).", MAXCLIENTNUMcxx . . $ `src/apps/sctp_xconnect.c:56:9`!); |
| 160 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 161 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 162 | } |
| 163 | } else |
| 164 | assoc_numcxx . . $ assoc_num. = 1; |
| 165 | |
| 166 | if (remote_hostcxx . . $ remote_host. && remote_portcxx . . $ remote_port.) { |
| 167 | if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., remote_portcxx . . $ remote_port., &hints, &rp) != 0) { |
| 168 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: bad remote hostname or port: %s, %s\n", |
| 169 | argv[0], remote_hostcxx . . $ remote_host., remote_portcxx . . $ remote_port.); |
| 170 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 171 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 172 | } |
| 173 | memcpycxx . . $ memcpy(cc817cb175f282d).(&server_loopcxx . . $ server_loop., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.); |
| 174 | } else { |
| 175 | printfcxx . . $ printf(581fddd72a8db8fc).("Remote host and remote port must be defined " |
| 176 | "in client mode\n"); |
| 177 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 178 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 179 | } |
| 180 | |
| 181 | if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_hostcxx . . $ local_host., local_portcxx . . $ local_port., &hints, &rp) != 0) { |
| 182 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: bad local hostname or port: %s, %s\n", |
| 183 | argv[0], local_hostcxx . . $ local_host., local_portcxx . . $ local_port.); |
| 184 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 185 | } |
| 186 | memcpycxx . . $ memcpy(cc817cb175f282d).(&client_loopcxx . . $ client_loop., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.); |
| 187 | } else if (modecxx . . $ mode. == SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`!) { |
| 188 | if (activecxx . . $ active.) { |
| 189 | printfcxx . . $ printf(581fddd72a8db8fc).("This option if for client use only"); |
| 190 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 191 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 192 | } |
| 193 | |
| 194 | if (remote_hostcxx . . $ remote_host. || remote_portcxx . . $ remote_port.) { |
| 195 | printfcxx . . $ printf(581fddd72a8db8fc).("Remote values not needed in server mode.\n"); |
| 196 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 197 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 198 | } |
| 199 | |
| 200 | if (!local_portcxx . . $ local_port.) { |
| 201 | printfcxx . . $ printf(581fddd72a8db8fc).("Specify a local port in server mode.\n"); |
| 202 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 203 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 204 | } |
| 205 | if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_hostcxx . . $ local_host., local_portcxx . . $ local_port., &hints, &rp) != 0) { |
| 206 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: bad local hostname or port: %s, %s\n", |
| 207 | argv[0], local_hostcxx . . $ local_host., local_portcxx . . $ local_port.); |
| 208 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 209 | } |
| 210 | memcpycxx . . $ memcpy(cc817cb175f282d).(&server_loopcxx . . $ server_loop., rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.); |
| 211 | } else { |
| 212 | printfcxx . . $ printf(581fddd72a8db8fc).("Must assisgn a client or server mode.\n"); |
| 213 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 214 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 215 | } |
| 216 | } /* parse_arguments() */ |
| 217 | |
| 218 | /* Handle data received */ |
| 219 | void data_receivedcxx . . $ data_received(37ebd854955fd3c).(struct msghdrcxx . . $ msghdr# *inmessage, int len, int stream, int socket) { |
| 220 | |
| 221 | int ppid, error; |
| 222 | char *ping = "PING"; |
| 223 | |
| 224 | if (modecxx . . $ mode. == SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`!) { |
| 225 | ppid = randcxx . . $ rand(b126dc7c1de90089).(); |
| 226 | |
| 227 | error = sctp_sendmsgcxx . . $ sctp_sendmsg(9dfe5aa294f24c42).(socket, |
| 228 | inmessage->msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base., |
| 229 | len, |
| 230 | (struct sockaddrcxx . . $ sockaddr# *)inmessage->msg_namecxx . . $ msghdr#msg_name., |
| 231 | inmessage->msg_namelencxx . . $ msghdr#msg_namelen., |
| 232 | ppid, |
| 233 | 0, |
| 234 | stream, |
| 235 | 0, 0); |
| 236 | |
| 237 | if (error < 0) { |
| 238 | printfcxx . . $ printf(581fddd72a8db8fc).("Send Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 239 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 240 | } |
| 241 | } else { |
| 242 | ppid = randcxx . . $ rand(b126dc7c1de90089).(); |
| 243 | |
| 244 | printfcxx . . $ printf(581fddd72a8db8fc).("Data Received by socket #: %d.\n", socket); |
| 245 | printfcxx . . $ printf(581fddd72a8db8fc).("\tMessage = %s\n", |
| 246 | (char *)inmessage->msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base.); |
| 247 | |
| 248 | if (activecxx . . $ active.) { |
| 249 | error = sctp_sendmsgcxx . . $ sctp_sendmsg(9dfe5aa294f24c42).(socket, ping, strlencxx . . $ strlen(751346f8406fd082).(ping) + 1, |
| 250 | (struct sockaddrcxx . . $ sockaddr# *)&server_loopcxx . . $ server_loop., |
| 251 | sizeof(server_loopcxx . . $ server_loop.), ppid, 0, |
| 252 | stream, 0, 0); |
| 253 | if (error < 0) { |
| 254 | printfcxx . . $ printf(581fddd72a8db8fc).("Send Failure: %s.\n", |
| 255 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 256 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /* This will print what type of SCTP_ASSOC_CHANGE state that was received */ |
| 263 | void print_sctp_sac_statecxx . . $ print_sctp_sac_state(1d54d2dd7755e86b).(struct msghdrcxx . . $ msghdr# *msg) { |
| 264 | |
| 265 | char *data; |
| 266 | union sctp_notificationcxx . . $ sctp_notification# *sn; |
| 267 | |
| 268 | if (msg->msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!) { |
| 269 | data = (char *)msg->msg_iovcxx . . $ msghdr#msg_iov.[0].iov_basecxx . . $ iovec#iov_base.; |
| 270 | |
| 271 | sn = (union sctp_notificationcxx . . $ sctp_notification# *)data; |
| 272 | |
| 273 | switch (sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_statecxx . . $ sctp_assoc_change#sac_state.) { |
| 274 | case SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.: |
| 275 | printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_COMM_UP\n"); |
| 276 | break; |
| 277 | case SCTP_COMM_LOSTcxx . . $ SCTP_COMM_LOST.: |
| 278 | printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_COMM_LOST\n"); |
| 279 | break; |
| 280 | case SCTP_RESTARTcxx . . $ SCTP_RESTART.: |
| 281 | printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_RESTART"); |
| 282 | break; |
| 283 | case SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.: |
| 284 | printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_SHUTDOWN_COMP\n"); |
| 285 | break; |
| 286 | case SCTP_CANT_STR_ASSOCcxx . . $ SCTP_CANT_STR_ASSOC.: |
| 287 | printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_CANT_STR_ASSOC\n"); |
| 288 | break; |
| 289 | default: |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | } /* void print_sctp_sac_state() */ |
| 294 | |
| 295 | /* Tests what type of MSG_NOTIFICATION has been received. |
| 296 | * For now this fucntion only works with SCTP_ASSOC_CHANGE |
| 297 | * types, but can be easily expanded. |
| 298 | * |
| 299 | * Will return... |
| 300 | * -1 if the msg_flags is not MSG_NOTIFICATION |
| 301 | * 0 if the MSG_NOTIFICATION type differs from the type |
| 302 | * passed into the additional variable |
| 303 | * 1 if the MSG_NOTIFICATION type matches the type |
| 304 | * passed into the additional variable |
| 305 | */ |
| 306 | int test_check_notification_typecxx . . $ test_check_notification_type(a42f927663784b66).(struct msghdrcxx . . $ msghdr# *msg, |
| 307 | uint16_tcxx . . $ uint16_t# sn_type, |
| 308 | uint32_tcxx . . $ uint32_t# additional) { |
| 309 | |
| 310 | char *data; |
| 311 | union sctp_notificationcxx . . $ sctp_notification# *sn; |
| 312 | |
| 313 | if (!(msg->msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!)) { |
| 314 | return -1; |
| 315 | } else { |
| 316 | |
| 317 | /* Fixup for testframe. */ |
| 318 | data = (char *)msg->msg_iovcxx . . $ msghdr#msg_iov.[0].iov_basecxx . . $ iovec#iov_base.; |
| 319 | |
| 320 | sn = (union sctp_notificationcxx . . $ sctp_notification# *)data; |
| 321 | |
| 322 | if (sn->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type. != sn_type) |
| 323 | return 0; |
| 324 | else if (sn->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type. == SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!) |
| 325 | if (sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_statecxx . . $ sctp_assoc_change#sac_state. == additional) |
| 326 | return 1; |
| 327 | return 0; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /* Determine the type of event and make correct adjustments to the |
| 332 | * association count |
| 333 | */ |
| 334 | int event_receivedcxx . . $ event_received(9f2402dc7c3b6a35).(struct msghdrcxx . . $ msghdr# *inmessage, int assoc_num) { |
| 335 | |
| 336 | int error; |
| 337 | |
| 338 | printfcxx . . $ printf(581fddd72a8db8fc).("Event Received\n"); |
| 339 | |
| 340 | print_sctp_sac_statecxx . . $ print_sctp_sac_state(1d54d2dd7755e86b).(inmessage); |
| 341 | |
| 342 | if (modecxx . . $ mode. == SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`!) { |
| 343 | /* Test type of Event */ |
| 344 | error = test_check_notification_typecxx . . $ test_check_notification_type(a42f927663784b66).(inmessage, |
| 345 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, |
| 346 | SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.); |
| 347 | if (error > 0) { |
| 348 | assoc_num++; |
| 349 | printfcxx . . $ printf(581fddd72a8db8fc).("Assosiation Established: count = %d.\n", |
| 350 | assoc_num); |
| 351 | } else { |
| 352 | error = test_check_notification_typecxx . . $ test_check_notification_type(a42f927663784b66).(inmessage, |
| 353 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, |
| 354 | SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.); |
| 355 | |
| 356 | if (error > 0) { |
| 357 | assoc_num--; |
| 358 | printfcxx . . $ printf(581fddd72a8db8fc).("Assosiation Shutdown: count = %d.\n", |
| 359 | assoc_num); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | return assoc_num; |
| 364 | } |
| 365 | |
| 366 | void server_modecxx . . $ server_mode(49f6e7a06ebc5aa8).() { |
| 367 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# msgname; |
| 368 | int server_socket, |
| 369 | error, |
| 370 | stream; |
| 371 | int assoc_num =0; |
| 372 | struct msghdrcxx . . $ msghdr# inmessage; |
| 373 | struct ioveccxx . . $ iovec# iov; |
| 374 | char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))]; |
| 375 | |
| 376 | |
| 377 | printfcxx . . $ printf(581fddd72a8db8fc).("Running in Server Mode...\n"); |
| 378 | |
| 379 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage)); |
| 380 | iov.iov_basecxx . . $ iovec#iov_base. = big_buffercxx . . $ big_buffer.; |
| 381 | iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!; |
| 382 | inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov; |
| 383 | inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. =1; |
| 384 | inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg; |
| 385 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 386 | inmessage.msg_namecxx . . $ msghdr#msg_name. = &msgname; |
| 387 | inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof (msgname); |
| 388 | |
| 389 | stream = 1; |
| 390 | |
| 391 | server_socket = socketcxx . . $ socket(2326284602b0bb2d).(PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!); |
| 392 | if (server_socket < 0) { |
| 393 | printfcxx . . $ printf(581fddd72a8db8fc).("Socket Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 394 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 395 | } |
| 396 | |
| 397 | error = bindcxx . . $ bind(1ce9971e209c3c95).(server_socket, &server_loopcxx . . $ server_loop..sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(server_loopcxx . . $ server_loop.)); |
| 398 | if (error != 0 ) { |
| 399 | printfcxx . . $ printf(581fddd72a8db8fc).("Bind Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 400 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 401 | } |
| 402 | |
| 403 | error = listencxx . . $ listen(9b79fb6aee4c0440).(server_socket, 1); |
| 404 | if (error != 0) { |
| 405 | printfcxx . . $ printf(581fddd72a8db8fc).("Listen Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 406 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 407 | } |
| 408 | while (TRUEcxx . . $ `src/apps/sctp_xconnect.c:58:9`!) { |
| 409 | error = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(server_socket, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 410 | if (error < 0) { |
| 411 | printfcxx . . $ printf(581fddd72a8db8fc).("Receive Failure: %s\n", |
| 412 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 413 | } else { |
| 414 | if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!) |
| 415 | assoc_num = event_receivedcxx . . $ event_received(9f2402dc7c3b6a35).(&inmessage, assoc_num); |
| 416 | else |
| 417 | data_receivedcxx . . $ data_received(37ebd854955fd3c).(&inmessage, error, stream, server_socket); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | void client_modecxx . . $ client_mode(49f6e7a06ebc5aa8).() { |
| 423 | |
| 424 | int i, error, stream, max_socket = 0; |
| 425 | uint32_tcxx . . $ uint32_t# ppid = 0; |
| 426 | int client_socket[assoc_numcxx . . $ assoc_num.]; |
| 427 | char *message = "Awake"; |
| 428 | fd_setcxx . . $ fd_set# rfds; |
| 429 | struct timevalcxx . . $ timeval# tv; |
| 430 | |
| 431 | stream = 1; |
| 432 | |
| 433 | printfcxx . . $ printf(581fddd72a8db8fc).("Running in Client Mode...\n"); |
| 434 | |
| 435 | /* Create the sockets */ |
| 436 | for (i = 0; i < assoc_numcxx . . $ assoc_num.; i++) { |
| 437 | client_socket[i] = socketcxx . . $ socket(2326284602b0bb2d).(PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, |
| 438 | IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!); |
| 439 | if (client_socket[i] < 0 ){ |
| 440 | printfcxx . . $ printf(581fddd72a8db8fc).("Socket Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 441 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 442 | } |
| 443 | |
| 444 | if (local_portcxx . . $ local_port.) { |
| 445 | error = bindcxx . . $ bind(1ce9971e209c3c95).(client_socket[i], &client_loopcxx . . $ client_loop..sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., |
| 446 | sizeof(client_loopcxx . . $ client_loop.)); |
| 447 | if (error < 0) { |
| 448 | printfcxx . . $ printf(581fddd72a8db8fc).("Bind Failure: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 449 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | printfcxx . . $ printf(581fddd72a8db8fc).("Create Socket #: %d\n", client_socket[i]); |
| 454 | |
| 455 | /* Connect to server and send initial message */ |
| 456 | error = connectcxx . . $ connect(1ce9971e209c3c95).(client_socket[i], &server_loopcxx . . $ server_loop..sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., |
| 457 | sizeof(server_loopcxx . . $ server_loop.)); |
| 458 | if (error < 0){ |
| 459 | printfcxx . . $ printf(581fddd72a8db8fc).("Connect Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 460 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 461 | } |
| 462 | |
| 463 | max_socket = client_socket[i]; |
| 464 | |
| 465 | ppid++; |
| 466 | |
| 467 | /* Send initial message */ |
| 468 | error = sctp_sendmsgcxx . . $ sctp_sendmsg(9dfe5aa294f24c42).(client_socket[i], |
| 469 | message, |
| 470 | strlencxx . . $ strlen(751346f8406fd082).(message) + 1, |
| 471 | (struct sockaddrcxx . . $ sockaddr# *)&server_loopcxx . . $ server_loop., |
| 472 | sizeof(server_loopcxx . . $ server_loop.), |
| 473 | ppid, |
| 474 | 0, |
| 475 | stream, |
| 476 | 0, 0); |
| 477 | if (error < 0 ) { |
| 478 | printfcxx . . $ printf(581fddd72a8db8fc).("Send Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 479 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | while (TRUEcxx . . $ `src/apps/sctp_xconnect.c:58:9`!){ |
| 484 | |
| 485 | /* Clear the set for select() */ |
| 486 | FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&rfds); |
| 487 | |
| 488 | /* Set time out values for select() */ |
| 489 | tv.tv_seccxx . . $ timeval#tv_sec. = 5; |
| 490 | tv.tv_useccxx . . $ timeval#tv_usec. = 0; |
| 491 | |
| 492 | /* Add the sockets select() will examine */ |
| 493 | for (i = 0; i < assoc_numcxx . . $ assoc_num.; i++) { |
| 494 | FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(client_socket[i], &rfds); |
| 495 | } |
| 496 | |
| 497 | /* Wait until there is data to be read from one of the |
| 498 | * sockets, or until the timer expires |
| 499 | */ |
| 500 | error = selectcxx . . $ select(6d24c7514c8a5b88).(max_socket + 1, &rfds, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &tv); |
| 501 | |
| 502 | if (error < 0) { |
| 503 | printfcxx . . $ printf(581fddd72a8db8fc).("Select Failure: %s.\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 504 | DUMP_COREcxx . . $ `src/testlib/sctputil.h:100:9`!; |
| 505 | } else if (error) { |
| 506 | /* Loop through the array of sockets to find the ones |
| 507 | *that have information to be read |
| 508 | */ |
| 509 | process_ready_socketscxx . . $ process_ready_sockets(aeb1eadf46fe1db1).(client_socket, assoc_numcxx . . $ assoc_num., &rfds); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | void process_ready_socketscxx . . $ process_ready_sockets(aeb1eadf46fe1db1).(int client_socket[], int assoc_num, fd_setcxx . . $ fd_set# *rfds) { |
| 515 | |
| 516 | int i, stream, error; |
| 517 | struct msghdrcxx . . $ msghdr# inmessage; |
| 518 | struct ioveccxx . . $ iovec# iov; |
| 519 | char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof (sctp_cmsg_data_t))]; |
| 520 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# msgname; |
| 521 | |
| 522 | /* Setup inmessage to be able to receive in incomming message */ |
| 523 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof (inmessage)); |
| 524 | iov.iov_basecxx . . $ iovec#iov_base. = big_buffercxx . . $ big_buffer.; |
| 525 | iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!; |
| 526 | inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov; |
| 527 | inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. =1; |
| 528 | inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg; |
| 529 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof (incmsg); |
| 530 | inmessage.msg_namecxx . . $ msghdr#msg_name. = &msgname; |
| 531 | inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof (msgname); |
| 532 | |
| 533 | stream = 1; |
| 534 | |
| 535 | for( i = 0; i < assoc_num; i++) { |
| 536 | if (FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(client_socket[i], rfds)) { |
| 537 | error = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(client_socket[i], &inmessage, |
| 538 | MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 539 | if (error < 0) |
| 540 | printfcxx . . $ printf(581fddd72a8db8fc).("Receive Failure: %s\n", |
| 541 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 542 | else { |
| 543 | /* Test to find the type of message that was read(event/data) */ |
| 544 | if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & |
| 545 | MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!) |
| 546 | event_receivedcxx . . $ event_received(9f2402dc7c3b6a35).(&inmessage, |
| 547 | 0); |
| 548 | |
| 549 | else |
| 550 | data_receivedcxx . . $ data_received(37ebd854955fd3c).(&inmessage, error, |
| 551 | stream, |
| 552 | client_socket[i]); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) { |
| 559 | |
| 560 | parse_argumentscxx . . $ parse_arguments(c759356ac01a31e7).(argc, argv); |
| 561 | |
| 562 | if (modecxx . . $ mode. == SERVERcxx . . $ `src/apps/sctp_xconnect.c:60:9`!) { |
| 563 | server_modecxx . . $ server_mode(49f6e7a06ebc5aa8).(); |
| 564 | } else if (modecxx . . $ mode. == CLIENTcxx . . $ `src/apps/sctp_xconnect.c:61:9`!){ |
| 565 | client_modecxx . . $ client_mode(49f6e7a06ebc5aa8).(); |
| 566 | } |
| 567 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 568 | } |
| 569 |