Debian Codegraph @

src/apps/peel_server.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2003
3 * Copyright (c) 2003 Cisco
4 *
5 * The SCTP implementation is free software;
6 * you can redistribute it and/or modify it under the terms of
7 * the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * The SCTP implementation is distributed in the hope that it
12 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 * ************************
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU CC; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * In addition:
23 *
24 * Copyright (c) 2003 Cisco
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions are met:
28 *
29 * a) Redistributions of source code must retain the above copyright notice,
30 * this list of conditions and the following disclaimer.
31 *
32 * b) Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in
34 * the documentation and/or other materials provided with the distribution.
35 *
36 * c) Neither the name of Cisco Systems, Inc. nor the names of its
37 * contributors may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
42 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
48 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
50 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 *
52 * Please send any bug reports or fixes you make to the
53 * email address(es):
54 * lksctp developers <[email protected]>
55 *
56 * Or submit a bug report through the following website:
57 * https://github.com/sctp/lksctp-tools/
58 *
59 * Any bugs reported to us we will try to fix... any fixes shared will
60 * be incorporated into the next SCTP release.
61 *
62 * Written or modified by:
63 * Randall Stewart <[email protected]>
64 * Sridhar Samudrala <[email protected]>
65 */
66
67 #include <ctype.h>
68
69 #include <stdio.h>
70 #include <stdlib.h>
71 #include <unistd.h>
72 #include <sys/types.h>
73 #include <sys/ioctl.h>
74 #include <sys/stat.h>
75 #include <sys/socket.h>
76 #include <net/if.h>
77 #include <netinet/in.h>
78
79 #include <stdarg.h>
80 #include <signal.h>
81 #include <fcntl.h>
82 #include <arpa/inet.h>
83 #include <time.h>
84 #include <string.h>
85 #include <errno.h>
86 #include <poll.h>
87 #include <sys/uio.h>
88 #include <netdb.h>
89
90 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
91 #ifdef __NetBSD__
92 #include <sys/inttypes.h>
93 #endif
94
95 #define SCTP_CRC32C_POLYcxx . . $ `src/apps/peel_server.c:95:9`! 0x1EDC6F41
96 #define SCTP_CRC32Ccxx . . $ `src/apps/peel_server.c:96:9`!(c,d) (c=(c>>8)^sctp_crc_c[(c^(d))&0xFF])
97 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
98 /* Copyright 2001, D. Otis. Use this program, code or tables */
99 /* extracted from it, as desired without restriction. */
100 /* */
101 /* 32 Bit Reflected CRC table generation for SCTP. */
102 /* To accommodate serial byte data being shifted out least */
103 /* significant bit first, the table's 32 bit words are reflected */
104 /* which flips both byte and bit MS and LS positions. The CRC */
105 /* is calculated MS bits first from the perspective of the serial*/
106 /* stream. The x^32 term is implied and the x^0 term may also */
107 /* be shown as +1. The polynomial code used is 0x1EDC6F41. */
108 /* Castagnoli93 */
109 /* x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+ */
110 /* x^11+x^10+x^9+x^8+x^6+x^0 */
111 /* Guy Castagnoli Stefan Braeuer and Martin Herrman */
112 /* "Optimization of Cyclic Redundancy-Check Codes */
113 /* with 24 and 32 Parity Bits", */
114 /* IEEE Transactions on Communications, Vol.41, No.6, June 1993 */
115 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
116
117 static unsigned char buffer1cxx . . $ buffer1.[4100];
118 static unsigned char buffer2cxx . . $ buffer2.[4100];
119 static unsigned char buffer3cxx . . $ buffer3.[4100];
120 static unsigned char buffer4cxx . . $ buffer4.[4100];
121 static struct sockaddr_incxx . . $ sockaddr_in# bindtocxx . . $ bindto.,gotcxx . . $ got.;
122 static socklen_tcxx . . $ socklen_t# lencxx . . $ len.;
123
124 unsigned long sctp_crc_ccxx . . $ sctp_crc_c.[256] = {
125 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
126 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
127 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL,
128 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
129 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL,
130 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L,
131 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L,
132 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL,
133 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL,
134 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
135 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L,
136 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL,
137 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L,
138 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL,
139 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL,
140 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L,
141 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L,
142 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L,
143 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L,
144 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
145 0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L,
146 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L,
147 0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L,
148 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L,
149 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L,
150 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L,
151 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L,
152 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L,
153 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L,
154 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
155 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L,
156 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L,
157 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL,
158 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L,
159 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L,
160 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL,
161 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L,
162 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL,
163 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL,
164 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
165 0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L,
166 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL,
167 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL,
168 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L,
169 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL,
170 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L,
171 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L,
172 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL,
173 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L,
174 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
175 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL,
176 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L,
177 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL,
178 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L,
179 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L,
180 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL,
181 0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL,
182 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L,
183 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L,
184 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
185 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L,
186 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL,
187 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL,
188 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L,
189 };
190
191 u_int32_tcxx . . $ u_int32_t#
192 update_crc32cxx . . $ update_crc32(ade514a5a6baa708).(u_int32_tcxx . . $ u_int32_t# crc32,
193 unsigned char *buffer,
194 unsigned int length)
195 {
196 int i;
197 for (i = 0; i < length; i++) {
198 SCTP_CRC32Ccxx . . $ `src/apps/peel_server.c:96:9`!(crc32, buffer[i]);
199 }
200 return (crc32);
201 }
202
203 u_int32_tcxx . . $ u_int32_t#
204 sctp_csum_finalizecxx . . $ sctp_csum_finalize(2141b656ce2cc063).(u_int32_tcxx . . $ u_int32_t# crc32)
205 {
206 u_int32_tcxx . . $ u_int32_t# result;
207 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == BIG_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:28:10`!
208 u_int8_t byte0, byte1, byte2, byte3;
209 #endif
210 /* Complement the result */
211 result = ~crc32;
212 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == BIG_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:28:10`!
213 /*
214 * For BIG-ENDIAN.. aka Motorola byte order the result is in
215 * little-endian form. So we must manually swap the bytes. Then
216 * we can call htonl() which does nothing...
217 */
218 byte0 = result & 0x000000ff;
219 byte1 = (result >> 8) & 0x000000ff;
220 byte2 = (result >> 16) & 0x000000ff;
221 byte3 = (result >> 24) & 0x000000ff;
222 result = ((byte0 << 24) |
223 (byte1 << 16) |
224 (byte2 << 8) |
225 byte3);
226 crc32 = htonl(result);
227 #else
228 /*
229 * For INTEL platforms the result comes out in network order.
230 * No htonl is required or the swap above. So we optimize out
231 * both the htonl and the manual swap above.
232 */
233 crc32 = result;
234 #endif
235 return (crc32);
236 }
237
238 int
239 check_bufferscxx . . $ check_buffers(b126dc7c1de90089).(void)
240 {
241 /* Prepare buffers */
242 u_int32_tcxx . . $ u_int32_t# temp,*csum;
243 int ret=0;
244 temp = 0xffffffff;
245 temp = update_crc32cxx . . $ update_crc32(ade514a5a6baa708).(temp,buffer1cxx . . $ buffer1.,(sizeof(buffer1cxx . . $ buffer1.)-4));
246 temp = sctp_csum_finalizecxx . . $ sctp_csum_finalize(2141b656ce2cc063).(temp);
247 csum = (u_int32_tcxx . . $ u_int32_t# *)(buffer1cxx . . $ buffer1.+(sizeof(buffer1cxx . . $ buffer1.)-4));
248 if(*csum != temp){
249 printfcxx . . $ printf(581fddd72a8db8fc).("Buffer1: Found csum:%x calculated:%x\n",
250 *csum,temp);
251 ret++;
252 }
253 temp = 0xffffffff;
254 temp = update_crc32cxx . . $ update_crc32(ade514a5a6baa708).(temp,buffer2cxx . . $ buffer2.,(sizeof(buffer2cxx . . $ buffer2.)-4));
255 temp = sctp_csum_finalizecxx . . $ sctp_csum_finalize(2141b656ce2cc063).(temp);
256 csum = (u_int32_tcxx . . $ u_int32_t# *)(buffer2cxx . . $ buffer2.+(sizeof(buffer2cxx . . $ buffer2.)-4));
257 if(*csum != temp){
258 printfcxx . . $ printf(581fddd72a8db8fc).("Buffer2: Found csum:%x calculated:%x\n",
259 *csum,temp);
260 ret++;
261 }
262
263 temp = 0xffffffff;
264 temp = update_crc32cxx . . $ update_crc32(ade514a5a6baa708).(temp,buffer3cxx . . $ buffer3.,(sizeof(buffer3cxx . . $ buffer3.)-4));
265 temp = sctp_csum_finalizecxx . . $ sctp_csum_finalize(2141b656ce2cc063).(temp);
266 csum = (u_int32_tcxx . . $ u_int32_t# *)(buffer3cxx . . $ buffer3.+(sizeof(buffer3cxx . . $ buffer3.)-4));
267 if(*csum != temp){
268 printfcxx . . $ printf(581fddd72a8db8fc).("Buffer3: Found csum:%x calculated:%x\n",
269 *csum,temp);
270 ret++;
271 }
272
273 temp = 0xffffffff;
274 temp = update_crc32cxx . . $ update_crc32(ade514a5a6baa708).(temp,buffer4cxx . . $ buffer4.,(sizeof(buffer4cxx . . $ buffer4.)-4));
275 temp = sctp_csum_finalizecxx . . $ sctp_csum_finalize(2141b656ce2cc063).(temp);
276 csum = (u_int32_tcxx . . $ u_int32_t# *)(buffer4cxx . . $ buffer4.+(sizeof(buffer4cxx . . $ buffer4.)-4));
277 if(*csum != temp){
278 printfcxx . . $ printf(581fddd72a8db8fc).("Buffer4: Found csum:%x calculated:%x\n",
279 *csum,temp);
280 ret++;
281 }
282 return(ret);
283 }
284
285 static int
286 my_handle_notificationcxx . . $ my_handle_notification(3c8082c546dd2ea0).(int fd,char *notify_buf) {
287 union sctp_notificationcxx . . $ sctp_notification# *snp;
288 struct sctp_assoc_changecxx . . $ sctp_assoc_change# *sac;
289 struct sctp_paddr_changecxx . . $ sctp_paddr_change# *spc;
290 struct sctp_remote_errorcxx . . $ sctp_remote_error# *sre;
291 struct sctp_send_failedcxx . . $ sctp_send_failed# *ssf;
292 struct sctp_shutdown_eventcxx . . $ sctp_shutdown_event# *sse;
293 int asocUp;
294 char *str;
295 char buf[256];
296 struct sockaddr_incxx . . $ sockaddr_in# *sin;
297 struct sockaddr_in6cxx . . $ sockaddr_in6# *sin6;
298
299 snp = (union sctp_notificationcxx . . $ sctp_notification# *)notify_buf;
300 asocUp = 0;
301 switch(snp->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type.) {
302 case SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!:
303 sac = &snp->sn_assoc_changecxx . . $ sctp_notification#sn_assoc_change.;
304 switch(sac->sac_statecxx . . $ sctp_assoc_change#sac_state.) {
305
306 case SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.:
307 str = "COMMUNICATION UP";
308 asocUp++;
309 break;
310 case SCTP_COMM_LOSTcxx . . $ SCTP_COMM_LOST.:
311 str = "COMMUNICATION LOST";
312 break;
313 case SCTP_RESTARTcxx . . $ SCTP_RESTART.:
314 str = "RESTART";
315 asocUp++;
316 break;
317 case SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.:
318 str = "SHUTDOWN COMPLETE";
319 break;
320 case SCTP_CANT_STR_ASSOCcxx . . $ SCTP_CANT_STR_ASSOC.:
321 str = "CANT START ASSOC";
322 printfcxx . . $ printf(581fddd72a8db8fc).("EXIT:SCTP_ASSOC_CHANGE: %s, assoc=%xh\n", str,
323 (uint32_tcxx . . $ uint32_t#)sac->sac_assoc_idcxx . . $ sctp_assoc_change#sac_assoc_id.);
324 exitcxx . . $ exit(3ca292c338df9bb3).(0);
325 break;
326 default:
327 str = "UNKNOWN";
328 } /* end switch(sac->sac_state) */
329 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_ASSOC_CHANGE: %s, assoc=%xh\n", str,
330 (uint32_tcxx . . $ uint32_t#)sac->sac_assoc_idcxx . . $ sctp_assoc_change#sac_assoc_id.);
331 break;
332 case SCTP_PEER_ADDR_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:668:9`!:
333 spc = &snp->sn_paddr_changecxx . . $ sctp_notification#sn_paddr_change.;
334 switch(spc->spc_statecxx . . $ sctp_paddr_change#spc_state.) {
335 case SCTP_ADDR_AVAILABLEcxx . . $ SCTP_ADDR_AVAILABLE.:
336 str = "ADDRESS AVAILABLE";
337 break;
338 case SCTP_ADDR_UNREACHABLEcxx . . $ SCTP_ADDR_UNREACHABLE.:
339 str = "ADDRESS UNAVAILABLE";
340 break;
341 case SCTP_ADDR_REMOVEDcxx . . $ SCTP_ADDR_REMOVED.:
342 str = "ADDRESS REMOVED";
343 break;
344 case SCTP_ADDR_ADDEDcxx . . $ SCTP_ADDR_ADDED.:
345 str = "ADDRESS ADDED";
346 break;
347 case SCTP_ADDR_MADE_PRIMcxx . . $ SCTP_ADDR_MADE_PRIM.:
348 str = "ADDRESS MADE PRIMARY";
349 break;
350 default:
351 str = "UNKNOWN";
352 } /* end switch */
353 sin6 = (struct sockaddr_in6cxx . . $ sockaddr_in6# *)&spc->spc_aaddrcxx . . $ sctp_paddr_change#spc_aaddr.;
354 if (sin6->sin6_familycxx . . $ sockaddr_in6#sin6_family. == AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!) {
355 inet_ntopcxx . . $ inet_ntop(6a923972b45bea03).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, (char*)&sin6->sin6_addrcxx . . $ sockaddr_in6#sin6_addr., buf, sizeof(buf));
356 } else {
357 sin = (struct sockaddr_incxx . . $ sockaddr_in# *)&spc->spc_aaddrcxx . . $ sctp_paddr_change#spc_aaddr.;
358 inet_ntopcxx . . $ inet_ntop(6a923972b45bea03).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, (char*)&sin->sin_addrcxx . . $ sockaddr_in#sin_addr., buf, sizeof(buf));
359 }
360 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_PEER_ADDR_CHANGE: %s, addr=%s, assoc=%xh\n", str,
361 buf, (uint32_tcxx . . $ uint32_t#)spc->spc_assoc_idcxx . . $ sctp_paddr_change#spc_assoc_id.);
362 break;
363 case SCTP_REMOTE_ERRORcxx . . $ `<external>/17169092326581286071/sctp.h:672:9`!:
364 sre = &snp->sn_remote_errorcxx . . $ sctp_notification#sn_remote_error.;
365 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_REMOTE_ERROR: assoc=%xh\n",
366 (uint32_tcxx . . $ uint32_t#)sre->sre_assoc_idcxx . . $ sctp_remote_error#sre_assoc_id.);
367 break;
368 case SCTP_SEND_FAILEDcxx . . $ `<external>/17169092326581286071/sctp.h:670:9`!:
369 ssf = &snp->sn_send_failedcxx . . $ sctp_notification#sn_send_failed.;
370 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_SEND_FAILED: assoc=%xh\n",
371 (uint32_tcxx . . $ uint32_t#)ssf->ssf_assoc_idcxx . . $ sctp_send_failed#ssf_assoc_id.);
372 break;
373 case SCTP_ADAPTATION_INDICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:678:9`!:
374 {
375 struct sctp_adaptation_eventcxx . . $ sctp_adaptation_event# *ae;
376 ae = &snp->sn_adaptation_eventcxx . . $ sctp_notification#sn_adaptation_event.;
377 printfcxx . . $ printf(581fddd72a8db8fc).("\nSCTP_adaptation_indication bits:0x%x\n",
378 (u_intcxx . . $ u_int#)ae->sai_adaptation_indcxx . . $ sctp_adaptation_event#sai_adaptation_ind.);
379 }
380 break;
381 case SCTP_PARTIAL_DELIVERY_EVENTcxx . . $ `<external>/17169092326581286071/sctp.h:676:9`!:
382 {
383 struct sctp_pdapi_eventcxx . . $ sctp_pdapi_event# *pdapi;
384 pdapi = &snp->sn_pdapi_eventcxx . . $ sctp_notification#sn_pdapi_event.;
385 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_PD-API event:%u\n",
386 pdapi->pdapi_indicationcxx . . $ sctp_pdapi_event#pdapi_indication.);
387 if(pdapi->pdapi_indicationcxx . . $ sctp_pdapi_event#pdapi_indication. == 0){
388 printfcxx . . $ printf(581fddd72a8db8fc).("PDI- Aborted\n");
389 }
390 }
391 break;
392
393 case SCTP_SHUTDOWN_EVENTcxx . . $ `<external>/17169092326581286071/sctp.h:674:9`!:
394 sse = &snp->sn_shutdown_eventcxx . . $ sctp_notification#sn_shutdown_event.;
395 printfcxx . . $ printf(581fddd72a8db8fc).("SCTP_SHUTDOWN_EVENT: assoc=%xh\n",
396 (uint32_tcxx . . $ uint32_t#)sse->sse_assoc_idcxx . . $ sctp_shutdown_event#sse_assoc_id.);
397 break;
398 default:
399 printfcxx . . $ printf(581fddd72a8db8fc).("Unknown notification event type=%xh\n",
400 snp->sn_headercxx . . $ sctp_notification#sn_header..sn_typecxx . . $ sctp_notification#$anonymous_type_3#sn_type.);
401 } /* end switch(snp->sn_type) */
402 return(asocUp);
403 }
404
405
406 static char readBuffercxx . . $ readBuffer.[65535];
407 static int szcxx . . $ sz.=0;
408 static char controlVectorcxx . . $ controlVector.[65535];
409 static struct msghdrcxx . . $ msghdr# msgcxx . . $ msg.;
410 int
411 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(int fd,int maxread)
412 {
413 /* receive some number of datagrams and
414 * act on them.
415 */
416 struct ioveccxx . . $ iovec# iov[2];
417 unsigned char from[200];
418
419 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&msgcxx . . $ msg.,0,sizeof(msgcxx . . $ msg.));
420 memsetcxx . . $ memset(d1de1e4fb215f1c6).(controlVectorcxx . . $ controlVector.,0,sizeof(controlVectorcxx . . $ controlVector.));
421 memsetcxx . . $ memset(d1de1e4fb215f1c6).(readBuffercxx . . $ readBuffer.,0,sizeof(readBuffercxx . . $ readBuffer.));
422
423 iov[0].iov_basecxx . . $ iovec#iov_base. = readBuffercxx . . $ readBuffer.;
424 iov[0].iov_lencxx . . $ iovec#iov_len. = maxread;
425 iov[1].iov_basecxx . . $ iovec#iov_base. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
426 iov[1].iov_lencxx . . $ iovec#iov_len. = 0;
427 msgcxx . . $ msg..msg_namecxx . . $ msghdr#msg_name. = (caddr_tcxx . . $ caddr_t#)from;
428 msgcxx . . $ msg..msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(from);
429 msgcxx . . $ msg..msg_iovcxx . . $ msghdr#msg_iov. = iov;
430 msgcxx . . $ msg..msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
431 msgcxx . . $ msg..msg_controlcxx . . $ msghdr#msg_control. = (caddr_tcxx . . $ caddr_t#)controlVectorcxx . . $ controlVector.;
432 msgcxx . . $ msg..msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(controlVectorcxx . . $ controlVector.);
433 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
434 szcxx . . $ sz. = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(fd,&msgcxx . . $ msg.,0);
435 printfcxx . . $ printf(581fddd72a8db8fc).("Read fd:%d returns %d errno:%d control len is %zu msgflg:%x\n",
436 fd,
437 szcxx . . $ sz.,errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!,
438 msgcxx . . $ msg..msg_controllencxx . . $ msghdr#msg_controllen.,
439 msgcxx . . $ msg..msg_flagscxx . . $ msghdr#msg_flags.);
440
441 if (msgcxx . . $ msg..msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!) {
442 printfcxx . . $ printf(581fddd72a8db8fc).("Got a notification\n");
443 return(my_handle_notificationcxx . . $ my_handle_notification(3c8082c546dd2ea0).(fd,readBuffercxx . . $ readBuffer.));
444 }else{
445 printfcxx . . $ printf(581fddd72a8db8fc).("Got data\n");
446 return(-1);
447 }
448 }
449
450
451 int
452 poll_fdcxx . . $ poll_fd(7864480464b09eea).(int fd)
453 {
454 int cameup;
455 int max;
456 fd_setcxx . . $ fd_set# readfds,writefds,exceptfds;
457 struct timevalcxx . . $ timeval# tv;
458
459 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&tv,0,sizeof(tv));
460 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&readfds);
461 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&writefds);
462 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&exceptfds);
463 cameup = 0;
464 max = fd + 1;
465
466 printfcxx . . $ printf(581fddd72a8db8fc).("poll_fd\n");
467 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(fd,&readfds);
468
469 if (selectcxx . . $ select(6d24c7514c8a5b88).(max, &readfds, &writefds, &exceptfds, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) == -1)
470 return(cameup);
471 if(FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(fd,&readfds)){
472 printfcxx . . $ printf(581fddd72a8db8fc).("Read please\n");
473 cameup += my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd,4100);
474 }
475
476 return(cameup);
477 }
478
479 static sctp_assoc_tcxx . . $ sctp_assoc_t#
480 dig_out_asocidcxx . . $ dig_out_asocid(b126dc7c1de90089).(void)
481 {
482 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *s_info;
483 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
484 s_info = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
485 if(msgcxx . . $ msg..msg_controllencxx . . $ msghdr#msg_controllen.){
486 /* parse through and see if we find
487 * the sctp_sndrcvinfo
488 */
489 cmsg = (struct cmsghdrcxx . . $ cmsghdr# *)controlVectorcxx . . $ controlVector.;
490 while(cmsg){
491 if(cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. == IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!){
492 if(cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. == SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!){
493 /* Got it */
494 s_info = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
495 break;
496 }
497 }
498 cmsg = CMSG_NXTHDRcxx . . $ `<external>/8962547315054503424/socket.h:303:9`!(&msg,cmsg);
499 }
500 }else{
501 printfcxx . . $ printf(581fddd72a8db8fc).("No CMSG?\n");
502 exitcxx . . $ exit(3ca292c338df9bb3).(0);
503 }
504 if(s_info == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!){
505 printfcxx . . $ printf(581fddd72a8db8fc).("No sinfo?\n");
506 exitcxx . . $ exit(3ca292c338df9bb3).(0);
507 }
508 return(s_info->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id.);
509 }
510
511
512 void
513 processcxx . . $ process(3e454b8ccf442868).(int fd,int magic)
514 {
515 int fd1,num_asoc,ret,i;
516 sctp_assoc_tcxx . . $ sctp_assoc_t# asoc;
517 struct timespeccxx . . $ timespec# ts;
518 num_asoc = 0;
519 i = 1;
520 ts.tv_seccxx . . $ timespec#tv_sec. = 0;
521 ts.tv_nseccxx . . $ timespec#tv_nsec. = 10000;
522
523 while(i < 4099){
524 printfcxx . . $ printf(581fddd72a8db8fc).("pass %d\n",i);
525 while(num_asoc < 2){
526 ret = poll_fdcxx . . $ poll_fd(7864480464b09eea).(fd);
527 if(ret >0 ){
528 num_asoc += ret;
529 }else if(ret == 0){
530 sleepcxx . . $ sleep(2141b656ce2cc063).(1);
531 }else if(ret < 0){
532 printfcxx . . $ printf(581fddd72a8db8fc).("Got data? %d\n",szcxx . . $ sz.);
533 sleepcxx . . $ sleep(2141b656ce2cc063).(1);
534 }
535 printfcxx . . $ printf(581fddd72a8db8fc).("asoc count is %d\n",num_asoc);
536 }
537 again:
538 printfcxx . . $ printf(581fddd72a8db8fc).("Reading for %d bytes from fd:%d\n",
539 i,fd);
540 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd,i);
541 if(szcxx . . $ sz. == i){
542 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer1cxx . . $ buffer1.,readBuffercxx . . $ readBuffer.,i);
543 }else{
544 printfcxx . . $ printf(581fddd72a8db8fc).("Huh I am messed up read %d wanted %d\n",
545 szcxx . . $ sz.,i);
546 goto again;
547 }
548 if(msgcxx . . $ msg..msg_flagscxx . . $ msghdr#msg_flags. & MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!){
549 printfcxx . . $ printf(581fddd72a8db8fc).("Huh got EOR on paritial read?\n");
550 exitcxx . . $ exit(3ca292c338df9bb3).(0);
551 }
552 asoc = dig_out_asocidcxx . . $ dig_out_asocid(b126dc7c1de90089).();
553 nanosleepcxx . . $ nanosleep(645c6fc2576d4126).(&ts,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
554
555 fd1 = sctp_peeloffcxx . . $ sctp_peeloff(9b79fb6aee4c0440).(fd,asoc);
556 if(fd1 == -1){
557 printfcxx . . $ printf(581fddd72a8db8fc).("peeloff failed %d/err:%d\n",
558 fd1,errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
559 exitcxx . . $ exit(3ca292c338df9bb3).(0);
560 }
561 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd1,(4100-i));
562 if(szcxx . . $ sz. > 0){
563 memcpycxx . . $ memcpy(cc817cb175f282d).(&buffer1cxx . . $ buffer1.[i],readBuffercxx . . $ readBuffer.,szcxx . . $ sz.);
564 printfcxx . . $ printf(581fddd72a8db8fc).("Copied %d bytes\n",szcxx . . $ sz.);
565 }else{
566 printfcxx . . $ printf(581fddd72a8db8fc).("Huh only read %d\n",szcxx . . $ sz.);
567 }
568 if(magic >= i){
569 printfcxx . . $ printf(581fddd72a8db8fc).("magic engaged\n");
570 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd,i);
571 }else{
572 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd,4100);
573 }
574 if(szcxx . . $ sz. > 0){
575 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer2cxx . . $ buffer2.,readBuffercxx . . $ readBuffer.,szcxx . . $ sz.);
576 printfcxx . . $ printf(581fddd72a8db8fc).("copied %d bytes\n",szcxx . . $ sz.);
577 }else{
578 printfcxx . . $ printf(581fddd72a8db8fc).("Huh only read %d\n",szcxx . . $ sz.);
579 }
580 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd1,4100);
581 if(szcxx . . $ sz. > 0){
582 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer3cxx . . $ buffer3.,readBuffercxx . . $ readBuffer.,szcxx . . $ sz.);
583 printfcxx . . $ printf(581fddd72a8db8fc).("copied %d bytes\n",szcxx . . $ sz.);
584 }else{
585 printfcxx . . $ printf(581fddd72a8db8fc).("Huh only read %d\n",szcxx . . $ sz.);
586 }
587 my_sctpReadInputcxx . . $ my_sctpReadInput(9b79fb6aee4c0440).(fd,4100);
588 if(szcxx . . $ sz. > 0){
589 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer4cxx . . $ buffer4.,readBuffercxx . . $ readBuffer.,szcxx . . $ sz.);
590 printfcxx . . $ printf(581fddd72a8db8fc).("copied %d bytes\n",szcxx . . $ sz.);
591 }else{
592 printfcxx . . $ printf(581fddd72a8db8fc).("Huh only read %d\n",szcxx . . $ sz.);
593 }
594 if(check_bufferscxx . . $ check_buffers(b126dc7c1de90089).()){
595 exitcxx . . $ exit(3ca292c338df9bb3).(0);
596 }
597 closecxx . . $ close(7864480464b09eea).(fd1);
598 i++;
599 num_asoc--;
600 }
601 }
602
603 int
604 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
605 {
606 int i,fd;
607 uint16_tcxx . . $ uint16_t# myport=0;
608 int magic=0;
609 struct sctp_event_subscribecxx . . $ sctp_event_subscribe# event = {0};
610 while((i= getoptcxx . . $ getopt(2483c31ff9bab884).(argc,argv,"m:M:")) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!){
611 switch(i){
612 case 'm':
613 myport = (uint16_tcxx . . $ uint16_t#)strtolcxx . . $ strtol(44bbb87609b212fc).(optargcxx . . $ optarg.,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,0);
614 break;
615 case 'M':
616 magic = strtolcxx . . $ strtol(44bbb87609b212fc).(optargcxx . . $ optarg.,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,0);
617 break;
618 };
619 }
620 /**********************socket 1 *******************/
621 fd = socketcxx . . $ socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
622 if(fd == -1){
623 printfcxx . . $ printf(581fddd72a8db8fc).("can't open socket:%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
624 return(-1);
625 }
626 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&bindtocxx . . $ bindto.,0,sizeof(bindtocxx . . $ bindto.));
627 //len = bindto.sin_len = sizeof(bindto);
628 lencxx . . $ len. = sizeof(bindtocxx . . $ bindto.);
629 bindtocxx . . $ bindto..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
630 printfcxx . . $ printf(581fddd72a8db8fc).("bind port %d\n",myport);
631 bindtocxx . . $ bindto..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(myport);
632 if(bindcxx . . $ bind(1ce9971e209c3c95).(fd,(struct sockaddrcxx . . $ sockaddr# *)&bindtocxx . . $ bindto., lencxx . . $ len.) < 0){
633 printfcxx . . $ printf(581fddd72a8db8fc).("can't bind a socket:%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
634 closecxx . . $ close(7864480464b09eea).(fd);
635 return(-1);
636 }
637 if(getsocknamecxx . . $ getsockname(46fcd054f4a4d98b).(fd,(struct sockaddrcxx . . $ sockaddr# *)&gotcxx . . $ got.,&lencxx . . $ len.) < 0){
638 printfcxx . . $ printf(581fddd72a8db8fc).("get sockname failed err:%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
639 closecxx . . $ close(7864480464b09eea).(fd);
640 return(-1);
641 }
642 printfcxx . . $ printf(581fddd72a8db8fc).("fd uses port %d\n",ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(got.sin_port));
643 if (listencxx . . $ listen(9b79fb6aee4c0440).(fd, 100) == -1) {
644 printfcxx . . $ printf(581fddd72a8db8fc).("listen err: %d\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
645 closecxx . . $ close(7864480464b09eea).(fd);
646 return(-1);
647 }
648 /* enable all event notifications */
649 event.sctp_data_io_eventcxx . . $ sctp_event_subscribe#sctp_data_io_event. = 1;
650 event.sctp_association_eventcxx . . $ sctp_event_subscribe#sctp_association_event. = 1;
651 event.sctp_address_eventcxx . . $ sctp_event_subscribe#sctp_address_event. = 1;
652 event.sctp_send_failure_eventcxx . . $ sctp_event_subscribe#sctp_send_failure_event. = 1;
653 event.sctp_peer_error_eventcxx . . $ sctp_event_subscribe#sctp_peer_error_event. = 1;
654 event.sctp_shutdown_eventcxx . . $ sctp_event_subscribe#sctp_shutdown_event. = 1;
655 event.sctp_partial_delivery_eventcxx . . $ sctp_event_subscribe#sctp_partial_delivery_event. = 1;
656 event.sctp_adaptation_layer_eventcxx . . $ sctp_event_subscribe#sctp_adaptation_layer_event. = 1;
657 if (setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(fd, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!,
658 SCTP_EVENTScxx . . $ `<external>/17169092326581286071/sctp.h:80:9`!, &event,
659 sizeof(event)) != 0) {
660 printfcxx . . $ printf(581fddd72a8db8fc).("Gak, can't set events errno:%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
661 exitcxx . . $ exit(3ca292c338df9bb3).(0);
662 }
663 printfcxx . . $ printf(581fddd72a8db8fc).("to process\n");
664 processcxx . . $ process(3e454b8ccf442868).(fd,magic);
665 return(0);
666 }
667