| 1 | #include "EXTERN.h" |
| 2 | #include "perl.h" |
| 3 | #include "XSUB.h" |
| 4 | |
| 5 | #include <sys/socket.h> |
| 6 | |
| 7 | #ifndef AF_NBS |
| 8 | #undef PF_NBS |
| 9 | #endif |
| 10 | |
| 11 | #ifndef AF_X25 |
| 12 | #undef PF_X25 |
| 13 | #endif |
| 14 | |
| 15 | static int |
| 16 | not_here(s) |
| 17 | char *s; |
| 18 | { |
| 19 | croak("Socket::%s not implemented on this architecture", s); |
| 20 | return -1; |
| 21 | } |
| 22 | |
| 23 | static double |
| 24 | constant(name, arg) |
| 25 | char *name; |
| 26 | int arg; |
| 27 | { |
| 28 | errno = 0; |
| 29 | switch (*name) { |
| 30 | case 'A': |
| 31 | if (strEQ(name, "AF_802")) |
| 32 | #ifdef AF_802 |
| 33 | return AF_802; |
| 34 | #else |
| 35 | goto not_there; |
| 36 | #endif |
| 37 | if (strEQ(name, "AF_APPLETALK")) |
| 38 | #ifdef AF_APPLETALK |
| 39 | return AF_APPLETALK; |
| 40 | #else |
| 41 | goto not_there; |
| 42 | #endif |
| 43 | if (strEQ(name, "AF_CCITT")) |
| 44 | #ifdef AF_CCITT |
| 45 | return AF_CCITT; |
| 46 | #else |
| 47 | goto not_there; |
| 48 | #endif |
| 49 | if (strEQ(name, "AF_CHAOS")) |
| 50 | #ifdef AF_CHAOS |
| 51 | return AF_CHAOS; |
| 52 | #else |
| 53 | goto not_there; |
| 54 | #endif |
| 55 | if (strEQ(name, "AF_DATAKIT")) |
| 56 | #ifdef AF_DATAKIT |
| 57 | return AF_DATAKIT; |
| 58 | #else |
| 59 | goto not_there; |
| 60 | #endif |
| 61 | if (strEQ(name, "AF_DECnet")) |
| 62 | #ifdef AF_DECnet |
| 63 | return AF_DECnet; |
| 64 | #else |
| 65 | goto not_there; |
| 66 | #endif |
| 67 | if (strEQ(name, "AF_DLI")) |
| 68 | #ifdef AF_DLI |
| 69 | return AF_DLI; |
| 70 | #else |
| 71 | goto not_there; |
| 72 | #endif |
| 73 | if (strEQ(name, "AF_ECMA")) |
| 74 | #ifdef AF_ECMA |
| 75 | return AF_ECMA; |
| 76 | #else |
| 77 | goto not_there; |
| 78 | #endif |
| 79 | if (strEQ(name, "AF_GOSIP")) |
| 80 | #ifdef AF_GOSIP |
| 81 | return AF_GOSIP; |
| 82 | #else |
| 83 | goto not_there; |
| 84 | #endif |
| 85 | if (strEQ(name, "AF_HYLINK")) |
| 86 | #ifdef AF_HYLINK |
| 87 | return AF_HYLINK; |
| 88 | #else |
| 89 | goto not_there; |
| 90 | #endif |
| 91 | if (strEQ(name, "AF_IMPLINK")) |
| 92 | #ifdef AF_IMPLINK |
| 93 | return AF_IMPLINK; |
| 94 | #else |
| 95 | goto not_there; |
| 96 | #endif |
| 97 | if (strEQ(name, "AF_INET")) |
| 98 | #ifdef AF_INET |
| 99 | return AF_INET; |
| 100 | #else |
| 101 | goto not_there; |
| 102 | #endif |
| 103 | if (strEQ(name, "AF_LAT")) |
| 104 | #ifdef AF_LAT |
| 105 | return AF_LAT; |
| 106 | #else |
| 107 | goto not_there; |
| 108 | #endif |
| 109 | if (strEQ(name, "AF_MAX")) |
| 110 | #ifdef AF_MAX |
| 111 | return AF_MAX; |
| 112 | #else |
| 113 | goto not_there; |
| 114 | #endif |
| 115 | if (strEQ(name, "AF_NBS")) |
| 116 | #ifdef AF_NBS |
| 117 | return AF_NBS; |
| 118 | #else |
| 119 | goto not_there; |
| 120 | #endif |
| 121 | if (strEQ(name, "AF_NIT")) |
| 122 | #ifdef AF_NIT |
| 123 | return AF_NIT; |
| 124 | #else |
| 125 | goto not_there; |
| 126 | #endif |
| 127 | if (strEQ(name, "AF_NS")) |
| 128 | #ifdef AF_NS |
| 129 | return AF_NS; |
| 130 | #else |
| 131 | goto not_there; |
| 132 | #endif |
| 133 | if (strEQ(name, "AF_OSI")) |
| 134 | #ifdef AF_OSI |
| 135 | return AF_OSI; |
| 136 | #else |
| 137 | goto not_there; |
| 138 | #endif |
| 139 | if (strEQ(name, "AF_OSINET")) |
| 140 | #ifdef AF_OSINET |
| 141 | return AF_OSINET; |
| 142 | #else |
| 143 | goto not_there; |
| 144 | #endif |
| 145 | if (strEQ(name, "AF_PUP")) |
| 146 | #ifdef AF_PUP |
| 147 | return AF_PUP; |
| 148 | #else |
| 149 | goto not_there; |
| 150 | #endif |
| 151 | if (strEQ(name, "AF_SNA")) |
| 152 | #ifdef AF_SNA |
| 153 | return AF_SNA; |
| 154 | #else |
| 155 | goto not_there; |
| 156 | #endif |
| 157 | if (strEQ(name, "AF_UNIX")) |
| 158 | #ifdef AF_UNIX |
| 159 | return AF_UNIX; |
| 160 | #else |
| 161 | goto not_there; |
| 162 | #endif |
| 163 | if (strEQ(name, "AF_UNSPEC")) |
| 164 | #ifdef AF_UNSPEC |
| 165 | return AF_UNSPEC; |
| 166 | #else |
| 167 | goto not_there; |
| 168 | #endif |
| 169 | if (strEQ(name, "AF_X25")) |
| 170 | #ifdef AF_X25 |
| 171 | return AF_X25; |
| 172 | #else |
| 173 | goto not_there; |
| 174 | #endif |
| 175 | break; |
| 176 | case 'B': |
| 177 | break; |
| 178 | case 'C': |
| 179 | break; |
| 180 | case 'D': |
| 181 | break; |
| 182 | case 'E': |
| 183 | break; |
| 184 | case 'F': |
| 185 | break; |
| 186 | case 'G': |
| 187 | break; |
| 188 | case 'H': |
| 189 | break; |
| 190 | case 'I': |
| 191 | break; |
| 192 | case 'J': |
| 193 | break; |
| 194 | case 'K': |
| 195 | break; |
| 196 | case 'L': |
| 197 | break; |
| 198 | case 'M': |
| 199 | if (strEQ(name, "MSG_DONTROUTE")) |
| 200 | #ifdef MSG_DONTROUTE |
| 201 | return MSG_DONTROUTE; |
| 202 | #else |
| 203 | goto not_there; |
| 204 | #endif |
| 205 | if (strEQ(name, "MSG_MAXIOVLEN")) |
| 206 | #ifdef MSG_MAXIOVLEN |
| 207 | return MSG_MAXIOVLEN; |
| 208 | #else |
| 209 | goto not_there; |
| 210 | #endif |
| 211 | if (strEQ(name, "MSG_OOB")) |
| 212 | #ifdef MSG_OOB |
| 213 | return MSG_OOB; |
| 214 | #else |
| 215 | goto not_there; |
| 216 | #endif |
| 217 | if (strEQ(name, "MSG_PEEK")) |
| 218 | #ifdef MSG_PEEK |
| 219 | return MSG_PEEK; |
| 220 | #else |
| 221 | goto not_there; |
| 222 | #endif |
| 223 | break; |
| 224 | case 'N': |
| 225 | break; |
| 226 | case 'O': |
| 227 | break; |
| 228 | case 'P': |
| 229 | if (strEQ(name, "PF_802")) |
| 230 | #ifdef PF_802 |
| 231 | return PF_802; |
| 232 | #else |
| 233 | goto not_there; |
| 234 | #endif |
| 235 | if (strEQ(name, "PF_APPLETALK")) |
| 236 | #ifdef PF_APPLETALK |
| 237 | return PF_APPLETALK; |
| 238 | #else |
| 239 | goto not_there; |
| 240 | #endif |
| 241 | if (strEQ(name, "PF_CCITT")) |
| 242 | #ifdef PF_CCITT |
| 243 | return PF_CCITT; |
| 244 | #else |
| 245 | goto not_there; |
| 246 | #endif |
| 247 | if (strEQ(name, "PF_CHAOS")) |
| 248 | #ifdef PF_CHAOS |
| 249 | return PF_CHAOS; |
| 250 | #else |
| 251 | goto not_there; |
| 252 | #endif |
| 253 | if (strEQ(name, "PF_DATAKIT")) |
| 254 | #ifdef PF_DATAKIT |
| 255 | return PF_DATAKIT; |
| 256 | #else |
| 257 | goto not_there; |
| 258 | #endif |
| 259 | if (strEQ(name, "PF_DECnet")) |
| 260 | #ifdef PF_DECnet |
| 261 | return PF_DECnet; |
| 262 | #else |
| 263 | goto not_there; |
| 264 | #endif |
| 265 | if (strEQ(name, "PF_DLI")) |
| 266 | #ifdef PF_DLI |
| 267 | return PF_DLI; |
| 268 | #else |
| 269 | goto not_there; |
| 270 | #endif |
| 271 | if (strEQ(name, "PF_ECMA")) |
| 272 | #ifdef PF_ECMA |
| 273 | return PF_ECMA; |
| 274 | #else |
| 275 | goto not_there; |
| 276 | #endif |
| 277 | if (strEQ(name, "PF_GOSIP")) |
| 278 | #ifdef PF_GOSIP |
| 279 | return PF_GOSIP; |
| 280 | #else |
| 281 | goto not_there; |
| 282 | #endif |
| 283 | if (strEQ(name, "PF_HYLINK")) |
| 284 | #ifdef PF_HYLINK |
| 285 | return PF_HYLINK; |
| 286 | #else |
| 287 | goto not_there; |
| 288 | #endif |
| 289 | if (strEQ(name, "PF_IMPLINK")) |
| 290 | #ifdef PF_IMPLINK |
| 291 | return PF_IMPLINK; |
| 292 | #else |
| 293 | goto not_there; |
| 294 | #endif |
| 295 | if (strEQ(name, "PF_INET")) |
| 296 | #ifdef PF_INET |
| 297 | return PF_INET; |
| 298 | #else |
| 299 | goto not_there; |
| 300 | #endif |
| 301 | if (strEQ(name, "PF_LAT")) |
| 302 | #ifdef PF_LAT |
| 303 | return PF_LAT; |
| 304 | #else |
| 305 | goto not_there; |
| 306 | #endif |
| 307 | if (strEQ(name, "PF_MAX")) |
| 308 | #ifdef PF_MAX |
| 309 | return PF_MAX; |
| 310 | #else |
| 311 | goto not_there; |
| 312 | #endif |
| 313 | if (strEQ(name, "PF_NBS")) |
| 314 | #ifdef PF_NBS |
| 315 | return PF_NBS; |
| 316 | #else |
| 317 | goto not_there; |
| 318 | #endif |
| 319 | if (strEQ(name, "PF_NIT")) |
| 320 | #ifdef PF_NIT |
| 321 | return PF_NIT; |
| 322 | #else |
| 323 | goto not_there; |
| 324 | #endif |
| 325 | if (strEQ(name, "PF_NS")) |
| 326 | #ifdef PF_NS |
| 327 | return PF_NS; |
| 328 | #else |
| 329 | goto not_there; |
| 330 | #endif |
| 331 | if (strEQ(name, "PF_OSI")) |
| 332 | #ifdef PF_OSI |
| 333 | return PF_OSI; |
| 334 | #else |
| 335 | goto not_there; |
| 336 | #endif |
| 337 | if (strEQ(name, "PF_OSINET")) |
| 338 | #ifdef PF_OSINET |
| 339 | return PF_OSINET; |
| 340 | #else |
| 341 | goto not_there; |
| 342 | #endif |
| 343 | if (strEQ(name, "PF_PUP")) |
| 344 | #ifdef PF_PUP |
| 345 | return PF_PUP; |
| 346 | #else |
| 347 | goto not_there; |
| 348 | #endif |
| 349 | if (strEQ(name, "PF_SNA")) |
| 350 | #ifdef PF_SNA |
| 351 | return PF_SNA; |
| 352 | #else |
| 353 | goto not_there; |
| 354 | #endif |
| 355 | if (strEQ(name, "PF_UNIX")) |
| 356 | #ifdef PF_UNIX |
| 357 | return PF_UNIX; |
| 358 | #else |
| 359 | goto not_there; |
| 360 | #endif |
| 361 | if (strEQ(name, "PF_UNSPEC")) |
| 362 | #ifdef PF_UNSPEC |
| 363 | return PF_UNSPEC; |
| 364 | #else |
| 365 | goto not_there; |
| 366 | #endif |
| 367 | if (strEQ(name, "PF_X25")) |
| 368 | #ifdef PF_X25 |
| 369 | return PF_X25; |
| 370 | #else |
| 371 | goto not_there; |
| 372 | #endif |
| 373 | break; |
| 374 | case 'Q': |
| 375 | break; |
| 376 | case 'R': |
| 377 | break; |
| 378 | case 'S': |
| 379 | if (strEQ(name, "SOCK_DGRAM")) |
| 380 | #ifdef SOCK_DGRAM |
| 381 | return SOCK_DGRAM; |
| 382 | #else |
| 383 | goto not_there; |
| 384 | #endif |
| 385 | if (strEQ(name, "SOCK_RAW")) |
| 386 | #ifdef SOCK_RAW |
| 387 | return SOCK_RAW; |
| 388 | #else |
| 389 | goto not_there; |
| 390 | #endif |
| 391 | if (strEQ(name, "SOCK_RDM")) |
| 392 | #ifdef SOCK_RDM |
| 393 | return SOCK_RDM; |
| 394 | #else |
| 395 | goto not_there; |
| 396 | #endif |
| 397 | if (strEQ(name, "SOCK_SEQPACKET")) |
| 398 | #ifdef SOCK_SEQPACKET |
| 399 | return SOCK_SEQPACKET; |
| 400 | #else |
| 401 | goto not_there; |
| 402 | #endif |
| 403 | if (strEQ(name, "SOCK_STREAM")) |
| 404 | #ifdef SOCK_STREAM |
| 405 | return SOCK_STREAM; |
| 406 | #else |
| 407 | goto not_there; |
| 408 | #endif |
| 409 | if (strEQ(name, "SOL_SOCKET")) |
| 410 | #ifdef SOL_SOCKET |
| 411 | return SOL_SOCKET; |
| 412 | #else |
| 413 | goto not_there; |
| 414 | #endif |
| 415 | if (strEQ(name, "SOMAXCONN")) |
| 416 | #ifdef SOMAXCONN |
| 417 | return SOMAXCONN; |
| 418 | #else |
| 419 | goto not_there; |
| 420 | #endif |
| 421 | if (strEQ(name, "SO_ACCEPTCONN")) |
| 422 | #ifdef SO_ACCEPTCONN |
| 423 | return SO_ACCEPTCONN; |
| 424 | #else |
| 425 | goto not_there; |
| 426 | #endif |
| 427 | if (strEQ(name, "SO_BROADCAST")) |
| 428 | #ifdef SO_BROADCAST |
| 429 | return SO_BROADCAST; |
| 430 | #else |
| 431 | goto not_there; |
| 432 | #endif |
| 433 | if (strEQ(name, "SO_DEBUG")) |
| 434 | #ifdef SO_DEBUG |
| 435 | return SO_DEBUG; |
| 436 | #else |
| 437 | goto not_there; |
| 438 | #endif |
| 439 | if (strEQ(name, "SO_DONTLINGER")) |
| 440 | #ifdef SO_DONTLINGER |
| 441 | return SO_DONTLINGER; |
| 442 | #else |
| 443 | goto not_there; |
| 444 | #endif |
| 445 | if (strEQ(name, "SO_DONTROUTE")) |
| 446 | #ifdef SO_DONTROUTE |
| 447 | return SO_DONTROUTE; |
| 448 | #else |
| 449 | goto not_there; |
| 450 | #endif |
| 451 | if (strEQ(name, "SO_ERROR")) |
| 452 | #ifdef SO_ERROR |
| 453 | return SO_ERROR; |
| 454 | #else |
| 455 | goto not_there; |
| 456 | #endif |
| 457 | if (strEQ(name, "SO_KEEPALIVE")) |
| 458 | #ifdef SO_KEEPALIVE |
| 459 | return SO_KEEPALIVE; |
| 460 | #else |
| 461 | goto not_there; |
| 462 | #endif |
| 463 | if (strEQ(name, "SO_LINGER")) |
| 464 | #ifdef SO_LINGER |
| 465 | return SO_LINGER; |
| 466 | #else |
| 467 | goto not_there; |
| 468 | #endif |
| 469 | if (strEQ(name, "SO_OOBINLINE")) |
| 470 | #ifdef SO_OOBINLINE |
| 471 | return SO_OOBINLINE; |
| 472 | #else |
| 473 | goto not_there; |
| 474 | #endif |
| 475 | if (strEQ(name, "SO_RCVBUF")) |
| 476 | #ifdef SO_RCVBUF |
| 477 | return SO_RCVBUF; |
| 478 | #else |
| 479 | goto not_there; |
| 480 | #endif |
| 481 | if (strEQ(name, "SO_RCVLOWAT")) |
| 482 | #ifdef SO_RCVLOWAT |
| 483 | return SO_RCVLOWAT; |
| 484 | #else |
| 485 | goto not_there; |
| 486 | #endif |
| 487 | if (strEQ(name, "SO_RCVTIMEO")) |
| 488 | #ifdef SO_RCVTIMEO |
| 489 | return SO_RCVTIMEO; |
| 490 | #else |
| 491 | goto not_there; |
| 492 | #endif |
| 493 | if (strEQ(name, "SO_REUSEADDR")) |
| 494 | #ifdef SO_REUSEADDR |
| 495 | return SO_REUSEADDR; |
| 496 | #else |
| 497 | goto not_there; |
| 498 | #endif |
| 499 | if (strEQ(name, "SO_REUSEPORT")) |
| 500 | #ifdef SO_REUSEPORT |
| 501 | return SO_REUSEPORT; |
| 502 | #else |
| 503 | goto not_there; |
| 504 | #endif |
| 505 | if (strEQ(name, "SO_SNDBUF")) |
| 506 | #ifdef SO_SNDBUF |
| 507 | return SO_SNDBUF; |
| 508 | #else |
| 509 | goto not_there; |
| 510 | #endif |
| 511 | if (strEQ(name, "SO_SNDLOWAT")) |
| 512 | #ifdef SO_SNDLOWAT |
| 513 | return SO_SNDLOWAT; |
| 514 | #else |
| 515 | goto not_there; |
| 516 | #endif |
| 517 | if (strEQ(name, "SO_SNDTIMEO")) |
| 518 | #ifdef SO_SNDTIMEO |
| 519 | return SO_SNDTIMEO; |
| 520 | #else |
| 521 | goto not_there; |
| 522 | #endif |
| 523 | if (strEQ(name, "SO_TYPE")) |
| 524 | #ifdef SO_TYPE |
| 525 | return SO_TYPE; |
| 526 | #else |
| 527 | goto not_there; |
| 528 | #endif |
| 529 | if (strEQ(name, "SO_USELOOPBACK")) |
| 530 | #ifdef SO_USELOOPBACK |
| 531 | return SO_USELOOPBACK; |
| 532 | #else |
| 533 | goto not_there; |
| 534 | #endif |
| 535 | break; |
| 536 | case 'T': |
| 537 | break; |
| 538 | case 'U': |
| 539 | break; |
| 540 | case 'V': |
| 541 | break; |
| 542 | case 'W': |
| 543 | break; |
| 544 | case 'X': |
| 545 | break; |
| 546 | case 'Y': |
| 547 | break; |
| 548 | case 'Z': |
| 549 | break; |
| 550 | } |
| 551 | errno = EINVAL; |
| 552 | return 0; |
| 553 | |
| 554 | not_there: |
| 555 | errno = ENOENT; |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | MODULE = Socket PACKAGE = Socket |
| 560 | |
| 561 | double |
| 562 | constant(name,arg) |
| 563 | char * name |
| 564 | int arg |
| 565 | |