| 1 | /* myftp - simple file transfer over sctp testing tool. |
| 2 | * Copyright (c) 2002 Intel Corp. |
| 3 | * |
| 4 | * This file is part of the LKSCTP kernel Implementation. This |
| 5 | * is a submission by Xingang Guo from the Intel Corporation while |
| 6 | * participating on the LKSCTP project. |
| 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 | * Written or modified by: |
| 33 | * Xingang Guo <[email protected]> |
| 34 | * Jon Grimm <[email protected]> |
| 35 | * |
| 36 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 37 | * be incorporated into the next SCTP release. |
| 38 | */ |
| 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | #define _GNU_SOURCEcxx . . $ `src/apps/myftp.c:42:9`! |
| 43 | #include <getopt.h> |
| 44 | #include <netdb.h> |
| 45 | #include <fcntl.h> |
| 46 | #include <unistd.h> |
| 47 | |
| 48 | #include <ctype.h> |
| 49 | #include <sys/types.h> |
| 50 | #include <sys/stat.h> |
| 51 | #include <sys/socket.h> |
| 52 | #include <sys/uio.h> |
| 53 | #include <netinet/in.h> /* for sockaddr_in */ |
| 54 | #include <errno.h> |
| 55 | #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/ |
| 56 | |
| 57 | #define BUFSIZEcxx . . $ `src/apps/myftp.c:57:9`! 1024 |
| 58 | static char buffercxx . . $ buffer.[BUFSIZEcxx . . $ `src/apps/myftp.c:57:9`!]; |
| 59 | #define DUMP_COREcxx . . $ `src/apps/myftp.c:59:9`! { char *diediedie = 0; *diediedie = 0; } |
| 60 | |
| 61 | typedef enumcxx . . $ $anonymous_type_4b7acaa756ed512_0# { COMMAND_NONEcxx . . $ COMMAND_NONE., COMMAND_RECVcxx . . $ COMMAND_RECV., COMMAND_SENDcxx . . $ COMMAND_SEND. } command_tcxx . . $ command_t#; |
| 62 | |
| 63 | /* These are the global options. */ |
| 64 | #define MAX_NUM_HOSTcxx . . $ `src/apps/myftp.c:64:9`! 5 |
| 65 | static char *local_hostcxx . . $ local_host.[MAX_NUM_HOSTcxx . . $ `src/apps/myftp.c:64:9`!]; |
| 66 | static int num_local_hostcxx . . $ num_local_host. = 0; |
| 67 | static char *local_portcxx . . $ local_port. = "4444"; |
| 68 | |
| 69 | static int buffer_sizecxx . . $ buffer_size. = BUFSIZEcxx . . $ `src/apps/myftp.c:57:9`!; |
| 70 | static char *remote_hostcxx . . $ remote_host. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 71 | static char *remote_portcxx . . $ remote_port. = "4444"; |
| 72 | static command_tcxx . . $ command_t# commandcxx . . $ command. = COMMAND_NONEcxx . . $ COMMAND_NONE.; |
| 73 | static char *filenamecxx . . $ filename. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 74 | static int interactivecxx . . $ interactive. = 0; |
| 75 | static unsigned long delaycxx . . $ delay. = 0; |
| 76 | static int verbosecxx . . $ verbose. = 0; |
| 77 | |
| 78 | static void |
| 79 | usagecxx . . $ usage(fda57c8427c60377).(char *argv0) |
| 80 | { |
| 81 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Usage: %s [options]\n",argv0); |
| 82 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Options:\n"); |
| 83 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--local, -H <hostname> Specify local interface\n"); |
| 84 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--local-port, -P <port> Specify local port (default 4444)\n"); |
| 85 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--remote, -h <hostname> Specify interface on remote host\n"); |
| 86 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--remote-port, -p <port> Specify remote port (default 4444)\n"); |
| 87 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--listen, -l Work in receiving mode\n"); |
| 88 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--send, -s Work in sending mode\n"); |
| 89 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--file, -f <filename> File to read or write,\n"); |
| 90 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--buffer, -b <size> Buffer size. (default 1024 bytes)\n"); |
| 91 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t by default use standard input/output.\n"); |
| 92 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--quick, -q Send packets continueously,\n"); |
| 93 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t do not wait for <ENTER> key. Default wait.\n"); |
| 94 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--delay, -d <usec> Delay between consecutive sends (see --quick)\n"); |
| 95 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t--verbose, -v In verbose mode, display the progress.\n"); |
| 96 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n\t--help, Print this message.\n\n"); |
| 97 | } /* usage() */ |
| 98 | |
| 99 | static int parse_argumentscxx . . $ parse_arguments(afcd3168fc1188a4).(int argc, char *argv[]) |
| 100 | { |
| 101 | int option_index = 0; |
| 102 | int c; |
| 103 | static struct optioncxx . . $ option# long_options[] = { |
| 104 | {"local", 1, 0, 1}, |
| 105 | {"local-port", 1, 0, 2}, |
| 106 | {"remote", 1, 0, 3}, |
| 107 | {"remote-port", 1, 0, 4}, |
| 108 | {"file", 1, 0, 5}, |
| 109 | {"delay", 1, 0, 6}, |
| 110 | {"buffer", 1, 0, 7}, |
| 111 | {"listen", 0, 0, 10}, |
| 112 | {"send", 0, 0, 11}, |
| 113 | {"quick", 0, 0, 12}, |
| 114 | {"verbose", 0, 0, 13}, |
| 115 | {"help", 0, 0, 99}, |
| 116 | {0, 0, 0, 0} |
| 117 | }; |
| 118 | |
| 119 | /* Parse the arguments. */ |
| 120 | while (1) { |
| 121 | c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "H:P:h:p:f:d:b:qlsv",long_options,&option_index); |
| 122 | if (c == -1) break; |
| 123 | |
| 124 | switch (c) { |
| 125 | case 0: |
| 126 | printfcxx . . $ printf(581fddd72a8db8fc). ("option %s", long_options[option_index].namecxx . . $ option#name.); |
| 127 | if (optargcxx . . $ optarg.) printfcxx . . $ printf(581fddd72a8db8fc). (" with arg %s", optargcxx . . $ optarg.); |
| 128 | printfcxx . . $ printf(581fddd72a8db8fc). ("\n"); |
| 129 | break; |
| 130 | case 1: /* local host */ |
| 131 | case 'H': |
| 132 | local_hostcxx . . $ local_host.[num_local_hostcxx . . $ num_local_host.++] = optargcxx . . $ optarg.; |
| 133 | break; |
| 134 | case 2: /* local port */ |
| 135 | case 'P': |
| 136 | local_portcxx . . $ local_port. = optargcxx . . $ optarg.; |
| 137 | break; |
| 138 | case 3: /* remote host */ |
| 139 | case 'h': |
| 140 | remote_hostcxx . . $ remote_host. = optargcxx . . $ optarg.; |
| 141 | break; |
| 142 | case 4: /* remote port */ |
| 143 | case 'p': |
| 144 | remote_portcxx . . $ remote_port. = optargcxx . . $ optarg.; |
| 145 | break; |
| 146 | case 5: |
| 147 | case 'f': |
| 148 | filenamecxx . . $ filename. = optargcxx . . $ optarg.; |
| 149 | break; |
| 150 | |
| 151 | case 6: |
| 152 | case 'd': |
| 153 | delaycxx . . $ delay. = strtoulcxx . . $ strtoul(31746e8d6ec49860).(optargcxx . . $ optarg.,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,10); |
| 154 | printfcxx . . $ printf(581fddd72a8db8fc).("delay is %ld usec\n",delaycxx . . $ delay.); |
| 155 | break; |
| 156 | |
| 157 | case 7: |
| 158 | case 'b': |
| 159 | buffer_sizecxx . . $ buffer_size. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 160 | if ( buffer_sizecxx . . $ buffer_size. > BUFSIZEcxx . . $ `src/apps/myftp.c:57:9`! ) { |
| 161 | buffer_sizecxx . . $ buffer_size. = BUFSIZEcxx . . $ `src/apps/myftp.c:57:9`!; |
| 162 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"Warning, buffer size too large, set to %d\n",buffer_sizecxx . . $ buffer_size.); |
| 163 | } |
| 164 | break; |
| 165 | |
| 166 | case 12: |
| 167 | case 'q': interactivecxx . . $ interactive. = 0; break; |
| 168 | |
| 169 | case 13: |
| 170 | case 'v': verbosecxx . . $ verbose. = 1; break; |
| 171 | /* COMMANDS */ |
| 172 | case 10: /* listen */ |
| 173 | case 'l': |
| 174 | if (commandcxx . . $ command.) { |
| 175 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: pick ONE of listen or send\n", argv[0]); |
| 176 | return 1; |
| 177 | } |
| 178 | else commandcxx . . $ command. = COMMAND_RECVcxx . . $ COMMAND_RECV.; |
| 179 | break; |
| 180 | |
| 181 | case 11: /* send */ |
| 182 | case 's': |
| 183 | if (commandcxx . . $ command.) { |
| 184 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: pick ONE of listen or send\n", argv[0]); |
| 185 | return 2; |
| 186 | } else commandcxx . . $ command. = COMMAND_SENDcxx . . $ COMMAND_SEND.; |
| 187 | break; |
| 188 | |
| 189 | case '?': |
| 190 | case 99: |
| 191 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 192 | return 3; |
| 193 | break; |
| 194 | |
| 195 | default: |
| 196 | printfcxx . . $ printf(581fddd72a8db8fc). ("%s: unrecognized option 0%c\n", argv[0], c); |
| 197 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 198 | return 4; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (optindcxx . . $ optind. < argc) { |
| 203 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: non-option arguments are illegal: ", argv[0]); |
| 204 | while (optindcxx . . $ optind. < argc) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s ", argv[optindcxx . . $ optind.++]); |
| 205 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n"); |
| 206 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 207 | return 5; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | if (0 == num_local_hostcxx . . $ num_local_host.) { |
| 212 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: You MUST provide a local host.\n", argv[0]); |
| 213 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 214 | return 6; |
| 215 | } |
| 216 | |
| 217 | if ( filenamecxx . . $ filename. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && commandcxx . . $ command. == COMMAND_SENDcxx . . $ COMMAND_SEND.) |
| 218 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s: Use standard input to send\n",argv[0]); |
| 219 | |
| 220 | if ( filenamecxx . . $ filename. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && commandcxx . . $ command. == COMMAND_RECVcxx . . $ COMMAND_RECV. ) |
| 221 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s: Use standard output to write\n",argv[0]); |
| 222 | |
| 223 | return 0; |
| 224 | } /* parse_arguments() */ |
| 225 | |
| 226 | static void |
| 227 | emsgcxx . . $ emsg(d0489a02ea06dfc6).(char *prog,char *s) |
| 228 | { |
| 229 | if ( prog != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! ) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s: ",prog); |
| 230 | perrorcxx . . $ perror(85c52e162fed56f9).(s); |
| 231 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!); |
| 232 | //DUMP_CORE; |
| 233 | |
| 234 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 235 | } |
| 236 | |
| 237 | static int build_endpointcxx . . $ build_endpoint(1ef8e6ec083aabb9).(char *argv0) |
| 238 | { |
| 239 | struct addrinfocxx . . $ addrinfo# hints, *rp; |
| 240 | int retval,i; |
| 241 | |
| 242 | /* Create the local endpoint. */ |
| 243 | if ( (retval = 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`!)) < 0 ) { |
| 244 | emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"socket"); |
| 245 | exitcxx . . $ exit(3ca292c338df9bb3).(retval); |
| 246 | } |
| 247 | |
| 248 | for ( i = 0;i < num_local_hostcxx . . $ num_local_host.;i++ ) { |
| 249 | /* Get the transport address for the local host name. */ |
| 250 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"Hostname %d is %s\n",i+1,local_hostcxx . . $ local_host.[i]); |
| 251 | |
| 252 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#)); |
| 253 | hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 254 | hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 255 | if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_hostcxx . . $ local_host.[i], local_portcxx . . $ local_port., &hints, &rp) != 0) { |
| 256 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n", argv0, local_hostcxx . . $ local_host.[i]); |
| 257 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 258 | } |
| 259 | |
| 260 | /* Bind this socket to the test port. */ |
| 261 | if (bindcxx . . $ bind(1ce9971e209c3c95).(retval, rp->ai_addrcxx . . $ addrinfo#ai_addr., rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.)) { |
| 262 | emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"bind"); |
| 263 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"Endpoint built.\n"); |
| 268 | |
| 269 | return retval; |
| 270 | } /* build_endpoint() */ |
| 271 | |
| 272 | /* Convenience structure to determine space needed for cmsg. */ |
| 273 | typedef unioncxx . . $ $anonymous_type_4b7acaa756ed512_1# { |
| 274 | struct sctp_initmsgcxx . . $ sctp_initmsg# initcxx . . $ $anonymous_type_4b7acaa756ed512_1#init.; |
| 275 | struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# sndrcvinfocxx . . $ $anonymous_type_4b7acaa756ed512_1#sndrcvinfo.; |
| 276 | } _sctp_cmsg_data_tcxx . . $ _sctp_cmsg_data_t#; |
| 277 | |
| 278 | |
| 279 | /* Listen on the socket, printing out anything that arrives. */ |
| 280 | static void |
| 281 | command_recvcxx . . $ command_recv(a07d8cccb7673f5a).(char *argv0, int sk) |
| 282 | { |
| 283 | struct msghdrcxx . . $ msghdr# inmessage; |
| 284 | char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(_sctp_cmsg_data_t))]; |
| 285 | struct ioveccxx . . $ iovec# iov; |
| 286 | int ret; |
| 287 | int fd; |
| 288 | int ct; |
| 289 | |
| 290 | if (listencxx . . $ listen(9b79fb6aee4c0440).(sk, 1) == -1) |
| 291 | emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0, "listen"); |
| 292 | /* Initialize inmessage with enough space for DATA... */ |
| 293 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage)); |
| 294 | iov.iov_basecxx . . $ iovec#iov_base. = buffercxx . . $ buffer.; |
| 295 | iov.iov_lencxx . . $ iovec#iov_len. = buffer_sizecxx . . $ buffer_size.; |
| 296 | inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov; |
| 297 | inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1; |
| 298 | /* or a control message. */ |
| 299 | inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg; |
| 300 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 301 | |
| 302 | /* creat a file */ |
| 303 | if ( filenamecxx . . $ filename. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! ) fd = 1; |
| 304 | else if ( (fd = opencxx . . $ open(e156e3aa1e5c4ad1).(filenamecxx . . $ filename.,O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!|O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`!,S_IREADcxx . . $ `<external>/531885356569766532/stat.h:175:10`!|S_IWRITEcxx . . $ `<external>/531885356569766532/stat.h:176:10`!)) == -1 ) |
| 305 | emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"open"); |
| 306 | |
| 307 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s Receiving...\n", argv0); |
| 308 | /* Get the messages sent */ |
| 309 | ct = 0; |
| 310 | while ( (ret = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!)) >= 0 ) { |
| 311 | if ( verbosecxx . . $ verbose. ) |
| 312 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s-%d received %d bytes\n", |
| 313 | argv0, ++ct, ret); |
| 314 | if ( !(inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!) ) { |
| 315 | //printf("%s write %d bytes\n",argv0,ret); |
| 316 | if ( writecxx . . $ write(41184a59d38b4f65).(fd,buffercxx . . $ buffer.,ret) != ret ) emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"write"); |
| 317 | } else { |
| 318 | union sctp_notificationcxx . . $ sctp_notification# *sn; |
| 319 | sn = (union sctp_notificationcxx . . $ sctp_notification# *)iov.iov_basecxx . . $ iovec#iov_base.; |
| 320 | 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`!) && |
| 321 | (sn->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change..sac_statecxx . . $ sctp_assoc_change#sac_state. |
| 322 | == SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.)) |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | } |
| 327 | |
| 328 | if ( ret < 0 ) emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"recvmsg"); |
| 329 | |
| 330 | closecxx . . $ close(7864480464b09eea).(fd); |
| 331 | closecxx . . $ close(7864480464b09eea).(sk); |
| 332 | } /* command_recv() */ |
| 333 | |
| 334 | /* Read lines from stdin and send them to the socket. */ |
| 335 | static void |
| 336 | command_sendcxx . . $ command_send(a07d8cccb7673f5a).(char *argv0, int sk) |
| 337 | { |
| 338 | struct msghdrcxx . . $ msghdr# outmsg; |
| 339 | struct ioveccxx . . $ iovec# iov; |
| 340 | struct addrinfocxx . . $ addrinfo# hints, *rp; |
| 341 | int fd; |
| 342 | int msglen; |
| 343 | int ct; |
| 344 | |
| 345 | /* Set up the destination. */ |
| 346 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(struct addrinfocxx . . $ addrinfo#)); |
| 347 | hints.ai_familycxx . . $ addrinfo#ai_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 348 | hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 349 | if (getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(remote_hostcxx . . $ remote_host., remote_portcxx . . $ remote_port., &hints, &rp) != 0) { |
| 350 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: bad hostname: %s\n", argv0, remote_hostcxx . . $ remote_host.); |
| 351 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 352 | } |
| 353 | |
| 354 | /* Initialize the message struct we use to pass messages to |
| 355 | * the remote socket. |
| 356 | */ |
| 357 | iov.iov_basecxx . . $ iovec#iov_base. = buffercxx . . $ buffer.; |
| 358 | iov.iov_lencxx . . $ iovec#iov_len. = buffer_sizecxx . . $ buffer_size.; |
| 359 | outmsg.msg_iovcxx . . $ msghdr#msg_iov. = &iov; |
| 360 | outmsg.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1; |
| 361 | outmsg.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 362 | outmsg.msg_controllencxx . . $ msghdr#msg_controllen. = 0; |
| 363 | outmsg.msg_namecxx . . $ msghdr#msg_name. = rp->ai_addrcxx . . $ addrinfo#ai_addr.; |
| 364 | outmsg.msg_namelencxx . . $ msghdr#msg_namelen. = rp->ai_addrlencxx . . $ addrinfo#ai_addrlen.; |
| 365 | |
| 366 | /* open the file */ |
| 367 | if ( filenamecxx . . $ filename. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! ) fd = 0; |
| 368 | else if ( (fd = opencxx . . $ open(e156e3aa1e5c4ad1).(filenamecxx . . $ filename.,O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!)) == -1 ) emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"open"); |
| 369 | |
| 370 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s ready to send...\n", argv0); |
| 371 | ct = 0; |
| 372 | while ( (msglen = readcxx . . $ read(7e34d0a36f355389).(fd,buffercxx . . $ buffer.,buffer_sizecxx . . $ buffer_size.)) > 0 ) { |
| 373 | /* Send to our neighbor. */ |
| 374 | iov.iov_lencxx . . $ iovec#iov_len. = msglen; |
| 375 | if ( sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(sk, &outmsg, 0) != msglen ) emsgcxx . . $ emsg(d0489a02ea06dfc6).(argv0,"sendmsg"); |
| 376 | if ( verbosecxx . . $ verbose. ) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s-%d send %d bytes\n",argv0,++ct,msglen); |
| 377 | if ( interactivecxx . . $ interactive. && fd != 1 ) |
| 378 | getcharcxx . . $ getchar(b126dc7c1de90089).(); |
| 379 | // no flow control? no problem, make it slow |
| 380 | else if ( delaycxx . . $ delay. > 0 ) |
| 381 | usleepcxx . . $ usleep(4c679297bf94b9eb).(delaycxx . . $ delay.); |
| 382 | } |
| 383 | |
| 384 | closecxx . . $ close(7864480464b09eea).(fd); |
| 385 | closecxx . . $ close(7864480464b09eea).(sk); |
| 386 | } /* command_send() */ |
| 387 | |
| 388 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 389 | { |
| 390 | int ret; |
| 391 | |
| 392 | if (( ret = parse_argumentscxx . . $ parse_arguments(afcd3168fc1188a4).(argc, argv) )) return ret; |
| 393 | |
| 394 | switch(commandcxx . . $ command.) { |
| 395 | case COMMAND_NONEcxx . . $ COMMAND_NONE.: |
| 396 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: Please specify a command.\n", argv[0]); |
| 397 | break; |
| 398 | case COMMAND_RECVcxx . . $ COMMAND_RECV.: |
| 399 | command_recvcxx . . $ command_recv(a07d8cccb7673f5a).(argv[0],build_endpointcxx . . $ build_endpoint(1ef8e6ec083aabb9).(argv[0])); |
| 400 | break; |
| 401 | case COMMAND_SENDcxx . . $ COMMAND_SEND.: |
| 402 | command_sendcxx . . $ command_send(a07d8cccb7673f5a).(argv[0],build_endpointcxx . . $ build_endpoint(1ef8e6ec083aabb9).(argv[0])); |
| 403 | break; |
| 404 | default: |
| 405 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: illegal command %d\n", argv[0], commandcxx . . $ command.); |
| 406 | } /* switch(command) */ |
| 407 | |
| 408 | return 0; |
| 409 | } |