| 1 | /*****************************************************************************/cxx . . $ `<file>/kiss/net2kiss.c`/ |
| 2 | |
| 3 | /* |
| 4 | * net2kiss.c - convert a network interface to KISS data stream |
| 5 | * |
| 6 | * Copyright (C) 1996 Thomas Sailer ([email protected]) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
| 22 | * |
| 23 | * Please note that the GPL allows you to use the driver, NOT the radio. |
| 24 | * In order to use the radio, you need a license from the communications |
| 25 | * authority of your country. |
| 26 | * |
| 27 | * |
| 28 | * History: |
| 29 | * 0.1 18.09.96 Started |
| 30 | */ |
| 31 | |
| 32 | /*****************************************************************************/ |
| 33 | |
| 34 | #include <stdio.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/time.h> |
| 38 | #include <errno.h> |
| 39 | #include <syslog.h> |
| 40 | #include <unistd.h> |
| 41 | #include <sys/ioctl.h> |
| 42 | #include <endian.h> |
| 43 | #include <netinet/in.h> |
| 44 | #include <sys/stat.h> |
| 45 | #include <fcntl.h> |
| 46 | #include <signal.h> |
| 47 | #include <grp.h> |
| 48 | #include <pty.h> |
| 49 | #include <string.h> |
| 50 | #include <termios.h> |
| 51 | #include <limits.h> |
| 52 | |
| 53 | #include <sys/socket.h> |
| 54 | #include <net/if.h> |
| 55 | |
| 56 | #include <net/ethernet.h> |
| 57 | |
| 58 | |
| 59 | /* --------------------------------------------------------------------- */ |
| 60 | |
| 61 | static int fdifcxx . . $ fdif., fdptycxx . . $ fdpty.; |
| 62 | static struct ifreqcxx . . $ ifreq# ifrcxx . . $ ifr.; |
| 63 | static char *prognamecxx . . $ progname.; |
| 64 | static int verbosecxx . . $ verbose.; |
| 65 | static int i_am_unix98_pty_mastercxx . . $ i_am_unix98_pty_master.; /* unix98 ptmx support */ |
| 66 | static char *nameptscxx . . $ namepts.; /* name of the unix98 pts slave, which |
| 67 | * the client has to use */ |
| 68 | |
| 69 | /* --------------------------------------------------------------------- */ |
| 70 | |
| 71 | static void diecxx . . $ die(fda57c8427c60377).(char *func) |
| 72 | { |
| 73 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s (%i)%s%s\n", prognamecxx . . $ progname., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), |
| 74 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, func ? " in " : "", func ? func : ""); |
| 75 | syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "%s (%i)%s%s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), |
| 76 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, func ? " in " : "", func ? func : ""); |
| 77 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 78 | } |
| 79 | |
| 80 | /* --------------------------------------------------------------------- */ |
| 81 | |
| 82 | static void display_packetcxx . . $ display_packet(e1e8b00c42c42532).(unsigned char *bp, unsigned int len) |
| 83 | { |
| 84 | unsigned char v1=1,cmd=0; |
| 85 | unsigned char i,j; |
| 86 | |
| 87 | if (!bp || !len) |
| 88 | return; |
| 89 | if (len < 8) |
| 90 | return; |
| 91 | if (bp[1] & 1) { |
| 92 | /* |
| 93 | * FlexNet Header Compression |
| 94 | */ |
| 95 | v1 = 0; |
| 96 | cmd = (bp[1] & 2) != 0; |
| 97 | printfcxx . . $ printf(581fddd72a8db8fc).("fm ? to "); |
| 98 | i = (bp[2] >> 2) & 0x3f; |
| 99 | if (i) |
| 100 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 101 | i = ((bp[2] << 4) | ((bp[3] >> 4) & 0xf)) & 0x3f; |
| 102 | if (i) |
| 103 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 104 | i = ((bp[3] << 2) | ((bp[4] >> 6) & 3)) & 0x3f; |
| 105 | if (i) |
| 106 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 107 | i = bp[4] & 0x3f; |
| 108 | if (i) |
| 109 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 110 | i = (bp[5] >> 2) & 0x3f; |
| 111 | if (i) |
| 112 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 113 | i = ((bp[5] << 4) | ((bp[6] >> 4) & 0xf)) & 0x3f; |
| 114 | if (i) |
| 115 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i+0x20); |
| 116 | printfcxx . . $ printf(581fddd72a8db8fc).("-%u QSO Nr %u", bp[6] & 0xf, (bp[0] << 6) | |
| 117 | (bp[1] >> 2)); |
| 118 | bp += 7; |
| 119 | len -= 7; |
| 120 | } else { |
| 121 | /* |
| 122 | * normal header |
| 123 | */ |
| 124 | if (len < 15) |
| 125 | return; |
| 126 | if ((bp[6] & 0x80) != (bp[13] & 0x80)) { |
| 127 | v1 = 0; |
| 128 | cmd = (bp[6] & 0x80); |
| 129 | } |
| 130 | printfcxx . . $ printf(581fddd72a8db8fc).("fm "); |
| 131 | for (i = 7; i < 13; i++) |
| 132 | if ((bp[i] &0xfe) != 0x40) |
| 133 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",bp[i] >> 1); |
| 134 | printfcxx . . $ printf(581fddd72a8db8fc).("-%u to ",(bp[13] >> 1) & 0xf); |
| 135 | for (i = 0; i < 6; i++) |
| 136 | if ((bp[i] &0xfe) != 0x40) |
| 137 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",bp[i] >> 1); |
| 138 | printfcxx . . $ printf(581fddd72a8db8fc).("-%u",(bp[6] >> 1) & 0xf); |
| 139 | bp += 14; |
| 140 | len -= 14; |
| 141 | if ((!(bp[-1] & 1)) && (len >= 7)) printfcxx . . $ printf(581fddd72a8db8fc).(" via "); |
| 142 | while ((!(bp[-1] & 1)) && (len >= 7)) { |
| 143 | for (i = 0; i < 6; i++) |
| 144 | if ((bp[i] &0xfe) != 0x40) |
| 145 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",bp[i] >> 1); |
| 146 | printfcxx . . $ printf(581fddd72a8db8fc).("-%u",(bp[6] >> 1) & 0xf); |
| 147 | bp += 7; |
| 148 | len -= 7; |
| 149 | if ((!(bp[-1] & 1)) && (len >= 7)) |
| 150 | printfcxx . . $ printf(581fddd72a8db8fc).(","); |
| 151 | } |
| 152 | } |
| 153 | if (!len) |
| 154 | return; |
| 155 | i = *bp++; |
| 156 | len--; |
| 157 | j = v1 ? ((i & 0x10) ? '!' : ' ') : |
| 158 | ((i & 0x10) ? (cmd ? '+' : '-') : (cmd ? '^' : 'v')); |
| 159 | if (!(i & 1)) { |
| 160 | /* |
| 161 | * Info frame |
| 162 | */ |
| 163 | printfcxx . . $ printf(581fddd72a8db8fc).(" I%u%u%c",(i >> 5) & 7,(i >> 1) & 7,j); |
| 164 | } else if (i & 2) { |
| 165 | /* |
| 166 | * U frame |
| 167 | */ |
| 168 | switch (i & (~0x10)) { |
| 169 | case 0x03: |
| 170 | printfcxx . . $ printf(581fddd72a8db8fc).(" UI%c",j); |
| 171 | break; |
| 172 | case 0x2f: |
| 173 | printfcxx . . $ printf(581fddd72a8db8fc).(" SABM%c",j); |
| 174 | break; |
| 175 | case 0x43: |
| 176 | printfcxx . . $ printf(581fddd72a8db8fc).(" DISC%c",j); |
| 177 | break; |
| 178 | case 0x0f: |
| 179 | printfcxx . . $ printf(581fddd72a8db8fc).(" DM%c",j); |
| 180 | break; |
| 181 | case 0x63: |
| 182 | printfcxx . . $ printf(581fddd72a8db8fc).(" UA%c",j); |
| 183 | break; |
| 184 | case 0x87: |
| 185 | printfcxx . . $ printf(581fddd72a8db8fc).(" FRMR%c",j); |
| 186 | break; |
| 187 | default: |
| 188 | printfcxx . . $ printf(581fddd72a8db8fc).(" unknown U (0x%x)%c",i & (~0x10),j); |
| 189 | break; |
| 190 | } |
| 191 | } else { |
| 192 | /* |
| 193 | * supervisory |
| 194 | */ |
| 195 | switch (i & 0xf) { |
| 196 | case 0x1: |
| 197 | printfcxx . . $ printf(581fddd72a8db8fc).(" RR%u%c",(i >> 5) & 7,j); |
| 198 | break; |
| 199 | case 0x5: |
| 200 | printfcxx . . $ printf(581fddd72a8db8fc).(" RNR%u%c",(i >> 5) & 7,j); |
| 201 | break; |
| 202 | case 0x9: |
| 203 | printfcxx . . $ printf(581fddd72a8db8fc).(" REJ%u%c",(i >> 5) & 7,j); |
| 204 | break; |
| 205 | default: |
| 206 | printfcxx . . $ printf(581fddd72a8db8fc).(" unknown S (0x%x)%u%c", i & 0xf, |
| 207 | (i >> 5) & 7, j); |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | if (!len) { |
| 212 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 213 | return; |
| 214 | } |
| 215 | printfcxx . . $ printf(581fddd72a8db8fc).(" pid=%02X\n", *bp++); |
| 216 | len--; |
| 217 | j = 0; |
| 218 | while (len) { |
| 219 | i = *bp++; |
| 220 | if ((i >= 32) && (i < 128)) |
| 221 | printfcxx . . $ printf(581fddd72a8db8fc).("%c",i); |
| 222 | else if (i == 13) { |
| 223 | if (j) |
| 224 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 225 | j = 0; |
| 226 | } else |
| 227 | printfcxx . . $ printf(581fddd72a8db8fc).("."); |
| 228 | if (i >= 32) |
| 229 | j = 1; |
| 230 | len--; |
| 231 | } |
| 232 | if (j) |
| 233 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 234 | } |
| 235 | |
| 236 | /* ---------------------------------------------------------------------- */ |
| 237 | |
| 238 | static void restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).(int signum) |
| 239 | { |
| 240 | if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(fdifcxx . . $ fdif., SIOCSIFFLAGScxx . . $ `<external>/13324550044150506404/sockios.h:61:9`!, &ifrcxx . . $ ifr.) < 0) |
| 241 | diecxx . . $ die(fda57c8427c60377).("ioctl SIOCSIFFLAGS"); |
| 242 | closecxx . . $ close(7864480464b09eea).(fdifcxx . . $ fdif.); |
| 243 | closecxx . . $ close(7864480464b09eea).(fdptycxx . . $ fdpty.); |
| 244 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 245 | } |
| 246 | |
| 247 | /* --------------------------------------------------------------------- */ |
| 248 | |
| 249 | #define KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`! ((unsigned char)0300) |
| 250 | #define KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`! ((unsigned char)0333) |
| 251 | #define KISS_TFENDcxx . . $ `kiss/net2kiss.c:251:9`! ((unsigned char)0334) |
| 252 | #define KISS_TFESCcxx . . $ `kiss/net2kiss.c:252:9`! ((unsigned char)0335) |
| 253 | |
| 254 | #define KISS_CMD_DATAcxx . . $ `kiss/net2kiss.c:254:9`! 0 |
| 255 | #define KISS_CMD_TXDELAYcxx . . $ `kiss/net2kiss.c:255:9`! 1 |
| 256 | #define KISS_CMD_PPERSISTcxx . . $ `kiss/net2kiss.c:256:9`! 2 |
| 257 | #define KISS_CMD_SLOTTIMEcxx . . $ `kiss/net2kiss.c:257:9`! 3 |
| 258 | #define KISS_CMD_TXTAILcxx . . $ `kiss/net2kiss.c:258:9`! 4 |
| 259 | #define KISS_CMD_FULLDUPcxx . . $ `kiss/net2kiss.c:259:9`! 5 |
| 260 | |
| 261 | #define KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`! 0 |
| 262 | #define KISS_RXcxx . . $ `kiss/net2kiss.c:262:9`! 1 |
| 263 | #define KISS_ESCAPEDcxx . . $ `kiss/net2kiss.c:263:9`! 2 |
| 264 | |
| 265 | /* --------------------------------------------------------------------- */ |
| 266 | |
| 267 | static void kiss_overflowcxx . . $ kiss_overflow(49f6e7a06ebc5aa8).(void) |
| 268 | { |
| 269 | if (verbosecxx . . $ verbose.) |
| 270 | printfcxx . . $ printf(581fddd72a8db8fc).("KISS: packet overflow\n"); |
| 271 | } |
| 272 | |
| 273 | static void kiss_bad_escapecxx . . $ kiss_bad_escape(49f6e7a06ebc5aa8).(void) |
| 274 | { |
| 275 | if (verbosecxx . . $ verbose.) |
| 276 | printfcxx . . $ printf(581fddd72a8db8fc).("KISS: bad escape sequence\n"); |
| 277 | } |
| 278 | |
| 279 | static void display_kiss_packetcxx . . $ display_kiss_packet(e9672921eb38367d).(char *pfx, unsigned char *pkt, |
| 280 | unsigned int pktlen) |
| 281 | { |
| 282 | if (!verbosecxx . . $ verbose.) |
| 283 | return; |
| 284 | switch (*pkt) { |
| 285 | case KISS_CMD_DATAcxx . . $ `kiss/net2kiss.c:254:9`!: |
| 286 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: ", pfx); |
| 287 | display_packetcxx . . $ display_packet(e1e8b00c42c42532).(pkt+1, pktlen-1); |
| 288 | break; |
| 289 | |
| 290 | case KISS_CMD_TXDELAYcxx . . $ `kiss/net2kiss.c:255:9`!: |
| 291 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: txdelay = %dms\n", pfx, (int)pkt[1] * 10); |
| 292 | break; |
| 293 | |
| 294 | case KISS_CMD_PPERSISTcxx . . $ `kiss/net2kiss.c:256:9`!: |
| 295 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: p persistence = %d\n", pfx, pkt[1]); |
| 296 | break; |
| 297 | |
| 298 | case KISS_CMD_SLOTTIMEcxx . . $ `kiss/net2kiss.c:257:9`!: |
| 299 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: slottime = %dms\n", pfx, (int)pkt[1] * 10); |
| 300 | break; |
| 301 | |
| 302 | case KISS_CMD_TXTAILcxx . . $ `kiss/net2kiss.c:258:9`!: |
| 303 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: txtail = %dms\n", pfx, (int)pkt[1] * 10); |
| 304 | break; |
| 305 | |
| 306 | case KISS_CMD_FULLDUPcxx . . $ `kiss/net2kiss.c:259:9`!: |
| 307 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: %sduplex\n", pfx, pkt[1] ? "full" : "half"); |
| 308 | break; |
| 309 | |
| 310 | default: |
| 311 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: unknown frame type 0x%02x, length %d\n", pfx, |
| 312 | *pkt, pktlen); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | static void kiss_packetcxx . . $ kiss_packet(6114369e11c68b96).(int fdif, char *addr, |
| 317 | unsigned char *pkt, unsigned int pktlen) |
| 318 | { |
| 319 | struct sockaddrcxx . . $ sockaddr# to; |
| 320 | int i; |
| 321 | |
| 322 | if (pktlen < 2) |
| 323 | return; |
| 324 | display_kiss_packetcxx . . $ display_kiss_packet(e9672921eb38367d).("KISS", pkt, pktlen); |
| 325 | strncpycxx . . $ strncpy(255158a415b673b0).(to.sa_datacxx . . $ sockaddr#sa_data., addr, sizeof(to.sa_datacxx . . $ sockaddr#sa_data.)); |
| 326 | i = sendtocxx . . $ sendto(efe9044f8eddf5c).(fdif, pkt, pktlen, 0, &to, sizeof(to)); |
| 327 | if (i >= 0) |
| 328 | return; |
| 329 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!) { |
| 330 | if (verbosecxx . . $ verbose.) |
| 331 | printfcxx . . $ printf(581fddd72a8db8fc).("sendto: %s: packet (size %d) too " |
| 332 | "long\n", addr, pktlen-1); |
| 333 | return; |
| 334 | } |
| 335 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EWOULDBLOCKcxx . . $ `<external>/17922322188510340118/errno.h:22:9`!) { |
| 336 | if (verbosecxx . . $ verbose.) |
| 337 | printfcxx . . $ printf(581fddd72a8db8fc).("sendto: %s: busy\n", addr); |
| 338 | return; |
| 339 | } |
| 340 | diecxx . . $ die(fda57c8427c60377).("sendto"); |
| 341 | } |
| 342 | |
| 343 | /* --------------------------------------------------------------------- */ |
| 344 | |
| 345 | static int doiocxx . . $ doio(56759362374d8228).(int fdif, int fdpty, char *ifaddr) |
| 346 | { |
| 347 | unsigned char ibuf[2048]; |
| 348 | unsigned char *bp; |
| 349 | unsigned char pktbuf[2048]; |
| 350 | unsigned char *pktptr = pktbuf; |
| 351 | unsigned char pktstate = KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`!; |
| 352 | unsigned char obuf[16384]; |
| 353 | unsigned int ob_wp = 0, ob_rp = 0, ob_wpx; |
| 354 | int i; |
| 355 | fd_setcxx . . $ fd_set# rmask, wmask; |
| 356 | struct sockaddrcxx . . $ sockaddr# from; |
| 357 | socklen_tcxx . . $ socklen_t# from_len; |
| 358 | |
| 359 | #define ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(c) \ |
| 360 | obuf[ob_wpx] = c; \ |
| 361 | ob_wpx = (ob_wpx + 1) % sizeof(obuf); \ |
| 362 | if (ob_wpx == ob_rp) goto kissencerr; |
| 363 | |
| 364 | #define ADD_KISSCHARcxx . . $ `kiss/net2kiss.c:364:9`!(c) \ |
| 365 | if (((c) & 0xff) == KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!) \ |
| 366 | { ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`!); ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_TFENDcxx . . $ `kiss/net2kiss.c:251:9`!); } \ |
| 367 | else if (((c) & 0xff) == KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`!) \ |
| 368 | { ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`!); ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_TFESCcxx . . $ `kiss/net2kiss.c:252:9`!); } \ |
| 369 | else { ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(c); } |
| 370 | |
| 371 | for (;;) { |
| 372 | FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&rmask); |
| 373 | FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&wmask); |
| 374 | FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(fdif, &rmask); |
| 375 | FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(fdpty, &rmask); |
| 376 | if (ob_rp != ob_wp) |
| 377 | FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(fdpty, &wmask); |
| 378 | i = selectcxx . . $ select(6d24c7514c8a5b88).((fdif > fdpty) ? fdif+1 : fdpty+1, &rmask, &wmask, |
| 379 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 380 | if (i < 0) |
| 381 | diecxx . . $ die(fda57c8427c60377).("select"); |
| 382 | if (FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(fdpty, &wmask)) { |
| 383 | if (ob_rp > ob_wp) |
| 384 | i = writecxx . . $ write(41184a59d38b4f65).(fdpty, obuf+ob_rp, |
| 385 | sizeof(obuf)-ob_rp); |
| 386 | else |
| 387 | i = writecxx . . $ write(41184a59d38b4f65).(fdpty, obuf+ob_rp, ob_wp - ob_rp); |
| 388 | if (i < 0) |
| 389 | diecxx . . $ die(fda57c8427c60377).("write"); |
| 390 | ob_rp = (ob_rp + i) % sizeof(obuf); |
| 391 | } |
| 392 | if (FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(fdpty, &rmask)) { |
| 393 | i = readcxx . . $ read(7e34d0a36f355389).(fdpty, bp = ibuf, sizeof(ibuf)); |
| 394 | if (i < 0) { |
| 395 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!) |
| 396 | diecxx . . $ die(fda57c8427c60377).("read"); |
| 397 | return 0; |
| 398 | } |
| 399 | for (; i > 0; i--, bp++) { |
| 400 | switch (pktstate) { |
| 401 | default: |
| 402 | case KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`!: |
| 403 | if (*bp != KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!) |
| 404 | break; |
| 405 | pktptr = pktbuf; |
| 406 | pktstate = KISS_RXcxx . . $ `kiss/net2kiss.c:262:9`!; |
| 407 | break; |
| 408 | |
| 409 | case KISS_RXcxx . . $ `kiss/net2kiss.c:262:9`!: |
| 410 | if (*bp == KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`!) { |
| 411 | pktstate = KISS_ESCAPEDcxx . . $ `kiss/net2kiss.c:263:9`!; |
| 412 | break; |
| 413 | } |
| 414 | if (*bp == KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!) { |
| 415 | kiss_packetcxx . . $ kiss_packet(6114369e11c68b96).(fdif, ifaddr, |
| 416 | pktbuf, |
| 417 | pktptr - pktbuf); |
| 418 | pktptr = pktbuf; |
| 419 | break; |
| 420 | } |
| 421 | if (pktptr >= pktbuf+sizeof(pktbuf)) { |
| 422 | kiss_overflowcxx . . $ kiss_overflow(49f6e7a06ebc5aa8).(); |
| 423 | pktstate = KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`!; |
| 424 | break; |
| 425 | } |
| 426 | *pktptr++ = *bp; |
| 427 | break; |
| 428 | |
| 429 | case KISS_ESCAPEDcxx . . $ `kiss/net2kiss.c:263:9`!: |
| 430 | if (pktptr >= pktbuf+sizeof(pktbuf)) { |
| 431 | kiss_overflowcxx . . $ kiss_overflow(49f6e7a06ebc5aa8).(); |
| 432 | pktstate = KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`!; |
| 433 | break; |
| 434 | } |
| 435 | if (*bp == KISS_TFESCcxx . . $ `kiss/net2kiss.c:252:9`!) |
| 436 | *pktptr++ = KISS_FESCcxx . . $ `kiss/net2kiss.c:250:9`!; |
| 437 | else if (*bp == KISS_TFENDcxx . . $ `kiss/net2kiss.c:251:9`!) |
| 438 | *pktptr++ = KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!; |
| 439 | else { |
| 440 | kiss_bad_escapecxx . . $ kiss_bad_escape(49f6e7a06ebc5aa8).(); |
| 441 | pktstate = KISS_HUNTcxx . . $ `kiss/net2kiss.c:261:9`!; |
| 442 | break; |
| 443 | } |
| 444 | pktstate = KISS_RXcxx . . $ `kiss/net2kiss.c:262:9`!; |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | if (FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(fdif, &rmask)) { |
| 450 | from_len = sizeof(from); |
| 451 | i = recvfromcxx . . $ recvfrom(67874f2c95950c9a).(fdif, bp = ibuf, sizeof(ibuf), 0, &from, |
| 452 | &from_len); |
| 453 | if (i < 0) { |
| 454 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EWOULDBLOCKcxx . . $ `<external>/17922322188510340118/errno.h:22:9`!) |
| 455 | continue; |
| 456 | diecxx . . $ die(fda57c8427c60377).("recvfrom"); |
| 457 | } |
| 458 | if (verbosecxx . . $ verbose.) |
| 459 | display_kiss_packetcxx . . $ display_kiss_packet(e9672921eb38367d).(from.sa_datacxx . . $ sockaddr#sa_data., ibuf, i); |
| 460 | ob_wpx = ob_wp; |
| 461 | ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!); |
| 462 | for (; i > 0; i--, bp++) { |
| 463 | ADD_KISSCHARcxx . . $ `kiss/net2kiss.c:364:9`!(*bp); |
| 464 | } |
| 465 | ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`!(KISS_FENDcxx . . $ `kiss/net2kiss.c:249:9`!); |
| 466 | ob_wp = ob_wpx; |
| 467 | } |
| 468 | continue; |
| 469 | kissencerr: |
| 470 | if (verbosecxx . . $ verbose.) |
| 471 | printfcxx . . $ printf(581fddd72a8db8fc).("KISS: Encoder out of memory\n"); |
| 472 | } |
| 473 | #undef ADD_CHARcxx . . $ `kiss/net2kiss.c:359:9`! |
| 474 | #undef ADD_KISSCHARcxx . . $ `kiss/net2kiss.c:364:9`! |
| 475 | } |
| 476 | |
| 477 | /* --------------------------------------------------------------------- */ |
| 478 | |
| 479 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 480 | { |
| 481 | struct ifreqcxx . . $ ifreq# ifr_new; |
| 482 | struct sockaddrcxx . . $ sockaddr# sa; |
| 483 | char *name_iface = "bc0"; |
| 484 | char *name_pname = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 485 | char slavename[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 486 | char *master_name; |
| 487 | struct termioscxx . . $ termios# termios; |
| 488 | int c; |
| 489 | int errflg = 0; |
| 490 | int symlnk = 0; |
| 491 | int symlnkforce = 0; |
| 492 | short if_newflags = 0; |
| 493 | int proto = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(ETH_P_AX25cxx . . $ `<external>/15209105680615352250/if_ether.h:135:9`!); |
| 494 | |
| 495 | prognamecxx . . $ progname. = argv[0]; |
| 496 | while ((c = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "sfzvai:")) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!) { |
| 497 | switch (c) { |
| 498 | case 's': |
| 499 | symlnk = 1; |
| 500 | break; |
| 501 | case 'f': |
| 502 | symlnkforce = 1; |
| 503 | break; |
| 504 | case 'i': |
| 505 | name_iface = optargcxx . . $ optarg.; |
| 506 | break; |
| 507 | case 'z': |
| 508 | if_newflags |= IFF_PROMISCcxx . . $ `<external>/2638090476884991293/if.h:61:10`!; |
| 509 | break; |
| 510 | case 'v': |
| 511 | verbosecxx . . $ verbose.++; |
| 512 | break; |
| 513 | case 'a': |
| 514 | proto = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(ETH_P_ALLcxx . . $ `<external>/15209105680615352250/if_ether.h:136:9`!); |
| 515 | break; |
| 516 | default: |
| 517 | errflg++; |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | if (argc > optindcxx . . $ optind.) |
| 522 | name_pname = argv[optindcxx . . $ optind.]; |
| 523 | else |
| 524 | errflg++; |
| 525 | if (errflg) { |
| 526 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-s] [-f] [-i iface] " |
| 527 | "[-z] [-v] ptyname\n", prognamecxx . . $ progname.); |
| 528 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 529 | } |
| 530 | openlogcxx . . $ openlog(7b85637613228108).(prognamecxx . . $ progname., LOG_PIDcxx . . $ `<external>/6168640806541382331/syslog.h:162:9`!, LOG_DAEMONcxx . . $ `<external>/6168640806541382331/syslog.h:96:9`!); |
| 531 | if (symlnk) { |
| 532 | int fdtty; |
| 533 | |
| 534 | if (openptycxx . . $ openpty(2250f1ea2c27406e).(&fdptycxx . . $ fdpty., &fdtty, slavename, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) { |
| 535 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: out of pseudoterminals\n", |
| 536 | prognamecxx . . $ progname.); |
| 537 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 538 | } |
| 539 | closecxx . . $ close(7864480464b09eea).(fdtty); |
| 540 | fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fdptycxx . . $ fdpty., F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fdptycxx . . $ fdpty., F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0) | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 541 | if (symlnkforce) |
| 542 | unlinkcxx . . $ unlink(5c4306d8553b3696).(name_pname); |
| 543 | if (symlinkcxx . . $ symlink(5ae29d726ae57f88).(slavename, name_pname)) |
| 544 | perrorcxx . . $ perror(85c52e162fed56f9).("symlink"); |
| 545 | /* Users await the slave pty to be referenced in the 2nd line */ |
| 546 | printfcxx . . $ printf(581fddd72a8db8fc).("Awaiting client connects on\n%s\n", slavename); |
| 547 | slavename[5] = 'p'; |
| 548 | master_name = slavename; |
| 549 | } else { |
| 550 | fdptycxx . . $ fdpty. = opencxx . . $ open(e156e3aa1e5c4ad1).(name_pname, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_NOCTTYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:53:10`! | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 551 | if (fdptycxx . . $ fdpty. < 0) { |
| 552 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: cannot open \"%s\"\n", prognamecxx . . $ progname., |
| 553 | name_pname); |
| 554 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 555 | } |
| 556 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).("/dev/ptmx", name_pname)) |
| 557 | i_am_unix98_pty_mastercxx . . $ i_am_unix98_pty_master. = 1; |
| 558 | master_name = name_pname; |
| 559 | } |
| 560 | fdifcxx . . $ fdif. = socketcxx . . $ socket(2326284602b0bb2d).(PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!, SOCK_PACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:44:9`!, proto); |
| 561 | if (fdifcxx . . $ fdif. < 0) |
| 562 | diecxx . . $ die(fda57c8427c60377).("socket"); |
| 563 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&sa, 0, sizeof(struct sockaddrcxx . . $ sockaddr#)); |
| 564 | memcpycxx . . $ memcpy(cc817cb175f282d).(sa.sa_datacxx . . $ sockaddr#sa_data., name_iface, sizeof(sa.sa_datacxx . . $ sockaddr#sa_data.)); |
| 565 | sa.sa_familycxx . . $ sockaddr#sa_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 566 | if (bindcxx . . $ bind(f39c6c650450bfdd).(fdifcxx . . $ fdif., &sa, sizeof(struct sockaddrcxx . . $ sockaddr#)) < 0) |
| 567 | diecxx . . $ die(fda57c8427c60377).("bind"); |
| 568 | memcpycxx . . $ memcpy(cc817cb175f282d).(ifrcxx . . $ ifr..ifr_namecxx . . $ `<external>/2638090476884991293/if.h:151:10`!, name_iface, IFNAMSIZcxx . . $ `<external>/2638090476884991293/if.h:129:10`!); |
| 569 | if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(fdifcxx . . $ fdif., SIOCGIFFLAGScxx . . $ `<external>/13324550044150506404/sockios.h:60:9`!, &ifrcxx . . $ ifr.) < 0) |
| 570 | diecxx . . $ die(fda57c8427c60377).("ioctl SIOCGIFFLAGS"); |
| 571 | ifr_new = ifrcxx . . $ ifr.; |
| 572 | ifr_new.ifr_flagscxx . . $ `<external>/2638090476884991293/if.h:157:10`! |= if_newflags; |
| 573 | if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(fdifcxx . . $ fdif., SIOCSIFFLAGScxx . . $ `<external>/13324550044150506404/sockios.h:61:9`!, &ifr_new) < 0) |
| 574 | diecxx . . $ die(fda57c8427c60377).("ioctl SIOCSIFFLAGS"); |
| 575 | if (i_am_unix98_pty_mastercxx . . $ i_am_unix98_pty_master.) { |
| 576 | /* get name of pts-device */ |
| 577 | nameptscxx . . $ namepts. = ptsnamecxx . . $ ptsname(ff224f080444ee45).(fdptycxx . . $ fdpty.); |
| 578 | if (nameptscxx . . $ namepts. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 579 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Cannot get name of pts-device.\n", prognamecxx . . $ progname.); |
| 580 | exitcxx . . $ exit(3ca292c338df9bb3). (1); |
| 581 | } |
| 582 | /* unlock pts-device */ |
| 583 | if (unlockptcxx . . $ unlockpt(7864480464b09eea).(fdptycxx . . $ fdpty.) == -1) { |
| 584 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Cannot unlock pts-device %s\n", prognamecxx . . $ progname., nameptscxx . . $ namepts.); |
| 585 | exitcxx . . $ exit(3ca292c338df9bb3). (1); |
| 586 | } |
| 587 | /* Users await the slave pty to be referenced in the 2nd line */ |
| 588 | printfcxx . . $ printf(581fddd72a8db8fc).("Awaiting client connects on\n%s\n", nameptscxx . . $ namepts.); |
| 589 | if (!verbosecxx . . $ verbose.) { |
| 590 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 591 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 592 | closecxx . . $ close(7864480464b09eea).(0); |
| 593 | closecxx . . $ close(7864480464b09eea).(1); |
| 594 | closecxx . . $ close(7864480464b09eea).(2); |
| 595 | } |
| 596 | } |
| 597 | signalcxx . . $ signal(c2d516773f91faf8).(SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 598 | signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 599 | signalcxx . . $ signal(c2d516773f91faf8).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 600 | signalcxx . . $ signal(c2d516773f91faf8).(SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 601 | signalcxx . . $ signal(c2d516773f91faf8).(SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 602 | signalcxx . . $ signal(c2d516773f91faf8).(SIGUSR2cxx . . $ `<external>/1457673850468744829/signum-arch.h:50:9`!, restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).); |
| 603 | |
| 604 | for (;;) { |
| 605 | if (tcgetattrcxx . . $ tcgetattr(7da5892ac34fc53f).(fdptycxx . . $ fdpty., &termios)) |
| 606 | diecxx . . $ die(fda57c8427c60377).("tcgetattr"); |
| 607 | termios.c_iflagcxx . . $ termios#c_iflag. = IGNBRKcxx . . $ `<external>/8770703639284775376/termios-c_iflag.h:24:9`!; |
| 608 | termios.c_oflagcxx . . $ termios#c_oflag. = 0; |
| 609 | termios.c_lflagcxx . . $ termios#c_lflag. = 0; |
| 610 | termios.c_cflagcxx . . $ termios#c_cflag. &= ~(CSIZEcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:24:9`!|CSTOPBcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:29:9`!|PARENBcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:31:9`!|HUPCLcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:33:9`!|CRTSCTScxx . . $ `<external>/934398879100599903/termios-c_cflag.h:39:10`!); |
| 611 | termios.c_cflagcxx . . $ termios#c_cflag. |= CS8cxx . . $ `<external>/934398879100599903/termios-c_cflag.h:28:11`!|CREADcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:30:9`!|CLOCALcxx . . $ `<external>/934398879100599903/termios-c_cflag.h:34:9`!; |
| 612 | if (tcsetattrcxx . . $ tcsetattr(4c59c899411d127a).(fdptycxx . . $ fdpty., TCSANOWcxx . . $ `<external>/7740429199341890421/termios-tcflow.h:24:9`!, &termios)) |
| 613 | diecxx . . $ die(fda57c8427c60377).("tsgetattr"); |
| 614 | if (doiocxx . . $ doio(56759362374d8228).(fdifcxx . . $ fdif., fdptycxx . . $ fdpty., name_iface)) |
| 615 | break; |
| 616 | if (i_am_unix98_pty_mastercxx . . $ i_am_unix98_pty_master.) { |
| 617 | if (verbosecxx . . $ verbose.) |
| 618 | printfcxx . . $ printf(581fddd72a8db8fc).("%s: Trying to poll port ptmx (slave %s).\nWaiting 30s...\n", prognamecxx . . $ progname., nameptscxx . . $ namepts.); |
| 619 | syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "Trying to poll port ptmx (slave %s). Waiting 30s...\n", nameptscxx . . $ namepts.); |
| 620 | sleepcxx . . $ sleep(2141b656ce2cc063).(30); |
| 621 | } else { |
| 622 | /* |
| 623 | * try to reopen master |
| 624 | */ |
| 625 | if (verbosecxx . . $ verbose.) |
| 626 | printfcxx . . $ printf(581fddd72a8db8fc).("reopening master tty: %s\n", master_name); |
| 627 | closecxx . . $ close(7864480464b09eea).(fdptycxx . . $ fdpty.); |
| 628 | |
| 629 | fdptycxx . . $ fdpty. = opencxx . . $ open(e156e3aa1e5c4ad1).(master_name, |
| 630 | O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_NOCTTYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:53:10`! | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 631 | if (fdptycxx . . $ fdpty. < 0) { |
| 632 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: cannot reopen \"%s\"\n", prognamecxx . . $ progname., |
| 633 | master_name); |
| 634 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | restore_ifflagscxx . . $ restore_ifflags(d4f767463ce0a6b3).(0); |
| 640 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 641 | } |
| 642 | |
| 643 | /* --------------------------------------------------------------------- */ |