This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Raw integrate on mainline - MULTIPLICITY issues with Socket.xs
[perl5.git] / ext / Socket / Socket.xs
CommitLineData
c5be433b 1#define PERL_NO_GET_CONTEXT
a0d0e21e
LW
2#include "EXTERN.h"
3#include "perl.h"
4#include "XSUB.h"
5
8e07c86e
AD
6#ifndef VMS
7# ifdef I_SYS_TYPES
8# include <sys/types.h>
9# endif
9cc6feab 10# include <sys/socket.h>
29209bc5 11# if defined(USE_SOCKS) && defined(I_SOCKS)
86959918
JH
12# include <socks.h>
13# endif
9cc6feab
JH
14# ifdef MPE
15# define PF_INET AF_INET
16# define PF_UNIX AF_UNIX
17# define SOCK_RAW 3
18# endif
19# ifdef I_SYS_UN
20# include <sys/un.h>
21# endif
bf9b2f8f
JH
22/* XXX Configure test for <netinet/in_systm.h needed XXX */
23# if defined(NeXT) || defined(__NeXT__)
24# include <netinet/in_systm.h>
25# endif
8e07c86e
AD
26# ifdef I_NETINET_IN
27# include <netinet/in.h>
28# endif
86959918
JH
29# ifdef I_NETDB
30# include <netdb.h>
31# endif
9cc6feab
JH
32# ifdef I_ARPA_INET
33# include <arpa/inet.h>
34# endif
35# ifdef I_NETINET_TCP
36# include <netinet/tcp.h>
37# endif
8e07c86e 38#else
9cc6feab 39# include "sockadapt.h"
8e07c86e 40#endif
a0d0e21e 41
6b1016b5
JH
42#ifdef I_SYSUIO
43# include <sys/uio.h>
44#endif
45
a0d0e21e 46#ifndef AF_NBS
9cc6feab 47# undef PF_NBS
a0d0e21e
LW
48#endif
49
50#ifndef AF_X25
9cc6feab 51# undef PF_X25
a0d0e21e
LW
52#endif
53
8e07c86e 54#ifndef INADDR_NONE
9cc6feab 55# define INADDR_NONE 0xffffffff
8e07c86e 56#endif /* INADDR_NONE */
7e1af8bc 57#ifndef INADDR_BROADCAST
9cc6feab 58# define INADDR_BROADCAST 0xffffffff
7e1af8bc 59#endif /* INADDR_BROADCAST */
8e07c86e 60#ifndef INADDR_LOOPBACK
9cc6feab 61# define INADDR_LOOPBACK 0x7F000001
8e07c86e
AD
62#endif /* INADDR_LOOPBACK */
63
7e1af8bc
PP
64#ifndef HAS_INET_ATON
65
66/*
67 * Check whether "cp" is a valid ascii representation
68 * of an Internet address and convert to a binary address.
69 * Returns 1 if the address is valid, 0 if not.
70 * This replaces inet_addr, the return value from which
71 * cannot distinguish between failure and a local broadcast address.
72 */
73static int
f0f333f4 74my_inet_aton(register const char *cp, struct in_addr *addr)
7e1af8bc 75{
c5be433b 76 dTHX;
0caed002 77 register U32 val;
7e1af8bc
PP
78 register int base;
79 register char c;
80 int nparts;
81 const char *s;
82 unsigned int parts[4];
83 register unsigned int *pp = parts;
84
0caed002
CS
85 if (!cp)
86 return 0;
7e1af8bc
PP
87 for (;;) {
88 /*
89 * Collect number up to ``.''.
90 * Values are specified as for C:
91 * 0x=hex, 0=octal, other=decimal.
92 */
93 val = 0; base = 10;
94 if (*cp == '0') {
95 if (*++cp == 'x' || *cp == 'X')
96 base = 16, cp++;
97 else
98 base = 8;
99 }
100 while ((c = *cp) != '\0') {
101 if (isDIGIT(c)) {
102 val = (val * base) + (c - '0');
103 cp++;
104 continue;
105 }
3280af22 106 if (base == 16 && (s=strchr(PL_hexdigit,c))) {
7e1af8bc 107 val = (val << 4) +
3280af22 108 ((s - PL_hexdigit) & 15);
7e1af8bc
PP
109 cp++;
110 continue;
111 }
112 break;
113 }
114 if (*cp == '.') {
115 /*
116 * Internet format:
117 * a.b.c.d
118 * a.b.c (with c treated as 16-bits)
119 * a.b (with b treated as 24 bits)
120 */
121 if (pp >= parts + 3 || val > 0xff)
122 return 0;
123 *pp++ = val, cp++;
124 } else
125 break;
126 }
127 /*
128 * Check for trailing characters.
129 */
130 if (*cp && !isSPACE(*cp))
131 return 0;
132 /*
133 * Concoct the address according to
134 * the number of parts specified.
135 */
136 nparts = pp - parts + 1; /* force to an int for switch() */
137 switch (nparts) {
138
139 case 1: /* a -- 32 bits */
140 break;
141
142 case 2: /* a.b -- 8.24 bits */
143 if (val > 0xffffff)
144 return 0;
145 val |= parts[0] << 24;
146 break;
147
148 case 3: /* a.b.c -- 8.8.16 bits */
149 if (val > 0xffff)
150 return 0;
151 val |= (parts[0] << 24) | (parts[1] << 16);
152 break;
153
154 case 4: /* a.b.c.d -- 8.8.8.8 bits */
155 if (val > 0xff)
156 return 0;
157 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
158 break;
159 }
160 addr->s_addr = htonl(val);
161 return 1;
162}
163
164#undef inet_aton
165#define inet_aton my_inet_aton
166
167#endif /* ! HAS_INET_ATON */
168
8e07c86e 169
a0d0e21e 170static int
f0f333f4 171not_here(char *s)
a0d0e21e
LW
172{
173 croak("Socket::%s not implemented on this architecture", s);
174 return -1;
175}
176
18085af4
JH
177#define PERL_constant_NOTFOUND 1
178#define PERL_constant_NOTDEF 2
179#define PERL_constant_ISIV 3
cea00dc5
NC
180#define PERL_constant_ISNO 4
181#define PERL_constant_ISNV 5
182#define PERL_constant_ISPV 6
183#define PERL_constant_ISPVN 7
184#define PERL_constant_ISSV 8
185#define PERL_constant_ISUNDEF 9
186#define PERL_constant_ISUV 10
187#define PERL_constant_ISYES 11
18085af4
JH
188
189static int
cea00dc5 190constant_6 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
191 /* When generated this function returned values for the list of names given
192 here. However, subsequent manual editing may have added or removed some.
193 AF_802 AF_DLI AF_LAT AF_MAX AF_NBS AF_NIT AF_OSI AF_PUP AF_SNA AF_X25
194 PF_802 PF_DLI PF_LAT PF_MAX PF_NBS PF_NIT PF_OSI PF_PUP PF_SNA PF_X25 */
195 /* Offset 3 gives the best switch position. */
196 switch (name[3]) {
197 case '8':
198 if (memEQ(name, "AF_802", 6)) {
199 /* ^ */
a0d0e21e 200#ifdef AF_802
18085af4
JH
201 *iv_return = AF_802;
202 return PERL_constant_ISIV;
a0d0e21e 203#else
18085af4 204 return PERL_constant_NOTDEF;
a0d0e21e 205#endif
18085af4
JH
206 }
207 if (memEQ(name, "PF_802", 6)) {
208 /* ^ */
209#ifdef PF_802
210 *iv_return = PF_802;
211 return PERL_constant_ISIV;
a0d0e21e 212#else
18085af4 213 return PERL_constant_NOTDEF;
a0d0e21e 214#endif
18085af4
JH
215 }
216 break;
217 case 'D':
218 if (memEQ(name, "AF_DLI", 6)) {
219 /* ^ */
220#ifdef AF_DLI
221 *iv_return = AF_DLI;
222 return PERL_constant_ISIV;
a0d0e21e 223#else
18085af4 224 return PERL_constant_NOTDEF;
a0d0e21e 225#endif
18085af4
JH
226 }
227 if (memEQ(name, "PF_DLI", 6)) {
228 /* ^ */
229#ifdef PF_DLI
230 *iv_return = PF_DLI;
231 return PERL_constant_ISIV;
a0d0e21e 232#else
18085af4 233 return PERL_constant_NOTDEF;
a0d0e21e 234#endif
18085af4
JH
235 }
236 break;
237 case 'L':
238 if (memEQ(name, "AF_LAT", 6)) {
239 /* ^ */
240#ifdef AF_LAT
241 *iv_return = AF_LAT;
242 return PERL_constant_ISIV;
a0d0e21e 243#else
18085af4 244 return PERL_constant_NOTDEF;
a0d0e21e 245#endif
18085af4
JH
246 }
247 if (memEQ(name, "PF_LAT", 6)) {
248 /* ^ */
249#ifdef PF_LAT
250 *iv_return = PF_LAT;
251 return PERL_constant_ISIV;
a0d0e21e 252#else
18085af4 253 return PERL_constant_NOTDEF;
a0d0e21e 254#endif
18085af4
JH
255 }
256 break;
257 case 'M':
258 if (memEQ(name, "AF_MAX", 6)) {
259 /* ^ */
260#ifdef AF_MAX
261 *iv_return = AF_MAX;
262 return PERL_constant_ISIV;
a0d0e21e 263#else
18085af4 264 return PERL_constant_NOTDEF;
a0d0e21e 265#endif
18085af4
JH
266 }
267 if (memEQ(name, "PF_MAX", 6)) {
268 /* ^ */
269#ifdef PF_MAX
270 *iv_return = PF_MAX;
271 return PERL_constant_ISIV;
a0d0e21e 272#else
18085af4 273 return PERL_constant_NOTDEF;
a0d0e21e 274#endif
18085af4
JH
275 }
276 break;
277 case 'N':
278 if (memEQ(name, "AF_NBS", 6)) {
279 /* ^ */
280#ifdef AF_NBS
281 *iv_return = AF_NBS;
282 return PERL_constant_ISIV;
a0d0e21e 283#else
18085af4 284 return PERL_constant_NOTDEF;
a0d0e21e 285#endif
18085af4
JH
286 }
287 if (memEQ(name, "AF_NIT", 6)) {
288 /* ^ */
289#ifdef AF_NIT
290 *iv_return = AF_NIT;
291 return PERL_constant_ISIV;
a0d0e21e 292#else
18085af4 293 return PERL_constant_NOTDEF;
a0d0e21e 294#endif
18085af4
JH
295 }
296 if (memEQ(name, "PF_NBS", 6)) {
297 /* ^ */
298#ifdef PF_NBS
299 *iv_return = PF_NBS;
300 return PERL_constant_ISIV;
a0d0e21e 301#else
18085af4 302 return PERL_constant_NOTDEF;
a0d0e21e 303#endif
18085af4
JH
304 }
305 if (memEQ(name, "PF_NIT", 6)) {
306 /* ^ */
307#ifdef PF_NIT
308 *iv_return = PF_NIT;
309 return PERL_constant_ISIV;
a0d0e21e 310#else
18085af4 311 return PERL_constant_NOTDEF;
a0d0e21e 312#endif
18085af4
JH
313 }
314 break;
315 case 'O':
316 if (memEQ(name, "AF_OSI", 6)) {
317 /* ^ */
318#ifdef AF_OSI
319 *iv_return = AF_OSI;
320 return PERL_constant_ISIV;
a0d0e21e 321#else
18085af4 322 return PERL_constant_NOTDEF;
a0d0e21e 323#endif
18085af4
JH
324 }
325 if (memEQ(name, "PF_OSI", 6)) {
326 /* ^ */
327#ifdef PF_OSI
328 *iv_return = PF_OSI;
329 return PERL_constant_ISIV;
a0d0e21e 330#else
18085af4 331 return PERL_constant_NOTDEF;
a0d0e21e 332#endif
18085af4
JH
333 }
334 break;
335 case 'P':
336 if (memEQ(name, "AF_PUP", 6)) {
337 /* ^ */
338#ifdef AF_PUP
339 *iv_return = AF_PUP;
340 return PERL_constant_ISIV;
a0d0e21e 341#else
18085af4 342 return PERL_constant_NOTDEF;
a0d0e21e 343#endif
18085af4
JH
344 }
345 if (memEQ(name, "PF_PUP", 6)) {
346 /* ^ */
347#ifdef PF_PUP
348 *iv_return = PF_PUP;
349 return PERL_constant_ISIV;
a0d0e21e 350#else
18085af4 351 return PERL_constant_NOTDEF;
a0d0e21e 352#endif
18085af4
JH
353 }
354 break;
355 case 'S':
356 if (memEQ(name, "AF_SNA", 6)) {
357 /* ^ */
358#ifdef AF_SNA
359 *iv_return = AF_SNA;
360 return PERL_constant_ISIV;
a0d0e21e 361#else
18085af4 362 return PERL_constant_NOTDEF;
a0d0e21e 363#endif
18085af4
JH
364 }
365 if (memEQ(name, "PF_SNA", 6)) {
366 /* ^ */
367#ifdef PF_SNA
368 *iv_return = PF_SNA;
369 return PERL_constant_ISIV;
a0d0e21e 370#else
18085af4 371 return PERL_constant_NOTDEF;
a0d0e21e 372#endif
18085af4
JH
373 }
374 break;
375 case 'X':
376 if (memEQ(name, "AF_X25", 6)) {
377 /* ^ */
378#ifdef AF_X25
379 *iv_return = AF_X25;
380 return PERL_constant_ISIV;
a0d0e21e 381#else
18085af4 382 return PERL_constant_NOTDEF;
a0d0e21e 383#endif
18085af4
JH
384 }
385 if (memEQ(name, "PF_X25", 6)) {
386 /* ^ */
387#ifdef PF_X25
388 *iv_return = PF_X25;
389 return PERL_constant_ISIV;
a0d0e21e 390#else
18085af4 391 return PERL_constant_NOTDEF;
a0d0e21e 392#endif
18085af4
JH
393 }
394 break;
395 }
396 return PERL_constant_NOTFOUND;
397}
398
399static int
cea00dc5 400constant_7 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
401 /* When generated this function returned values for the list of names given
402 here. However, subsequent manual editing may have added or removed some.
403 AF_ECMA AF_INET AF_UNIX IOV_MAX MSG_EOF MSG_EOR MSG_FIN MSG_OOB MSG_RST
404 MSG_SYN MSG_URG PF_ECMA PF_INET PF_UNIX SHUT_RD SHUT_WR SO_TYPE */
405 /* Offset 4 gives the best switch position. */
406 switch (name[4]) {
407 case 'C':
408 if (memEQ(name, "AF_ECMA", 7)) {
409 /* ^ */
410#ifdef AF_ECMA
411 *iv_return = AF_ECMA;
412 return PERL_constant_ISIV;
a0d0e21e 413#else
18085af4 414 return PERL_constant_NOTDEF;
a0d0e21e 415#endif
18085af4
JH
416 }
417 if (memEQ(name, "PF_ECMA", 7)) {
418 /* ^ */
419#ifdef PF_ECMA
420 *iv_return = PF_ECMA;
421 return PERL_constant_ISIV;
a0d0e21e 422#else
18085af4 423 return PERL_constant_NOTDEF;
a0d0e21e 424#endif
18085af4
JH
425 }
426 break;
427 case 'E':
428 if (memEQ(name, "MSG_EOF", 7)) {
429 /* ^ */
430#ifdef MSG_EOF
431 *iv_return = MSG_EOF;
432 return PERL_constant_ISIV;
a0d0e21e 433#else
18085af4 434 return PERL_constant_NOTDEF;
a0d0e21e 435#endif
18085af4
JH
436 }
437 if (memEQ(name, "MSG_EOR", 7)) {
438 /* ^ */
439#ifdef MSG_EOR
440 *iv_return = MSG_EOR;
441 return PERL_constant_ISIV;
6b1016b5 442#else
18085af4 443 return PERL_constant_NOTDEF;
6b1016b5 444#endif
18085af4
JH
445 }
446 break;
447 case 'F':
448 if (memEQ(name, "MSG_FIN", 7)) {
449 /* ^ */
450#ifdef MSG_FIN
451 *iv_return = MSG_FIN;
452 return PERL_constant_ISIV;
6b1016b5 453#else
18085af4 454 return PERL_constant_NOTDEF;
6b1016b5 455#endif
18085af4
JH
456 }
457 break;
458 case 'M':
459 if (memEQ(name, "IOV_MAX", 7)) {
460 /* ^ */
461#ifdef IOV_MAX
462 *iv_return = IOV_MAX;
463 return PERL_constant_ISIV;
de4597cb 464#else
18085af4 465 return PERL_constant_NOTDEF;
de4597cb 466#endif
18085af4
JH
467 }
468 break;
469 case 'N':
470 if (memEQ(name, "AF_INET", 7)) {
471 /* ^ */
472#ifdef AF_INET
473 *iv_return = AF_INET;
474 return PERL_constant_ISIV;
de4597cb 475#else
18085af4 476 return PERL_constant_NOTDEF;
de4597cb 477#endif
18085af4
JH
478 }
479 if (memEQ(name, "AF_UNIX", 7)) {
480 /* ^ */
481#ifdef AF_UNIX
482 *iv_return = AF_UNIX;
483 return PERL_constant_ISIV;
a1896f58 484#else
18085af4 485 return PERL_constant_NOTDEF;
a1896f58 486#endif
18085af4
JH
487 }
488 if (memEQ(name, "PF_INET", 7)) {
489 /* ^ */
490#ifdef PF_INET
491 *iv_return = PF_INET;
492 return PERL_constant_ISIV;
a0d0e21e 493#else
18085af4 494 return PERL_constant_NOTDEF;
a0d0e21e 495#endif
18085af4
JH
496 }
497 if (memEQ(name, "PF_UNIX", 7)) {
498 /* ^ */
499#ifdef PF_UNIX
500 *iv_return = PF_UNIX;
501 return PERL_constant_ISIV;
de4597cb 502#else
18085af4 503 return PERL_constant_NOTDEF;
de4597cb 504#endif
18085af4
JH
505 }
506 break;
507 case 'O':
508 if (memEQ(name, "MSG_OOB", 7)) {
cea00dc5 509 /* ^ */
18085af4
JH
510#if defined(MSG_OOB) || defined(HAS_MSG_OOB) /* might be an enum */
511 *iv_return = MSG_OOB;
512 return PERL_constant_ISIV;
de4597cb 513#else
18085af4 514 return PERL_constant_NOTDEF;
de4597cb 515#endif
18085af4
JH
516 }
517 break;
518 case 'R':
519 if (memEQ(name, "MSG_RST", 7)) {
520 /* ^ */
521#ifdef MSG_RST
522 *iv_return = MSG_RST;
523 return PERL_constant_ISIV;
de4597cb 524#else
18085af4 525 return PERL_constant_NOTDEF;
de4597cb 526#endif
18085af4
JH
527 }
528 break;
529 case 'S':
530 if (memEQ(name, "MSG_SYN", 7)) {
531 /* ^ */
532#ifdef MSG_SYN
533 *iv_return = MSG_SYN;
534 return PERL_constant_ISIV;
de4597cb 535#else
18085af4 536 return PERL_constant_NOTDEF;
de4597cb 537#endif
18085af4
JH
538 }
539 break;
540 case 'U':
541 if (memEQ(name, "MSG_URG", 7)) {
542 /* ^ */
543#ifdef MSG_URG
544 *iv_return = MSG_URG;
545 return PERL_constant_ISIV;
de4597cb 546#else
18085af4 547 return PERL_constant_NOTDEF;
de4597cb 548#endif
18085af4
JH
549 }
550 break;
551 case 'Y':
552 if (memEQ(name, "SO_TYPE", 7)) {
553 /* ^ */
554#ifdef SO_TYPE
555 *iv_return = SO_TYPE;
556 return PERL_constant_ISIV;
a0d0e21e 557#else
18085af4 558 return PERL_constant_NOTDEF;
a0d0e21e 559#endif
18085af4
JH
560 }
561 break;
562 case '_':
563 if (memEQ(name, "SHUT_RD", 7)) {
564 /* ^ */
565#ifdef SHUT_RD
566 *iv_return = SHUT_RD;
567 return PERL_constant_ISIV;
6b1016b5 568#else
18085af4
JH
569 *iv_return = 0;
570 return PERL_constant_ISIV;
6b1016b5 571#endif
18085af4
JH
572 }
573 if (memEQ(name, "SHUT_WR", 7)) {
574 /* ^ */
575#ifdef SHUT_WR
576 *iv_return = SHUT_WR;
577 return PERL_constant_ISIV;
de4597cb 578#else
18085af4
JH
579 *iv_return = 1;
580 return PERL_constant_ISIV;
de4597cb 581#endif
18085af4
JH
582 }
583 break;
584 }
585 return PERL_constant_NOTFOUND;
586}
587
588static int
cea00dc5 589constant_8 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
590 /* When generated this function returned values for the list of names given
591 here. However, subsequent manual editing may have added or removed some.
592 AF_CCITT AF_CHAOS AF_GOSIP MSG_PEEK PF_CCITT PF_CHAOS PF_GOSIP SOCK_RAW
593 SOCK_RDM SO_DEBUG SO_ERROR */
594 /* Offset 7 gives the best switch position. */
595 switch (name[7]) {
596 case 'G':
597 if (memEQ(name, "SO_DEBUG", 8)) {
598 /* ^ */
599#ifdef SO_DEBUG
600 *iv_return = SO_DEBUG;
601 return PERL_constant_ISIV;
a0d0e21e 602#else
18085af4 603 return PERL_constant_NOTDEF;
a0d0e21e 604#endif
18085af4
JH
605 }
606 break;
607 case 'K':
608 if (memEQ(name, "MSG_PEEK", 8)) {
609 /* ^ */
5b8dae3f 610#if defined(MSG_PEEK) || defined(HAS_MSG_PEEK) /* might be an enum */
18085af4
JH
611 *iv_return = MSG_PEEK;
612 return PERL_constant_ISIV;
a0d0e21e 613#else
18085af4 614 return PERL_constant_NOTDEF;
a0d0e21e 615#endif
18085af4
JH
616 }
617 break;
618 case 'M':
619 if (memEQ(name, "SOCK_RDM", 8)) {
620 /* ^ */
621#ifdef SOCK_RDM
622 *iv_return = SOCK_RDM;
623 return PERL_constant_ISIV;
a1896f58 624#else
18085af4 625 return PERL_constant_NOTDEF;
a1896f58 626#endif
18085af4
JH
627 }
628 break;
629 case 'P':
630 if (memEQ(name, "AF_GOSIP", 8)) {
631 /* ^ */
632#ifdef AF_GOSIP
633 *iv_return = AF_GOSIP;
634 return PERL_constant_ISIV;
de4597cb 635#else
18085af4 636 return PERL_constant_NOTDEF;
de4597cb 637#endif
18085af4
JH
638 }
639 if (memEQ(name, "PF_GOSIP", 8)) {
640 /* ^ */
641#ifdef PF_GOSIP
642 *iv_return = PF_GOSIP;
643 return PERL_constant_ISIV;
de4597cb 644#else
18085af4 645 return PERL_constant_NOTDEF;
de4597cb 646#endif
18085af4
JH
647 }
648 break;
649 case 'R':
650 if (memEQ(name, "SO_ERROR", 8)) {
651 /* ^ */
652#ifdef SO_ERROR
653 *iv_return = SO_ERROR;
654 return PERL_constant_ISIV;
de4597cb 655#else
18085af4 656 return PERL_constant_NOTDEF;
de4597cb 657#endif
18085af4
JH
658 }
659 break;
660 case 'S':
661 if (memEQ(name, "AF_CHAOS", 8)) {
662 /* ^ */
663#ifdef AF_CHAOS
664 *iv_return = AF_CHAOS;
665 return PERL_constant_ISIV;
de4597cb 666#else
18085af4 667 return PERL_constant_NOTDEF;
de4597cb 668#endif
18085af4
JH
669 }
670 if (memEQ(name, "PF_CHAOS", 8)) {
671 /* ^ */
672#ifdef PF_CHAOS
673 *iv_return = PF_CHAOS;
674 return PERL_constant_ISIV;
a0d0e21e 675#else
18085af4 676 return PERL_constant_NOTDEF;
a0d0e21e 677#endif
18085af4
JH
678 }
679 break;
680 case 'T':
681 if (memEQ(name, "AF_CCITT", 8)) {
682 /* ^ */
683#ifdef AF_CCITT
684 *iv_return = AF_CCITT;
685 return PERL_constant_ISIV;
a0d0e21e 686#else
18085af4 687 return PERL_constant_NOTDEF;
a0d0e21e 688#endif
18085af4
JH
689 }
690 if (memEQ(name, "PF_CCITT", 8)) {
691 /* ^ */
a0d0e21e 692#ifdef PF_CCITT
18085af4
JH
693 *iv_return = PF_CCITT;
694 return PERL_constant_ISIV;
a0d0e21e 695#else
18085af4 696 return PERL_constant_NOTDEF;
a0d0e21e 697#endif
18085af4
JH
698 }
699 break;
700 case 'W':
701 if (memEQ(name, "SOCK_RAW", 8)) {
702 /* ^ */
703#ifdef SOCK_RAW
704 *iv_return = SOCK_RAW;
705 return PERL_constant_ISIV;
a0d0e21e 706#else
18085af4 707 return PERL_constant_NOTDEF;
a0d0e21e 708#endif
18085af4
JH
709 }
710 break;
711 }
712 return PERL_constant_NOTFOUND;
713}
714
715static int
cea00dc5 716constant_9 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
717 /* When generated this function returned values for the list of names given
718 here. However, subsequent manual editing may have added or removed some.
719 AF_DECnet AF_HYLINK AF_OSINET AF_UNSPEC MSG_BCAST MSG_MCAST MSG_PROXY
720 MSG_TRUNC PF_DECnet PF_HYLINK PF_OSINET PF_UNSPEC SCM_CREDS SHUT_RDWR
721 SOMAXCONN SO_LINGER SO_RCVBUF SO_SNDBUF TCP_MAXRT */
722 /* Offset 6 gives the best switch position. */
723 switch (name[6]) {
724 case 'A':
725 if (memEQ(name, "MSG_BCAST", 9)) {
726 /* ^ */
727#ifdef MSG_BCAST
728 *iv_return = MSG_BCAST;
729 return PERL_constant_ISIV;
a0d0e21e 730#else
18085af4 731 return PERL_constant_NOTDEF;
a0d0e21e 732#endif
18085af4
JH
733 }
734 if (memEQ(name, "MSG_MCAST", 9)) {
735 /* ^ */
736#ifdef MSG_MCAST
737 *iv_return = MSG_MCAST;
738 return PERL_constant_ISIV;
a0d0e21e 739#else
18085af4 740 return PERL_constant_NOTDEF;
a0d0e21e 741#endif
18085af4
JH
742 }
743 break;
744 case 'B':
745 if (memEQ(name, "SO_RCVBUF", 9)) {
746 /* ^ */
747#ifdef SO_RCVBUF
748 *iv_return = SO_RCVBUF;
749 return PERL_constant_ISIV;
a0d0e21e 750#else
18085af4 751 return PERL_constant_NOTDEF;
a0d0e21e 752#endif
18085af4
JH
753 }
754 if (memEQ(name, "SO_SNDBUF", 9)) {
755 /* ^ */
756#ifdef SO_SNDBUF
757 *iv_return = SO_SNDBUF;
758 return PERL_constant_ISIV;
a0d0e21e 759#else
18085af4 760 return PERL_constant_NOTDEF;
a0d0e21e 761#endif
18085af4
JH
762 }
763 break;
764 case 'D':
765 if (memEQ(name, "SHUT_RDWR", 9)) {
766 /* ^ */
767#ifdef SHUT_RDWR
768 *iv_return = SHUT_RDWR;
769 return PERL_constant_ISIV;
a0d0e21e 770#else
18085af4
JH
771 *iv_return = 2;
772 return PERL_constant_ISIV;
a0d0e21e 773#endif
18085af4
JH
774 }
775 break;
776 case 'E':
777 if (memEQ(name, "SCM_CREDS", 9)) {
778 /* ^ */
779#ifdef SCM_CREDS
780 *iv_return = SCM_CREDS;
781 return PERL_constant_ISIV;
a0d0e21e 782#else
18085af4 783 return PERL_constant_NOTDEF;
a0d0e21e 784#endif
18085af4
JH
785 }
786 break;
787 case 'G':
788 if (memEQ(name, "SO_LINGER", 9)) {
789 /* ^ */
790#ifdef SO_LINGER
791 *iv_return = SO_LINGER;
792 return PERL_constant_ISIV;
a0d0e21e 793#else
18085af4 794 return PERL_constant_NOTDEF;
a0d0e21e 795#endif
18085af4
JH
796 }
797 break;
798 case 'I':
799 if (memEQ(name, "AF_HYLINK", 9)) {
800 /* ^ */
801#ifdef AF_HYLINK
802 *iv_return = AF_HYLINK;
803 return PERL_constant_ISIV;
a0d0e21e 804#else
18085af4 805 return PERL_constant_NOTDEF;
a0d0e21e 806#endif
18085af4
JH
807 }
808 if (memEQ(name, "PF_HYLINK", 9)) {
809 /* ^ */
810#ifdef PF_HYLINK
811 *iv_return = PF_HYLINK;
812 return PERL_constant_ISIV;
a0d0e21e 813#else
18085af4 814 return PERL_constant_NOTDEF;
a0d0e21e 815#endif
18085af4
JH
816 }
817 break;
818 case 'N':
819 if (memEQ(name, "AF_OSINET", 9)) {
820 /* ^ */
821#ifdef AF_OSINET
822 *iv_return = AF_OSINET;
823 return PERL_constant_ISIV;
a0d0e21e 824#else
18085af4 825 return PERL_constant_NOTDEF;
a0d0e21e 826#endif
18085af4
JH
827 }
828 if (memEQ(name, "PF_OSINET", 9)) {
829 /* ^ */
830#ifdef PF_OSINET
831 *iv_return = PF_OSINET;
832 return PERL_constant_ISIV;
a0d0e21e 833#else
18085af4 834 return PERL_constant_NOTDEF;
a0d0e21e 835#endif
18085af4
JH
836 }
837 break;
838 case 'O':
839 if (memEQ(name, "MSG_PROXY", 9)) {
840 /* ^ */
841#if defined(MSG_PROXY) || defined(HAS_MSG_PROXY) /* might be an enum */
842 *iv_return = MSG_PROXY;
843 return PERL_constant_ISIV;
a0d0e21e 844#else
18085af4 845 return PERL_constant_NOTDEF;
a0d0e21e 846#endif
18085af4
JH
847 }
848 if (memEQ(name, "SOMAXCONN", 9)) {
849 /* ^ */
850#ifdef SOMAXCONN
851 *iv_return = SOMAXCONN;
852 return PERL_constant_ISIV;
a0d0e21e 853#else
18085af4 854 return PERL_constant_NOTDEF;
a0d0e21e 855#endif
18085af4
JH
856 }
857 break;
858 case 'P':
859 if (memEQ(name, "AF_UNSPEC", 9)) {
860 /* ^ */
861#ifdef AF_UNSPEC
862 *iv_return = AF_UNSPEC;
863 return PERL_constant_ISIV;
a0d0e21e 864#else
18085af4 865 return PERL_constant_NOTDEF;
a0d0e21e 866#endif
18085af4
JH
867 }
868 if (memEQ(name, "PF_UNSPEC", 9)) {
869 /* ^ */
870#ifdef PF_UNSPEC
871 *iv_return = PF_UNSPEC;
872 return PERL_constant_ISIV;
a0d0e21e 873#else
18085af4 874 return PERL_constant_NOTDEF;
a0d0e21e 875#endif
18085af4
JH
876 }
877 break;
878 case 'U':
879 if (memEQ(name, "MSG_TRUNC", 9)) {
880 /* ^ */
881#ifdef MSG_TRUNC
882 *iv_return = MSG_TRUNC;
883 return PERL_constant_ISIV;
a0d0e21e 884#else
18085af4 885 return PERL_constant_NOTDEF;
a0d0e21e 886#endif
18085af4
JH
887 }
888 break;
889 case 'X':
890 if (memEQ(name, "TCP_MAXRT", 9)) {
891 /* ^ */
892#ifdef TCP_MAXRT
893 *iv_return = TCP_MAXRT;
894 return PERL_constant_ISIV;
a0d0e21e 895#else
18085af4 896 return PERL_constant_NOTDEF;
a0d0e21e 897#endif
18085af4
JH
898 }
899 break;
900 case 'n':
901 if (memEQ(name, "AF_DECnet", 9)) {
902 /* ^ */
903#ifdef AF_DECnet
904 *iv_return = AF_DECnet;
905 return PERL_constant_ISIV;
a0d0e21e 906#else
18085af4 907 return PERL_constant_NOTDEF;
a0d0e21e 908#endif
18085af4
JH
909 }
910 if (memEQ(name, "PF_DECnet", 9)) {
911 /* ^ */
912#ifdef PF_DECnet
913 *iv_return = PF_DECnet;
914 return PERL_constant_ISIV;
a0d0e21e 915#else
18085af4 916 return PERL_constant_NOTDEF;
a0d0e21e 917#endif
18085af4
JH
918 }
919 break;
920 }
921 return PERL_constant_NOTFOUND;
922}
923
924static int
cea00dc5 925constant_10 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
926 /* When generated this function returned values for the list of names given
927 here. However, subsequent manual editing may have added or removed some.
cea00dc5
NC
928 AF_DATAKIT AF_IMPLINK INADDR_ANY MSG_CTRUNC PF_DATAKIT PF_IMPLINK
929 SCM_RIGHTS SOCK_DGRAM SOL_SOCKET TCP_MAXSEG TCP_STDURG UIO_MAXIOV */
18085af4
JH
930 /* Offset 6 gives the best switch position. */
931 switch (name[6]) {
932 case 'A':
933 if (memEQ(name, "AF_DATAKIT", 10)) {
934 /* ^ */
935#ifdef AF_DATAKIT
936 *iv_return = AF_DATAKIT;
937 return PERL_constant_ISIV;
a0d0e21e 938#else
18085af4 939 return PERL_constant_NOTDEF;
a0d0e21e 940#endif
18085af4
JH
941 }
942 if (memEQ(name, "PF_DATAKIT", 10)) {
943 /* ^ */
944#ifdef PF_DATAKIT
945 *iv_return = PF_DATAKIT;
946 return PERL_constant_ISIV;
de4597cb 947#else
18085af4 948 return PERL_constant_NOTDEF;
de4597cb 949#endif
18085af4
JH
950 }
951 break;
952 case 'C':
953 if (memEQ(name, "SOL_SOCKET", 10)) {
954 /* ^ */
955#ifdef SOL_SOCKET
956 *iv_return = SOL_SOCKET;
957 return PERL_constant_ISIV;
de4597cb 958#else
18085af4 959 return PERL_constant_NOTDEF;
de4597cb 960#endif
18085af4
JH
961 }
962 break;
963 case 'D':
964 if (memEQ(name, "TCP_STDURG", 10)) {
965 /* ^ */
966#ifdef TCP_STDURG
967 *iv_return = TCP_STDURG;
968 return PERL_constant_ISIV;
de4597cb 969#else
18085af4 970 return PERL_constant_NOTDEF;
de4597cb 971#endif
18085af4
JH
972 }
973 break;
974 case 'G':
975 if (memEQ(name, "SCM_RIGHTS", 10)) {
976 /* ^ */
5b8dae3f 977#if defined(SCM_RIGHTS) || defined(HAS_SCM_RIGHTS) /* might be an enum */
18085af4
JH
978 *iv_return = SCM_RIGHTS;
979 return PERL_constant_ISIV;
de4597cb 980#else
18085af4 981 return PERL_constant_NOTDEF;
de4597cb 982#endif
18085af4
JH
983 }
984 if (memEQ(name, "SOCK_DGRAM", 10)) {
985 /* ^ */
986#ifdef SOCK_DGRAM
987 *iv_return = SOCK_DGRAM;
988 return PERL_constant_ISIV;
de4597cb 989#else
18085af4 990 return PERL_constant_NOTDEF;
de4597cb 991#endif
18085af4
JH
992 }
993 break;
994 case 'L':
995 if (memEQ(name, "AF_IMPLINK", 10)) {
996 /* ^ */
997#ifdef AF_IMPLINK
998 *iv_return = AF_IMPLINK;
999 return PERL_constant_ISIV;
ca6e1c26 1000#else
18085af4 1001 return PERL_constant_NOTDEF;
ca6e1c26 1002#endif
18085af4
JH
1003 }
1004 if (memEQ(name, "PF_IMPLINK", 10)) {
1005 /* ^ */
1006#ifdef PF_IMPLINK
1007 *iv_return = PF_IMPLINK;
1008 return PERL_constant_ISIV;
ca6e1c26 1009#else
18085af4 1010 return PERL_constant_NOTDEF;
ca6e1c26 1011#endif
18085af4
JH
1012 }
1013 break;
1014 case 'R':
1015 if (memEQ(name, "MSG_CTRUNC", 10)) {
1016 /* ^ */
1017#if defined(MSG_CTRUNC) || defined(HAS_MSG_CTRUNC) /* might be an enum */
1018 *iv_return = MSG_CTRUNC;
1019 return PERL_constant_ISIV;
ca6e1c26 1020#else
18085af4 1021 return PERL_constant_NOTDEF;
ca6e1c26 1022#endif
18085af4
JH
1023 }
1024 break;
1025 case 'X':
1026 if (memEQ(name, "TCP_MAXSEG", 10)) {
1027 /* ^ */
1028#ifdef TCP_MAXSEG
1029 *iv_return = TCP_MAXSEG;
1030 return PERL_constant_ISIV;
a0d0e21e 1031#else
18085af4 1032 return PERL_constant_NOTDEF;
a0d0e21e 1033#endif
18085af4
JH
1034 }
1035 if (memEQ(name, "UIO_MAXIOV", 10)) {
1036 /* ^ */
1037#ifdef UIO_MAXIOV
1038 *iv_return = UIO_MAXIOV;
1039 return PERL_constant_ISIV;
a0d0e21e 1040#else
18085af4 1041 return PERL_constant_NOTDEF;
a0d0e21e 1042#endif
18085af4
JH
1043 }
1044 break;
cea00dc5
NC
1045 case '_':
1046 if (memEQ(name, "INADDR_ANY", 10)) {
1047 /* ^ */
1048#ifdef INADDR_ANY
1049 {
1050struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_ANY);
1051 *sv_return = sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ));
1052 return PERL_constant_ISSV;
1053 }
1054#else
1055 return PERL_constant_NOTDEF;
1056#endif
1057 }
1058 break;
18085af4
JH
1059 }
1060 return PERL_constant_NOTFOUND;
1061}
1062
1063static int
cea00dc5 1064constant_11 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
1065 /* When generated this function returned values for the list of names given
1066 here. However, subsequent manual editing may have added or removed some.
cea00dc5
NC
1067 INADDR_NONE IPPROTO_TCP MSG_WAITALL SCM_CONNECT SOCK_STREAM SO_RCVLOWAT
1068 SO_RCVTIMEO SO_SNDLOWAT SO_SNDTIMEO TCP_NODELAY */
1069 /* Offset 5 gives the best switch position. */
1070 switch (name[5]) {
1071 case 'A':
1072 if (memEQ(name, "MSG_WAITALL", 11)) {
1073 /* ^ */
1074#ifdef MSG_WAITALL
1075 *iv_return = MSG_WAITALL;
18085af4 1076 return PERL_constant_ISIV;
a0d0e21e 1077#else
18085af4 1078 return PERL_constant_NOTDEF;
a0d0e21e 1079#endif
18085af4
JH
1080 }
1081 break;
cea00dc5
NC
1082 case 'D':
1083 if (memEQ(name, "SO_SNDLOWAT", 11)) {
1084 /* ^ */
1085#ifdef SO_SNDLOWAT
1086 *iv_return = SO_SNDLOWAT;
18085af4 1087 return PERL_constant_ISIV;
a0d0e21e 1088#else
18085af4 1089 return PERL_constant_NOTDEF;
a0d0e21e 1090#endif
18085af4
JH
1091 }
1092 if (memEQ(name, "SO_SNDTIMEO", 11)) {
cea00dc5 1093 /* ^ */
18085af4
JH
1094#ifdef SO_SNDTIMEO
1095 *iv_return = SO_SNDTIMEO;
1096 return PERL_constant_ISIV;
a0d0e21e 1097#else
18085af4 1098 return PERL_constant_NOTDEF;
a0d0e21e 1099#endif
18085af4
JH
1100 }
1101 break;
cea00dc5 1102 case 'O':
18085af4 1103 if (memEQ(name, "SCM_CONNECT", 11)) {
cea00dc5 1104 /* ^ */
18085af4
JH
1105#ifdef SCM_CONNECT
1106 *iv_return = SCM_CONNECT;
1107 return PERL_constant_ISIV;
a0d0e21e 1108#else
18085af4 1109 return PERL_constant_NOTDEF;
a0d0e21e 1110#endif
18085af4 1111 }
cea00dc5
NC
1112 if (memEQ(name, "TCP_NODELAY", 11)) {
1113 /* ^ */
1114#ifdef TCP_NODELAY
1115 *iv_return = TCP_NODELAY;
18085af4 1116 return PERL_constant_ISIV;
a0d0e21e 1117#else
18085af4 1118 return PERL_constant_NOTDEF;
a0d0e21e 1119#endif
18085af4 1120 }
cea00dc5
NC
1121 break;
1122 case 'R':
1123 if (memEQ(name, "INADDR_NONE", 11)) {
1124 /* ^ */
1125#ifdef INADDR_NONE
1126 {
1127struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_NONE);
1128 *sv_return = sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ));
1129 return PERL_constant_ISSV;
1130 }
a0d0e21e 1131#else
18085af4 1132 return PERL_constant_NOTDEF;
a0d0e21e 1133#endif
18085af4
JH
1134 }
1135 break;
cea00dc5 1136 case 'S':
18085af4 1137 if (memEQ(name, "SOCK_STREAM", 11)) {
cea00dc5 1138 /* ^ */
18085af4
JH
1139#ifdef SOCK_STREAM
1140 *iv_return = SOCK_STREAM;
1141 return PERL_constant_ISIV;
a0d0e21e 1142#else
18085af4 1143 return PERL_constant_NOTDEF;
a0d0e21e 1144#endif
18085af4
JH
1145 }
1146 break;
1147 case 'T':
cea00dc5
NC
1148 if (memEQ(name, "IPPROTO_TCP", 11)) {
1149 /* ^ */
1150#ifdef IPPROTO_TCP
1151 *iv_return = IPPROTO_TCP;
18085af4 1152 return PERL_constant_ISIV;
a0d0e21e 1153#else
18085af4 1154 return PERL_constant_NOTDEF;
a0d0e21e 1155#endif
18085af4
JH
1156 }
1157 break;
cea00dc5
NC
1158 case 'V':
1159 if (memEQ(name, "SO_RCVLOWAT", 11)) {
1160 /* ^ */
1161#ifdef SO_RCVLOWAT
1162 *iv_return = SO_RCVLOWAT;
1163 return PERL_constant_ISIV;
1164#else
1165 return PERL_constant_NOTDEF;
1166#endif
1167 }
1168 if (memEQ(name, "SO_RCVTIMEO", 11)) {
1169 /* ^ */
1170#ifdef SO_RCVTIMEO
1171 *iv_return = SO_RCVTIMEO;
18085af4 1172 return PERL_constant_ISIV;
a0d0e21e 1173#else
18085af4 1174 return PERL_constant_NOTDEF;
a0d0e21e 1175#endif
18085af4
JH
1176 }
1177 break;
1178 }
1179 return PERL_constant_NOTFOUND;
1180}
1181
1182static int
cea00dc5 1183constant_12 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
1184 /* When generated this function returned values for the list of names given
1185 here. However, subsequent manual editing may have added or removed some.
1186 AF_APPLETALK MSG_CTLFLAGS MSG_DONTWAIT MSG_ERRQUEUE MSG_NOSIGNAL
1187 PF_APPLETALK SO_BROADCAST SO_DONTROUTE SO_KEEPALIVE SO_OOBINLINE
1188 SO_REUSEADDR SO_REUSEPORT */
1189 /* Offset 10 gives the best switch position. */
1190 switch (name[10]) {
1191 case 'A':
1192 if (memEQ(name, "MSG_NOSIGNAL", 12)) {
1193 /* ^ */
1194#ifdef MSG_NOSIGNAL
1195 *iv_return = MSG_NOSIGNAL;
1196 return PERL_constant_ISIV;
a0d0e21e 1197#else
18085af4 1198 return PERL_constant_NOTDEF;
a0d0e21e 1199#endif
18085af4
JH
1200 }
1201 break;
1202 case 'D':
1203 if (memEQ(name, "SO_REUSEADDR", 12)) {
1204 /* ^ */
1205#ifdef SO_REUSEADDR
1206 *iv_return = SO_REUSEADDR;
1207 return PERL_constant_ISIV;
a0d0e21e 1208#else
18085af4 1209 return PERL_constant_NOTDEF;
a0d0e21e 1210#endif
18085af4
JH
1211 }
1212 break;
1213 case 'G':
1214 if (memEQ(name, "MSG_CTLFLAGS", 12)) {
1215 /* ^ */
1216#ifdef MSG_CTLFLAGS
1217 *iv_return = MSG_CTLFLAGS;
1218 return PERL_constant_ISIV;
a0d0e21e 1219#else
18085af4 1220 return PERL_constant_NOTDEF;
a0d0e21e 1221#endif
18085af4
JH
1222 }
1223 break;
1224 case 'I':
1225 if (memEQ(name, "MSG_DONTWAIT", 12)) {
1226 /* ^ */
1227#ifdef MSG_DONTWAIT
1228 *iv_return = MSG_DONTWAIT;
1229 return PERL_constant_ISIV;
1230#else
1231 return PERL_constant_NOTDEF;
1232#endif
1233 }
1234 break;
1235 case 'L':
1236 if (memEQ(name, "AF_APPLETALK", 12)) {
1237 /* ^ */
1238#ifdef AF_APPLETALK
1239 *iv_return = AF_APPLETALK;
1240 return PERL_constant_ISIV;
a0d0e21e 1241#else
18085af4 1242 return PERL_constant_NOTDEF;
a0d0e21e 1243#endif
18085af4
JH
1244 }
1245 if (memEQ(name, "PF_APPLETALK", 12)) {
1246 /* ^ */
1247#ifdef PF_APPLETALK
1248 *iv_return = PF_APPLETALK;
1249 return PERL_constant_ISIV;
1250#else
1251 return PERL_constant_NOTDEF;
1252#endif
1253 }
1254 break;
1255 case 'N':
1256 if (memEQ(name, "SO_OOBINLINE", 12)) {
1257 /* ^ */
a0d0e21e 1258#ifdef SO_OOBINLINE
18085af4
JH
1259 *iv_return = SO_OOBINLINE;
1260 return PERL_constant_ISIV;
a0d0e21e 1261#else
18085af4 1262 return PERL_constant_NOTDEF;
a0d0e21e 1263#endif
18085af4
JH
1264 }
1265 break;
1266 case 'R':
1267 if (memEQ(name, "SO_REUSEPORT", 12)) {
1268 /* ^ */
1269#ifdef SO_REUSEPORT
1270 *iv_return = SO_REUSEPORT;
1271 return PERL_constant_ISIV;
a0d0e21e 1272#else
18085af4 1273 return PERL_constant_NOTDEF;
a0d0e21e 1274#endif
18085af4
JH
1275 }
1276 break;
1277 case 'S':
1278 if (memEQ(name, "SO_BROADCAST", 12)) {
1279 /* ^ */
1280#ifdef SO_BROADCAST
1281 *iv_return = SO_BROADCAST;
1282 return PERL_constant_ISIV;
a0d0e21e 1283#else
18085af4 1284 return PERL_constant_NOTDEF;
a0d0e21e 1285#endif
18085af4
JH
1286 }
1287 break;
1288 case 'T':
1289 if (memEQ(name, "SO_DONTROUTE", 12)) {
1290 /* ^ */
1291#ifdef SO_DONTROUTE
1292 *iv_return = SO_DONTROUTE;
1293 return PERL_constant_ISIV;
a0d0e21e 1294#else
18085af4 1295 return PERL_constant_NOTDEF;
a0d0e21e 1296#endif
18085af4
JH
1297 }
1298 break;
1299 case 'U':
1300 if (memEQ(name, "MSG_ERRQUEUE", 12)) {
1301 /* ^ */
1302#ifdef MSG_ERRQUEUE
1303 *iv_return = MSG_ERRQUEUE;
1304 return PERL_constant_ISIV;
a0d0e21e 1305#else
18085af4 1306 return PERL_constant_NOTDEF;
a0d0e21e 1307#endif
18085af4
JH
1308 }
1309 break;
1310 case 'V':
1311 if (memEQ(name, "SO_KEEPALIVE", 12)) {
1312 /* ^ */
1313#ifdef SO_KEEPALIVE
1314 *iv_return = SO_KEEPALIVE;
1315 return PERL_constant_ISIV;
a0d0e21e 1316#else
18085af4 1317 return PERL_constant_NOTDEF;
a0d0e21e 1318#endif
18085af4
JH
1319 }
1320 break;
1321 }
1322 return PERL_constant_NOTFOUND;
1323}
1324
1325static int
cea00dc5 1326constant_13 (const char *name, IV *iv_return, SV **sv_return) {
18085af4
JH
1327 /* When generated this function returned values for the list of names given
1328 here. However, subsequent manual editing may have added or removed some.
1329 MSG_CTLIGNORE MSG_DONTROUTE MSG_MAXIOVLEN SCM_TIMESTAMP SO_ACCEPTCONN
1330 SO_DONTLINGER TCP_KEEPALIVE */
1331 /* Offset 5 gives the best switch position. */
1332 switch (name[5]) {
1333 case 'A':
1334 if (memEQ(name, "MSG_MAXIOVLEN", 13)) {
1335 /* ^ */
1336#ifdef MSG_MAXIOVLEN
1337 *iv_return = MSG_MAXIOVLEN;
1338 return PERL_constant_ISIV;
a0d0e21e 1339#else
18085af4 1340 return PERL_constant_NOTDEF;
a0d0e21e 1341#endif
18085af4
JH
1342 }
1343 break;
1344 case 'C':
1345 if (memEQ(name, "SO_ACCEPTCONN", 13)) {
1346 /* ^ */
1347#ifdef SO_ACCEPTCONN
1348 *iv_return = SO_ACCEPTCONN;
1349 return PERL_constant_ISIV;
a0d0e21e 1350#else
18085af4 1351 return PERL_constant_NOTDEF;
a0d0e21e 1352#endif
18085af4
JH
1353 }
1354 break;
1355 case 'E':
1356 if (memEQ(name, "TCP_KEEPALIVE", 13)) {
1357 /* ^ */
1358#ifdef TCP_KEEPALIVE
1359 *iv_return = TCP_KEEPALIVE;
1360 return PERL_constant_ISIV;
a0d0e21e 1361#else
18085af4 1362 return PERL_constant_NOTDEF;
a0d0e21e 1363#endif
18085af4
JH
1364 }
1365 break;
1366 case 'I':
1367 if (memEQ(name, "SCM_TIMESTAMP", 13)) {
1368 /* ^ */
1369#ifdef SCM_TIMESTAMP
1370 *iv_return = SCM_TIMESTAMP;
1371 return PERL_constant_ISIV;
a0d0e21e 1372#else
18085af4 1373 return PERL_constant_NOTDEF;
a0d0e21e 1374#endif
18085af4
JH
1375 }
1376 break;
1377 case 'N':
1378 if (memEQ(name, "SO_DONTLINGER", 13)) {
1379 /* ^ */
1380#ifdef SO_DONTLINGER
1381 *iv_return = SO_DONTLINGER;
1382 return PERL_constant_ISIV;
a0d0e21e 1383#else
18085af4 1384 return PERL_constant_NOTDEF;
a0d0e21e 1385#endif
18085af4
JH
1386 }
1387 break;
1388 case 'O':
1389 if (memEQ(name, "MSG_DONTROUTE", 13)) {
1390 /* ^ */
1391#if defined(MSG_DONTROUTE) || defined(HAS_MSG_DONTROUTE) /* might be an enum */
1392 *iv_return = MSG_DONTROUTE;
1393 return PERL_constant_ISIV;
1494e794 1394#else
18085af4 1395 return PERL_constant_NOTDEF;
1494e794 1396#endif
18085af4
JH
1397 }
1398 break;
1399 case 'T':
1400 if (memEQ(name, "MSG_CTLIGNORE", 13)) {
1401 /* ^ */
1402#ifdef MSG_CTLIGNORE
1403 *iv_return = MSG_CTLIGNORE;
1404 return PERL_constant_ISIV;
1494e794 1405#else
18085af4 1406 return PERL_constant_NOTDEF;
1494e794 1407#endif
18085af4
JH
1408 }
1409 break;
1410 }
1411 return PERL_constant_NOTFOUND;
1412}
1413
1414static int
cea00dc5 1415constant (const char *name, STRLEN len, IV *iv_return, SV **sv_return) {
18085af4
JH
1416 /* Initially switch on the length of the name. */
1417 /* When generated this function returned values for the list of names given
1418 in this section of perl code. Rather than manually editing these functions
1419 to add or remove constants, which would result in this comment and section
1420 of code becoming inaccurate, we recommend that you edit this section of
1421 code, and use it to regenerate a new set of constant functions which you
1422 then use to replace the originals.
1423
1424 Regenerate these constant functions by feeding this entire source file to
1425 perl -x
1426
cea00dc5 1427#!../../perl -w
18085af4
JH
1428use ExtUtils::Constant qw (constant_types C_constant XS_constant);
1429
cea00dc5 1430my $types = {map {($_, 1)} qw(IV SV)};
18085af4
JH
1431my @names = (qw(AF_802 AF_APPLETALK AF_CCITT AF_CHAOS AF_DATAKIT AF_DECnet
1432 AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK AF_INET AF_LAT
1433 AF_MAX AF_NBS AF_NIT AF_NS AF_OSI AF_OSINET AF_PUP AF_SNA
1434 AF_UNIX AF_UNSPEC AF_X25 IOV_MAX IPPROTO_TCP MSG_BCAST
1435 MSG_CTLFLAGS MSG_CTLIGNORE MSG_DONTWAIT MSG_EOF MSG_EOR
1436 MSG_ERRQUEUE MSG_FIN MSG_MAXIOVLEN MSG_MCAST MSG_NOSIGNAL
cea00dc5
NC
1437 MSG_RST MSG_SYN MSG_TRUNC MSG_URG MSG_WAITALL PF_802
1438 PF_APPLETALK PF_CCITT PF_CHAOS PF_DATAKIT PF_DECnet PF_DLI
1439 PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_LAT PF_MAX
1440 PF_NBS PF_NIT PF_NS PF_OSI PF_OSINET PF_PUP PF_SNA PF_UNIX
1441 PF_UNSPEC PF_X25 SCM_CONNECT SCM_CREDENTIALS SCM_CREDS
1442 SCM_TIMESTAMP SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET
1443 SOCK_STREAM SOL_SOCKET SOMAXCONN SO_ACCEPTCONN SO_BROADCAST
1444 SO_DEBUG SO_DONTLINGER SO_DONTROUTE SO_ERROR SO_KEEPALIVE
1445 SO_LINGER SO_OOBINLINE SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO
1446 SO_REUSEADDR SO_REUSEPORT SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO
1447 SO_TYPE SO_USELOOPBACK TCP_KEEPALIVE TCP_MAXRT TCP_MAXSEG
1448 TCP_NODELAY TCP_STDURG UIO_MAXIOV),
1449 {name=>"INADDR_ANY", type=>"SV", value=>"sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ))", pre=>"struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_ANY);"},
1450 {name=>"INADDR_BROADCAST", type=>"SV", value=>"sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ))", pre=>"struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_BROADCAST);"},
1451 {name=>"INADDR_LOOPBACK", type=>"SV", value=>"sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ))", pre=>"struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_LOOPBACK);"},
1452 {name=>"INADDR_NONE", type=>"SV", value=>"sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ))", pre=>"struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_NONE);"},
d05c1ba0
JH
1453 {name=>"MSG_CTRUNC", type=>"IV", macro=>["#if defined(MSG_CTRUNC) || defined(HAS_MSG_CTRUNC) /" . "* might be an enum *" . "/\n", "#endif\n"]},
1454 {name=>"MSG_DONTROUTE", type=>"IV", macro=>["#if defined(MSG_DONTROUTE) || defined(HAS_MSG_DONTROUTE) /" . "* might be an enum *" . "/\n", "#endif\n"]},
1455 {name=>"MSG_OOB", type=>"IV", macro=>["#if defined(MSG_OOB) || defined(HAS_MSG_OOB) /" . "* might be an enum *" . "/\n", "#endif\n"]},
1456 {name=>"MSG_PEEK", type=>"IV", macro=>["#if defined(MSG_PEEK) || defined(HAS_MSG_PEEK) /" . "* might be an enum *" . "/\n", "#endif\n"]},
1457 {name=>"MSG_PROXY", type=>"IV", macro=>["#if defined(MSG_PROXY) || defined(HAS_MSG_PROXY) /" . "* might be an enum *" . "/\n", "#endif\n"]},
1458 {name=>"SCM_RIGHTS", type=>"IV", macro=>["#if defined(SCM_RIGHTS) || defined(HAS_SCM_RIGHTS) /" . "* might be an enum *" . "/\n", "#endif\n"]},
18085af4
JH
1459 {name=>"SHUT_RD", type=>"IV", default=>["IV", "0"]},
1460 {name=>"SHUT_RDWR", type=>"IV", default=>["IV", "2"]},
1461 {name=>"SHUT_WR", type=>"IV", default=>["IV", "1"]});
1462
1463print constant_types(); # macro defs
cea00dc5 1464foreach (C_constant ("Socket", 'constant', 'IV', $types, undef, 3, @names) ) {
18085af4
JH
1465 print $_, "\n"; # C constant subs
1466}
1467print "#### XS Section:\n";
1468print XS_constant ("Socket", $types);
1469__END__
1470 */
1471
1472 switch (len) {
1473 case 5:
cea00dc5
NC
1474 /* Names all of length 5. */
1475 /* AF_NS PF_NS */
1476 /* Offset 0 gives the best switch position. */
1477 switch (name[0]) {
1478 case 'A':
1479 if (memEQ(name, "AF_NS", 5)) {
1480 /* ^ */
1481#ifdef AF_NS
1482 *iv_return = AF_NS;
1483 return PERL_constant_ISIV;
1484#else
1485 return PERL_constant_NOTDEF;
1486#endif
1487 }
1488 break;
1489 case 'P':
1490 if (memEQ(name, "PF_NS", 5)) {
1491 /* ^ */
1492#ifdef PF_NS
1493 *iv_return = PF_NS;
1494 return PERL_constant_ISIV;
1495#else
1496 return PERL_constant_NOTDEF;
1497#endif
1498 }
1499 break;
1500 }
18085af4
JH
1501 break;
1502 case 6:
cea00dc5 1503 return constant_6 (name, iv_return, sv_return);
18085af4
JH
1504 break;
1505 case 7:
cea00dc5 1506 return constant_7 (name, iv_return, sv_return);
18085af4
JH
1507 break;
1508 case 8:
cea00dc5 1509 return constant_8 (name, iv_return, sv_return);
18085af4
JH
1510 break;
1511 case 9:
cea00dc5 1512 return constant_9 (name, iv_return, sv_return);
18085af4
JH
1513 break;
1514 case 10:
cea00dc5 1515 return constant_10 (name, iv_return, sv_return);
18085af4
JH
1516 break;
1517 case 11:
cea00dc5 1518 return constant_11 (name, iv_return, sv_return);
18085af4
JH
1519 break;
1520 case 12:
cea00dc5 1521 return constant_12 (name, iv_return, sv_return);
18085af4
JH
1522 break;
1523 case 13:
cea00dc5 1524 return constant_13 (name, iv_return, sv_return);
18085af4
JH
1525 break;
1526 case 14:
cea00dc5
NC
1527 /* Names all of length 14. */
1528 /* SOCK_SEQPACKET SO_USELOOPBACK */
1529 /* Offset 8 gives the best switch position. */
1530 switch (name[8]) {
1531 case 'O':
1532 if (memEQ(name, "SO_USELOOPBACK", 14)) {
1533 /* ^ */
1534#ifdef SO_USELOOPBACK
1535 *iv_return = SO_USELOOPBACK;
1536 return PERL_constant_ISIV;
1537#else
1538 return PERL_constant_NOTDEF;
1539#endif
1540 }
1541 break;
1542 case 'P':
1543 if (memEQ(name, "SOCK_SEQPACKET", 14)) {
1544 /* ^ */
1545#ifdef SOCK_SEQPACKET
1546 *iv_return = SOCK_SEQPACKET;
1547 return PERL_constant_ISIV;
1548#else
1549 return PERL_constant_NOTDEF;
1550#endif
1551 }
1552 break;
1553 }
18085af4
JH
1554 break;
1555 case 15:
cea00dc5
NC
1556 /* Names all of length 15. */
1557 /* INADDR_LOOPBACK SCM_CREDENTIALS */
1558 /* Offset 4 gives the best switch position. */
1559 switch (name[4]) {
1560 case 'C':
1561 if (memEQ(name, "SCM_CREDENTIALS", 15)) {
1562 /* ^ */
18085af4 1563#ifdef SCM_CREDENTIALS
cea00dc5
NC
1564 *iv_return = SCM_CREDENTIALS;
1565 return PERL_constant_ISIV;
1566#else
1567 return PERL_constant_NOTDEF;
1568#endif
1569 }
1570 break;
1571 case 'D':
1572 if (memEQ(name, "INADDR_LOOPBACK", 15)) {
1573 /* ^ */
1574#ifdef INADDR_LOOPBACK
1575 {
1576struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_LOOPBACK);
1577 *sv_return = sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ));
1578 return PERL_constant_ISSV;
1579 }
1580#else
1581 return PERL_constant_NOTDEF;
1582#endif
1583 }
1584 break;
1585 }
1586 break;
1587 case 16:
1588 if (memEQ(name, "INADDR_BROADCAST", 16)) {
1589#ifdef INADDR_BROADCAST
1590 {
1591struct in_addr ip_address; ip_address.s_addr = htonl(INADDR_BROADCAST);
1592 *sv_return = sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address ));
1593 return PERL_constant_ISSV;
1594 }
1494e794 1595#else
18085af4 1596 return PERL_constant_NOTDEF;
1494e794 1597#endif
18085af4
JH
1598 }
1599 break;
1600 }
1601 return PERL_constant_NOTFOUND;
a0d0e21e
LW
1602}
1603
8e07c86e 1604
a0d0e21e
LW
1605MODULE = Socket PACKAGE = Socket
1606
18085af4
JH
1607void
1608constant(sv)
1609 PREINIT:
cea00dc5 1610 dXSTARG;
18085af4
JH
1611 STRLEN len;
1612 int type;
1613 IV iv;
1614 /* NV nv; Uncomment this if you need to return NVs */
1615 /* const char *pv; Uncomment this if you need to return PVs */
1616 INPUT:
1617 SV * sv;
1618 const char * s = SvPV(sv, len);
1619 PPCODE:
1620 /* Change this to constant(s, len, &iv, &nv);
1621 if you need to return both NVs and IVs */
cea00dc5 1622 type = constant(s, len, &iv, &sv);
18085af4
JH
1623 /* Return 1 or 2 items. First is error message, or undef if no error.
1624 Second, if present, is found value */
1625 switch (type) {
1626 case PERL_constant_NOTFOUND:
1627 sv = sv_2mortal(newSVpvf("%s is not a valid Socket macro", s));
1628 PUSHs(sv);
1629 break;
1630 case PERL_constant_NOTDEF:
1631 sv = sv_2mortal(newSVpvf(
1632 "Your vendor has not defined Socket macro %s, used", s));
1633 PUSHs(sv);
1634 break;
1635 case PERL_constant_ISIV:
1636 EXTEND(SP, 1);
1637 PUSHs(&PL_sv_undef);
1638 PUSHi(iv);
1639 break;
cea00dc5
NC
1640 case PERL_constant_ISSV:
1641 EXTEND(SP, 1);
1642 PUSHs(&PL_sv_undef);
1643 PUSHs(sv);
1644 break;
18085af4
JH
1645 /* Uncomment this if you need to return UVs
1646 case PERL_constant_ISUV:
1647 EXTEND(SP, 1);
1648 PUSHs(&PL_sv_undef);
1649 PUSHu((UV)iv);
1650 break; */
1651 default:
1652 sv = sv_2mortal(newSVpvf(
cea00dc5 1653 "Unexpected return type %d while processing Socket macro %s, used",
18085af4
JH
1654 type, s));
1655 PUSHs(sv);
1656 }
8e07c86e
AD
1657
1658void
1659inet_aton(host)
1660 char * host
1661 CODE:
1662 {
1663 struct in_addr ip_address;
1664 struct hostent * phe;
ac9fe1c2 1665 int ok = inet_aton(host, &ip_address);
8e07c86e 1666
ac9fe1c2 1667 if (!ok && (phe = gethostbyname(host))) {
8e07c86e 1668 Copy( phe->h_addr, &ip_address, phe->h_length, char );
7e1af8bc 1669 ok = 1;
8e07c86e
AD
1670 }
1671
1672 ST(0) = sv_newmortal();
7e1af8bc 1673 if (ok) {
8e07c86e
AD
1674 sv_setpvn( ST(0), (char *)&ip_address, sizeof ip_address );
1675 }
1676 }
1677
1678void
1679inet_ntoa(ip_address_sv)
1680 SV * ip_address_sv
1681 CODE:
1682 {
1683 STRLEN addrlen;
1684 struct in_addr addr;
1685 char * addr_str;
1686 char * ip_address = SvPV(ip_address_sv,addrlen);
1687 if (addrlen != sizeof(addr)) {
1688 croak("Bad arg length for %s, length is %d, should be %d",
1689 "Socket::inet_ntoa",
1690 addrlen, sizeof(addr));
1691 }
1692
1693 Copy( ip_address, &addr, sizeof addr, char );
1694 addr_str = inet_ntoa(addr);
1695
79cb57f6 1696 ST(0) = sv_2mortal(newSVpvn(addr_str, strlen(addr_str)));
8e07c86e
AD
1697 }
1698
1699void
4633a7c4
LW
1700pack_sockaddr_un(pathname)
1701 char * pathname
1702 CODE:
1703 {
25f94b33 1704#ifdef I_SYS_UN
4633a7c4 1705 struct sockaddr_un sun_ad; /* fear using sun */
fcdb74fc 1706 STRLEN len;
202975e6 1707
4633a7c4
LW
1708 Zero( &sun_ad, sizeof sun_ad, char );
1709 sun_ad.sun_family = AF_UNIX;
20408e3c
GS
1710 len = strlen(pathname);
1711 if (len > sizeof(sun_ad.sun_path))
1712 len = sizeof(sun_ad.sun_path);
202975e6
IZ
1713# ifdef OS2 /* Name should start with \socket\ and contain backslashes! */
1714 {
1715 int off;
1716 char *s, *e;
1717
1718 if (pathname[0] != '/' && pathname[0] != '\\')
1719 croak("Relative UNIX domain socket name '%s' unsupported", pathname);
1720 else if (len < 8
1721 || pathname[7] != '/' && pathname[7] != '\\'
1722 || !strnicmp(pathname + 1, "socket", 6))
1723 off = 7;
1724 else
1725 off = 0; /* Preserve names starting with \socket\ */
1726 Copy( "\\socket", sun_ad.sun_path, off, char);
1727 Copy( pathname, sun_ad.sun_path + off, len, char );
1728
1729 s = sun_ad.sun_path + off - 1;
1730 e = s + len + 1;
1731 while (++s < e)
1732 if (*s = '/')
1733 *s = '\\';
1734 }
1735# else /* !( defined OS2 ) */
20408e3c 1736 Copy( pathname, sun_ad.sun_path, len, char );
202975e6 1737# endif
79cb57f6 1738 ST(0) = sv_2mortal(newSVpvn((char *)&sun_ad, sizeof sun_ad));
25f94b33
AD
1739#else
1740 ST(0) = (SV *) not_here("pack_sockaddr_un");
1741#endif
1742
4633a7c4
LW
1743 }
1744
1745void
1746unpack_sockaddr_un(sun_sv)
1747 SV * sun_sv
f13e1b2f 1748 CODE:
4633a7c4 1749 {
25f94b33 1750#ifdef I_SYS_UN
4633a7c4 1751 struct sockaddr_un addr;
fcdb74fc
TB
1752 STRLEN sockaddrlen;
1753 char * sun_ad = SvPV(sun_sv,sockaddrlen);
1754 char * e;
36902e12
RG
1755# ifndef __linux__
1756 /* On Linux sockaddrlen on sockets returned by accept, recvfrom,
1757 getpeername and getsockname is not equal to sizeof(addr). */
4633a7c4
LW
1758 if (sockaddrlen != sizeof(addr)) {
1759 croak("Bad arg length for %s, length is %d, should be %d",
1760 "Socket::unpack_sockaddr_un",
1761 sockaddrlen, sizeof(addr));
1762 }
36902e12 1763# endif
4633a7c4
LW
1764
1765 Copy( sun_ad, &addr, sizeof addr, char );
1766
1767 if ( addr.sun_family != AF_UNIX ) {
1768 croak("Bad address family for %s, got %d, should be %d",
1769 "Socket::unpack_sockaddr_un",
1770 addr.sun_family,
1771 AF_UNIX);
fcdb74fc
TB
1772 }
1773 e = addr.sun_path;
1774 while (*e && e < addr.sun_path + sizeof addr.sun_path)
1775 ++e;
79cb57f6 1776 ST(0) = sv_2mortal(newSVpvn(addr.sun_path, e - addr.sun_path));
25f94b33
AD
1777#else
1778 ST(0) = (SV *) not_here("unpack_sockaddr_un");
1779#endif
4633a7c4
LW
1780 }
1781
1782void
1783pack_sockaddr_in(port,ip_address)
2c129a17 1784 unsigned short port
8e07c86e
AD
1785 char * ip_address
1786 CODE:
1787 {
1788 struct sockaddr_in sin;
1789
1790 Zero( &sin, sizeof sin, char );
4633a7c4 1791 sin.sin_family = AF_INET;
8e07c86e
AD
1792 sin.sin_port = htons(port);
1793 Copy( ip_address, &sin.sin_addr, sizeof sin.sin_addr, char );
1794
79cb57f6 1795 ST(0) = sv_2mortal(newSVpvn((char *)&sin, sizeof sin));
8e07c86e
AD
1796 }
1797
1798void
1799unpack_sockaddr_in(sin_sv)
1800 SV * sin_sv
1801 PPCODE:
1802 {
1803 STRLEN sockaddrlen;
1804 struct sockaddr_in addr;
2c129a17 1805 unsigned short port;
8e07c86e
AD
1806 struct in_addr ip_address;
1807 char * sin = SvPV(sin_sv,sockaddrlen);
1808 if (sockaddrlen != sizeof(addr)) {
1809 croak("Bad arg length for %s, length is %d, should be %d",
1810 "Socket::unpack_sockaddr_in",
1811 sockaddrlen, sizeof(addr));
1812 }
8e07c86e 1813 Copy( sin, &addr,sizeof addr, char );
4633a7c4
LW
1814 if ( addr.sin_family != AF_INET ) {
1815 croak("Bad address family for %s, got %d, should be %d",
1816 "Socket::unpack_sockaddr_in",
1817 addr.sin_family,
1818 AF_INET);
1819 }
8e07c86e
AD
1820 port = ntohs(addr.sin_port);
1821 ip_address = addr.sin_addr;
1822
924508f0 1823 EXTEND(SP, 2);
2c129a17 1824 PUSHs(sv_2mortal(newSViv((IV) port)));
79cb57f6 1825 PUSHs(sv_2mortal(newSVpvn((char *)&ip_address,sizeof ip_address)));
8e07c86e 1826 }