1 /*
2
3 # Copyright 1995,2002 Spider Boardman.
4 # All rights reserved.
5 #
6 # Automatic licensing for this software is available. This software
7 # can be copied and used under the terms of the GNU Public License,
8 # version 1 or (at your option) any later version, or under the
9 # terms of the Artistic license. Both of these can be found with
10 # the Perl distribution, which this software is intended to augment.
11 #
12 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
13 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15
16 */
17
18 /*
19 * Can't rely on #ifdef to keep some compilers from griping about a #pragma
20 * which they don't recognize, so do it the old-fashioned way.
21 */
22
23 static char const rcsid[] = "@(#) $Id: Gen.xs,v 1.24 2002/04/10 11:05:58 spider Exp $";
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 #include "EXTERN.h"
29 #include "perl.h"
30 #include "XSUB.h"
31
32 #ifdef I_FCNTL
33 #include <fcntl.h>
34 #endif
35 #ifdef I_SYS_FILE
36 #include <sys/file.h>
37 #endif
38
39 #ifndef VMS
40 # ifdef I_SYS_TYPES
41 # include <sys/types.h>
42 # endif
43 #include <sys/socket.h>
44 #ifdef I_SYS_UN
45 #include <sys/un.h>
46 #endif
47 # ifdef I_NETINET_IN
48 # include <netinet/in.h>
49 # endif
50 #include <netdb.h>
51 #else
52 #include "sockadapt.h"
53 #endif
54
55 #include "netgen.h"
56
57 #ifdef BAD_TCP_MSS
58 # undef TCP_MSS
59 # define TCP_MSS TCP_MSS_IETF
60 #endif
61
62 #ifndef SHUT_RD
63 #ifdef O_RDONLY
64 #define SHUT_RD O_RDONLY
65 #else
66 #define SHUT_RD 0
67 #endif
68 #endif
69
70 #ifndef SHUT_WR
71 #ifdef O_WRONLY
72 #define SHUT_WR O_WRONLY
73 #else
74 #define SHUT_WR 1
75 #endif
76 #endif
77
78 #ifndef SHUT_RDWR
79 #ifdef O_RDWR
80 #define SHUT_RDWR O_RDWR
81 #else
82 #define SHUT_RDWR 2
83 #endif
84 #endif
85
86 #if !defined(PATCHLEVEL)
87 #include <patchlevel.h>
88 #endif
89 #if (PATCHLEVEL < 5)
90 #ifndef PL_sv_undef
91 #define PL_dowarn dowarn
92 #define PL_sv_no sv_no
93 #define PL_sv_undef sv_undef
94 #endif
95 #endif
96
97 #ifndef dTHX
98 #define dTHX dTHR
99 #define pTHX_
100 #define _pTHX
101 #define pTHX
102 #define aTHX
103 #define aTHX_
104 #define _aTHX
105 #define NV double
106 #endif
107
108 #ifndef dTHR
109 #define dTHR extern int Perl___notused
110 #endif
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 /* Just in case still don't have MIN and we need it for TCP_MSS.... */
117 #ifndef MIN
118 #define MIN(_A,_B) (((_A)<(_B))?(_A):(_B))
119 #endif
120
121 /* Default EAGAIN and EWOULDBLOCK from each other, punting to 0 if neither
122 * is available.
123 */
124 #ifndef EAGAIN
125 #ifndef EWOULDBLOCK
126 #define EWOULDBLOCK 0
127 #endif
128 #define EAGAIN EWOULDBLOCK
129 #endif
130 #ifndef EWOULDBLOCK
131 #define EWOULDBLOCK EAGAIN
132 #endif
133
134 static void
135 #ifdef CAN_PROTOTYPE
136 #define newmissing(_hv,_nm,_fl) S_newmissing(aTHX_ _hv, _nm, _fl)
S_newmissing(pTHX_ HV * missing,char * name,char * file)137 S_newmissing(pTHX_ HV *missing, char *name, char *file)
138 #else
139 newmissing(missing, name, file)
140 HV *missing;
141 char *name;
142 char *file;
143 #endif
144 {
145 STRLEN klen;
146 CV *cv;
147 klen = strlen(name);
148 (void) hv_fetch(missing, name, klen, TRUE);
149 cv = newXS(name, Perl_cv_undef, file); /* newSUB with no block */
150 sv_setsv((SV*)cv, &PL_sv_no); /* prototype it as "()" */
151 }
152
153 #ifndef CVf_CONST
154 /*
155 * cv_constant() exists so that the constant XSUBs will return their
156 * proper values even when not inlined.
157 */
158
159 static
XS(cv_constant)160 XS(cv_constant)
161 {
162 dXSARGS;
163 if (items != 0) {
164 ST(0) = sv_newmortal();
165 gv_efullname3(ST(0), CvGV(cv), Nullch);
166 croak("Usage: %s()", SvPVX(ST(0)));
167 }
168 if (CvSTART(cv)) {
169 ST(0) = ((SVOP*)CvSTART(cv))->op_sv;
170 XSRETURN(1);
171 }
172 XSRETURN_UNDEF;
173 }
174
175 /*
176 * Create a new 'constant' XSUB, suitable for inlining as a constant.
177 * Depends on the behaviour of cv_const_sv().
178 */
179
180 static void
181 #ifdef CAN_PROTOTYPE
182 #define newXSconst(_nm,_vsv,_fl) S_newXSconst(aTHX_ _nm, _vsv, _fl)
S_newXSconst(pTHX_ char * name,SV * valsv,char * file)183 S_newXSconst(pTHX_ char *name, SV *valsv, char *file)
184 #else
185 newXSconst(name, valsv, file)
186 char * name;
187 SV * valsv;
188 char * file;
189 #endif
190 {
191 CV *cv;
192 OP *svop;
193 cv = newXS(name, cv_constant, file);
194 sv_setsv((SV*)cv, &PL_sv_no); /* prototype it as () */
195 if (SvTEMP(valsv)) /* Don't let mortality get you down. */
196 SvREFCNT_inc(valsv); /* Give it an afterlife. :-> */
197 svop = newSVOP(OP_CONST, 0, valsv); /* does SvREADONLY_on */
198 svop->op_next = Nullop; /* terminate search in cv_const_sv() */
199 CvSTART(cv) = svop; /* voila! we're a constant! */
200 }
201 #else /* !defined CVf_CONST, now defined */
202 #define newXSconst(_nm,_vsv,_fl) Perl_newCONSTSUB(aTHX_ Nullhv, _nm, _vsv)
203 #endif /* defined CVf_CONST */
204
205 /*
206 * Auxiliary routines to create constant XSUBs of various types.
207 */
208
209 static void
210 #ifdef CAN_PROTOTYPE
211 #define newXSconstPV(_nm,_st,_fl) S_newXSconstPV(aTHX_ _nm, _st, _fl)
S_newXSconstPV(pTHX_ char * name,char * string,char * file)212 S_newXSconstPV(pTHX_ char *name, char *string, char *file)
213 #else
214 newXSconstPV(name, string, file)
215 char *name;
216 char *string;
217 char *file;
218 #endif
219 {
220 SV *valsv = newSVpv(string, strlen(string));
221 newXSconst(name, valsv, file);
222 }
223
224 static void
225 #ifdef CAN_PROTOTYPE
226 #define newXSconstPVN(_nm,_st,_ln,_fl) S_newXSconstPVN(aTHX_ _nm, _st, _ln, _fl)
S_newXSconstPVN(pTHX_ char * name,char * string,STRLEN len,char * file)227 S_newXSconstPVN(pTHX_ char *name, char *string, STRLEN len, char *file)
228 #else
229 newXSconstPVN(name, string, len, file)
230 char *name;
231 char *string;
232 STRLEN len;
233 char *file;
234 #endif
235 {
236 SV *valsv = newSVpv(string, len);
237 newXSconst(name, valsv, file);
238 }
239
240 static void
241 #ifdef CAN_PROTOTYPE
242 #define newXSconstIV(_nm,_iv,_fl) S_newXSconstIV(aTHX_ _nm, _iv, _fl)
S_newXSconstIV(pTHX_ char * name,IV ival,char * file)243 S_newXSconstIV(pTHX_ char *name, IV ival, char *file)
244 #else
245 newXSconstIV(name, ival, file)
246 char *name;
247 IV ival;
248 char *file;
249 #endif
250 {
251 newXSconst(name, newSViv(ival), file);
252 }
253
254 static void
255 #ifdef CAN_PROTOTYPE
256 #define newXSconstUV(_nm,_uv,_fl) S_newXSconstUV(aTHX_ _nm, _uv, _fl)
S_newXSconstUV(pTHX_ char * name,UV uval,char * file)257 S_newXSconstUV(pTHX_ char *name, UV uval, char *file)
258 #else
259 newXSconstUV(name, uval, file)
260 char * name;
261 UV uval;
262 char * file;
263 #endif
264 {
265 SV * valsv = newSVsv(&PL_sv_undef); /* missing newSVuv()! */
266 sv_setuv(valsv, uval);
267 newXSconst(name, valsv, file);
268 }
269
270 static void
271 #ifdef CAN_PROTOTYPE
272 #define newXSconstNV(_nm,_nv,_fl) S_newXSconstNV(aTHX_ _nm, _nv, _fl)
S_newXSconstNV(pTHX_ char * name,NV nval,char * file)273 S_newXSconstNV(pTHX_ char *name, NV nval, char *file)
274 #else
275 newXSconstNV(name, nval, file)
276 char * name;
277 double nval;
278 char * file;
279 #endif
280 {
281 newXSconst(name, newSVnv(nval), file);
282 }
283
284
285 typedef U32 sv_inaddr_t;
286 /*
287 * typemap helper for T_INADDR inputs
288 */
289
290 static sv_inaddr_t
291 #ifdef CAN_PROTOTYPE
292 #define sv2inaddr(_sv) S_sv2inaddr(aTHX_ _sv)
S_sv2inaddr(pTHX_ SV * sv)293 S_sv2inaddr(pTHX_ SV *sv)
294 #else
295 sv2inaddr(sv)
296 SV *sv;
297 #endif
298 {
299 struct in_addr ina;
300 char *cp;
301 STRLEN len;
302 if (!sv)
303 return 0;
304 if (SvGMAGICAL(sv)) {
305 mg_get(sv);
306 if (SvIOKp(sv))
307 return (sv_inaddr_t)SvUVX(sv);
308 if (SvNOKp(sv))
309 return (sv_inaddr_t)U_V(SvNVX(sv));
310 if (!SvPOKp(sv) || SvCUR(sv) != sizeof ina)
311 return (sv_inaddr_t)sv_2uv(sv);
312 }
313 else if (SvROK(sv))
314 return (sv_inaddr_t)sv_2uv(sv);
315 else if (SvNIOK(sv)) {
316 if (SvIOK(sv))
317 return (sv_inaddr_t)SvUVX(sv);
318 return (sv_inaddr_t)U_V(SvNVX(sv));
319 }
320 else if (!SvPOK(sv) || SvCUR(sv) != sizeof ina)
321 return (sv_inaddr_t)sv_2uv(sv);
322 /* Here for apparent inaddr's, perhaps from unpack_sockaddr_in(). */
323 cp = SvPV(sv,len);
324 Copy(cp, (char*)&ina, len, char);
325 return (sv_inaddr_t)ntohl(ina.s_addr);
326 }
327
328
329 /*
330 * In the XS sections which follow, the sections with f_?c_ prefixes
331 * are generated from the list of exportable constants.
332 */
333
334 MODULE = Net::Gen PACKAGE = Net::Gen
335
336 PROTOTYPES: ENABLE
337
338 BOOT:
339 {
340 HV *missing = perl_get_hv("Net::Gen::_missing", GV_ADDMULTI);
341
342
343 MODULE = Net::Gen PACKAGE = Net::TCP PREFIX = f_uc_
344
345 BOOT:
346 newXSconstUV("Net::TCP::TCPOPT_EOL", TCPOPT_EOL, file);
347 newXSconstUV("Net::TCP::TCPOPT_MAXSEG", TCPOPT_MAXSEG, file);
348 newXSconstUV("Net::TCP::TCPOPT_NOP", TCPOPT_NOP, file);
349 newXSconstUV("Net::TCP::TCPOPT_WINDOW", TCPOPT_WINDOW, file);
350 #ifdef TCP_MAXSEG
351 newXSconstUV("Net::TCP::TCP_MAXSEG", TCP_MAXSEG, file);
352 #else
353 newmissing(missing, "Net::TCP::TCP_MAXSEG", file);
354 #endif
355 newXSconstUV("Net::TCP::TCP_MAXWIN", TCP_MAXWIN, file);
356 newXSconstUV("Net::TCP::TCP_MAX_WINSHIFT", TCP_MAX_WINSHIFT, file);
357 newXSconstUV("Net::TCP::TCP_MSS", TCP_MSS, file);
358 #ifdef TCP_NODELAY
359 newXSconstUV("Net::TCP::TCP_NODELAY", TCP_NODELAY, file);
360 #else
361 newmissing(missing, "Net::TCP::TCP_NODELAY", file);
362 #endif
363 #ifdef TCP_RPTR2RXT
364 newXSconstUV("Net::TCP::TCP_RPTR2RXT", TCP_RPTR2RXT, file);
365 #else
366 newmissing(missing, "Net::TCP::TCP_RPTR2RXT", file);
367 #endif
368 newXSconstUV("Net::TCP::TH_ACK", TH_ACK, file);
369 newXSconstUV("Net::TCP::TH_FIN", TH_FIN, file);
370 newXSconstUV("Net::TCP::TH_PUSH", TH_PUSH, file);
371 newXSconstUV("Net::TCP::TH_RST", TH_RST, file);
372 newXSconstUV("Net::TCP::TH_SYN", TH_SYN, file);
373 newXSconstUV("Net::TCP::TH_URG", TH_URG, file);
374
375
376 MODULE = Net::Gen PACKAGE = Net::Inet PREFIX = f_uc_
377
378 BOOT:
379 newXSconstUV("Net::Inet::DEFTTL", DEFTTL, file);
380 newXSconstUV("Net::Inet::ICMP_ADVLENMIN", ICMP_ADVLENMIN, file);
381 newXSconstUV("Net::Inet::ICMP_ECHO", ICMP_ECHO, file);
382 newXSconstUV("Net::Inet::ICMP_ECHOREPLY", ICMP_ECHOREPLY, file);
383 newXSconstUV("Net::Inet::ICMP_IREQ", ICMP_IREQ, file);
384 newXSconstUV("Net::Inet::ICMP_IREQREPLY", ICMP_IREQREPLY, file);
385 newXSconstUV("Net::Inet::ICMP_MASKLEN", ICMP_MASKLEN, file);
386 newXSconstUV("Net::Inet::ICMP_MASKREPLY", ICMP_MASKREPLY, file);
387 newXSconstUV("Net::Inet::ICMP_MASKREQ", ICMP_MASKREQ, file);
388 newXSconstUV("Net::Inet::ICMP_MAXTYPE", ICMP_MAXTYPE, file);
389 newXSconstUV("Net::Inet::ICMP_MINLEN", ICMP_MINLEN, file);
390 newXSconstUV("Net::Inet::ICMP_PARAMPROB", ICMP_PARAMPROB, file);
391 newXSconstUV("Net::Inet::ICMP_REDIRECT", ICMP_REDIRECT, file);
392 newXSconstUV("Net::Inet::ICMP_REDIRECT_HOST", ICMP_REDIRECT_HOST, file);
393 newXSconstUV("Net::Inet::ICMP_REDIRECT_NET", ICMP_REDIRECT_NET, file);
394 newXSconstUV("Net::Inet::ICMP_REDIRECT_TOSHOST", ICMP_REDIRECT_TOSHOST, file);
395 newXSconstUV("Net::Inet::ICMP_REDIRECT_TOSNET", ICMP_REDIRECT_TOSNET, file);
396 newXSconstUV("Net::Inet::ICMP_SOURCEQUENCH", ICMP_SOURCEQUENCH, file);
397 newXSconstUV("Net::Inet::ICMP_TIMXCEED", ICMP_TIMXCEED, file);
398 newXSconstUV("Net::Inet::ICMP_TIMXCEED_INTRANS", ICMP_TIMXCEED_INTRANS, file);
399 newXSconstUV("Net::Inet::ICMP_TIMXCEED_REASS", ICMP_TIMXCEED_REASS, file);
400 newXSconstUV("Net::Inet::ICMP_TSLEN", ICMP_TSLEN, file);
401 newXSconstUV("Net::Inet::ICMP_TSTAMP", ICMP_TSTAMP, file);
402 newXSconstUV("Net::Inet::ICMP_TSTAMPREPLY", ICMP_TSTAMPREPLY, file);
403 newXSconstUV("Net::Inet::ICMP_UNREACH", ICMP_UNREACH, file);
404 newXSconstUV("Net::Inet::ICMP_UNREACH_HOST", ICMP_UNREACH_HOST, file);
405 newXSconstUV("Net::Inet::ICMP_UNREACH_NEEDFRAG", ICMP_UNREACH_NEEDFRAG, file);
406 newXSconstUV("Net::Inet::ICMP_UNREACH_NET", ICMP_UNREACH_NET, file);
407 newXSconstUV("Net::Inet::ICMP_UNREACH_PORT", ICMP_UNREACH_PORT, file);
408 newXSconstUV("Net::Inet::ICMP_UNREACH_PROTOCOL", ICMP_UNREACH_PROTOCOL, file);
409 newXSconstUV("Net::Inet::ICMP_UNREACH_SRCFAIL", ICMP_UNREACH_SRCFAIL, file);
410 newXSconstUV("Net::Inet::IN_CLASSA_HOST", IN_CLASSA_HOST, file);
411 newXSconstUV("Net::Inet::IN_CLASSA_MAX", IN_CLASSA_MAX, file);
412 newXSconstUV("Net::Inet::IN_CLASSA_NET", IN_CLASSA_NET, file);
413 newXSconstUV("Net::Inet::IN_CLASSA_NSHIFT", IN_CLASSA_NSHIFT, file);
414 #ifdef IN_CLASSA_SUBHOST
415 newXSconstUV("Net::Inet::IN_CLASSA_SUBHOST", IN_CLASSA_SUBHOST, file);
416 #else
417 newmissing(missing, "Net::Inet::IN_CLASSA_SUBHOST", file);
418 #endif
419 #ifdef IN_CLASSA_SUBNET
420 newXSconstUV("Net::Inet::IN_CLASSA_SUBNET", IN_CLASSA_SUBNET, file);
421 #else
422 newmissing(missing, "Net::Inet::IN_CLASSA_SUBNET", file);
423 #endif
424 #ifdef IN_CLASSA_SUBNSHIFT
425 newXSconstUV("Net::Inet::IN_CLASSA_SUBNSHIFT", IN_CLASSA_SUBNSHIFT, file);
426 #else
427 newmissing(missing, "Net::Inet::IN_CLASSA_SUBNSHIFT", file);
428 #endif
429 newXSconstUV("Net::Inet::IN_CLASSB_HOST", IN_CLASSB_HOST, file);
430 newXSconstUV("Net::Inet::IN_CLASSB_MAX", IN_CLASSB_MAX, file);
431 newXSconstUV("Net::Inet::IN_CLASSB_NET", IN_CLASSB_NET, file);
432 newXSconstUV("Net::Inet::IN_CLASSB_NSHIFT", IN_CLASSB_NSHIFT, file);
433 #ifdef IN_CLASSB_SUBHOST
434 newXSconstUV("Net::Inet::IN_CLASSB_SUBHOST", IN_CLASSB_SUBHOST, file);
435 #else
436 newmissing(missing, "Net::Inet::IN_CLASSB_SUBHOST", file);
437 #endif
438 #ifdef IN_CLASSB_SUBNET
439 newXSconstUV("Net::Inet::IN_CLASSB_SUBNET", IN_CLASSB_SUBNET, file);
440 #else
441 newmissing(missing, "Net::Inet::IN_CLASSB_SUBNET", file);
442 #endif
443 #ifdef IN_CLASSB_SUBNSHIFT
444 newXSconstUV("Net::Inet::IN_CLASSB_SUBNSHIFT", IN_CLASSB_SUBNSHIFT, file);
445 #else
446 newmissing(missing, "Net::Inet::IN_CLASSB_SUBNSHIFT", file);
447 #endif
448 newXSconstUV("Net::Inet::IN_CLASSC_HOST", IN_CLASSC_HOST, file);
449 newXSconstUV("Net::Inet::IN_CLASSC_MAX", IN_CLASSC_MAX, file);
450 newXSconstUV("Net::Inet::IN_CLASSC_NET", IN_CLASSC_NET, file);
451 newXSconstUV("Net::Inet::IN_CLASSC_NSHIFT", IN_CLASSC_NSHIFT, file);
452 newXSconstUV("Net::Inet::IN_CLASSD_HOST", IN_CLASSD_HOST, file);
453 newXSconstUV("Net::Inet::IN_CLASSD_NET", IN_CLASSD_NET, file);
454 newXSconstUV("Net::Inet::IN_CLASSD_NSHIFT", IN_CLASSD_NSHIFT, file);
455 newXSconstUV("Net::Inet::IN_LOOPBACKNET", IN_LOOPBACKNET, file);
456 #ifdef IPFRAGTTL
457 newXSconstUV("Net::Inet::IPFRAGTTL", IPFRAGTTL, file);
458 #else
459 newmissing(missing, "Net::Inet::IPFRAGTTL", file);
460 #endif
461 newXSconstUV("Net::Inet::IPOPT_CIPSO", IPOPT_CIPSO, file);
462 newXSconstUV("Net::Inet::IPOPT_CONTROL", IPOPT_CONTROL, file);
463 newXSconstUV("Net::Inet::IPOPT_DEBMEAS", IPOPT_DEBMEAS, file);
464 newXSconstUV("Net::Inet::IPOPT_EOL", IPOPT_EOL, file);
465 newXSconstUV("Net::Inet::IPOPT_LSRR", IPOPT_LSRR, file);
466 newXSconstUV("Net::Inet::IPOPT_MINOFF", IPOPT_MINOFF, file);
467 newXSconstUV("Net::Inet::IPOPT_NOP", IPOPT_NOP, file);
468 newXSconstUV("Net::Inet::IPOPT_OFFSET", IPOPT_OFFSET, file);
469 newXSconstUV("Net::Inet::IPOPT_OLEN", IPOPT_OLEN, file);
470 newXSconstUV("Net::Inet::IPOPT_OPTVAL", IPOPT_OPTVAL, file);
471 newXSconstUV("Net::Inet::IPOPT_RESERVED1", IPOPT_RESERVED1, file);
472 newXSconstUV("Net::Inet::IPOPT_RESERVED2", IPOPT_RESERVED2, file);
473 newXSconstUV("Net::Inet::IPOPT_RIPSO_AUX", IPOPT_RIPSO_AUX, file);
474 newXSconstUV("Net::Inet::IPOPT_RR", IPOPT_RR, file);
475 newXSconstUV("Net::Inet::IPOPT_SATID", IPOPT_SATID, file);
476 newXSconstUV("Net::Inet::IPOPT_SECURITY", IPOPT_SECURITY, file);
477 newXSconstUV("Net::Inet::IPOPT_SECUR_CONFID", IPOPT_SECUR_CONFID, file);
478 newXSconstUV("Net::Inet::IPOPT_SECUR_EFTO", IPOPT_SECUR_EFTO, file);
479 newXSconstUV("Net::Inet::IPOPT_SECUR_MMMM", IPOPT_SECUR_MMMM, file);
480 newXSconstUV("Net::Inet::IPOPT_SECUR_RESTR", IPOPT_SECUR_RESTR, file);
481 newXSconstUV("Net::Inet::IPOPT_SECUR_SECRET", IPOPT_SECUR_SECRET, file);
482 newXSconstUV("Net::Inet::IPOPT_SECUR_TOPSECRET", IPOPT_SECUR_TOPSECRET, file);
483 newXSconstUV("Net::Inet::IPOPT_SECUR_UNCLASS", IPOPT_SECUR_UNCLASS, file);
484 newXSconstUV("Net::Inet::IPOPT_SSRR", IPOPT_SSRR, file);
485 newXSconstUV("Net::Inet::IPOPT_TS", IPOPT_TS, file);
486 newXSconstUV("Net::Inet::IPOPT_TS_PRESPEC", IPOPT_TS_PRESPEC, file);
487 newXSconstUV("Net::Inet::IPOPT_TS_TSANDADDR", IPOPT_TS_TSANDADDR, file);
488 newXSconstUV("Net::Inet::IPOPT_TS_TSONLY", IPOPT_TS_TSONLY, file);
489 newXSconstUV("Net::Inet::IPPORT_RESERVED", IPPORT_RESERVED, file);
490 #ifdef IPPORT_TIMESERVER
491 newXSconstUV("Net::Inet::IPPORT_TIMESERVER", IPPORT_TIMESERVER, file);
492 #else
493 newmissing(missing, "Net::Inet::IPPORT_TIMESERVER", file);
494 #endif
495 newXSconstUV("Net::Inet::IPPORT_USERRESERVED", IPPORT_USERRESERVED, file);
496 newXSconstUV("Net::Inet::IPPROTO_EGP", IPPROTO_EGP, file);
497 newXSconstUV("Net::Inet::IPPROTO_EON", IPPROTO_EON, file);
498 newXSconstUV("Net::Inet::IPPROTO_GGP", IPPROTO_GGP, file);
499 newXSconstUV("Net::Inet::IPPROTO_HELLO", IPPROTO_HELLO, file);
500 newXSconstUV("Net::Inet::IPPROTO_ICMP", IPPROTO_ICMP, file);
501 newXSconstUV("Net::Inet::IPPROTO_IDP", IPPROTO_IDP, file);
502 newXSconstUV("Net::Inet::IPPROTO_IGMP", IPPROTO_IGMP, file);
503 newXSconstUV("Net::Inet::IPPROTO_IP", IPPROTO_IP, file);
504 newXSconstUV("Net::Inet::IPPROTO_IPIP", IPPROTO_IPIP, file);
505 newXSconstUV("Net::Inet::IPPROTO_MAX", IPPROTO_MAX, file);
506 newXSconstUV("Net::Inet::IPPROTO_PUP", IPPROTO_PUP, file);
507 newXSconstUV("Net::Inet::IPPROTO_RAW", IPPROTO_RAW, file);
508 newXSconstUV("Net::Inet::IPPROTO_RSVP", IPPROTO_RSVP, file);
509 newXSconstUV("Net::Inet::IPPROTO_TCP", IPPROTO_TCP, file);
510 newXSconstUV("Net::Inet::IPPROTO_TP", IPPROTO_TP, file);
511 newXSconstUV("Net::Inet::IPPROTO_UDP", IPPROTO_UDP, file);
512 newXSconstUV("Net::Inet::IPTOS_LOWDELAY", IPTOS_LOWDELAY, file);
513 newXSconstUV("Net::Inet::IPTOS_PREC_CRITIC_ECP", IPTOS_PREC_CRITIC_ECP, file);
514 newXSconstUV("Net::Inet::IPTOS_PREC_FLASH", IPTOS_PREC_FLASH, file);
515 newXSconstUV("Net::Inet::IPTOS_PREC_FLASHOVERRIDE", IPTOS_PREC_FLASHOVERRIDE, file);
516 newXSconstUV("Net::Inet::IPTOS_PREC_IMMEDIATE", IPTOS_PREC_IMMEDIATE, file);
517 newXSconstUV("Net::Inet::IPTOS_PREC_INTERNETCONTROL", IPTOS_PREC_INTERNETCONTROL, file);
518 newXSconstUV("Net::Inet::IPTOS_PREC_NETCONTROL", IPTOS_PREC_NETCONTROL, file);
519 newXSconstUV("Net::Inet::IPTOS_PREC_PRIORITY", IPTOS_PREC_PRIORITY, file);
520 newXSconstUV("Net::Inet::IPTOS_PREC_ROUTINE", IPTOS_PREC_ROUTINE, file);
521 newXSconstUV("Net::Inet::IPTOS_RELIABILITY", IPTOS_RELIABILITY, file);
522 newXSconstUV("Net::Inet::IPTOS_THROUGHPUT", IPTOS_THROUGHPUT, file);
523 newXSconstUV("Net::Inet::IPTTLDEC", IPTTLDEC, file);
524 newXSconstUV("Net::Inet::IPVERSION", IPVERSION, file);
525 #ifdef IP_ADD_MEMBERSHIP
526 newXSconstUV("Net::Inet::IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP, file);
527 #else
528 newmissing(missing, "Net::Inet::IP_ADD_MEMBERSHIP", file);
529 #endif
530 #ifdef IP_DEFAULT_MULTICAST_LOOP
531 newXSconstUV("Net::Inet::IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP, file);
532 #else
533 newmissing(missing, "Net::Inet::IP_DEFAULT_MULTICAST_LOOP", file);
534 #endif
535 #ifdef IP_DEFAULT_MULTICAST_TTL
536 newXSconstUV("Net::Inet::IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL, file);
537 #else
538 newmissing(missing, "Net::Inet::IP_DEFAULT_MULTICAST_TTL", file);
539 #endif
540 newXSconstUV("Net::Inet::IP_DF", IP_DF, file);
541 #ifdef IP_DROP_MEMBERSHIP
542 newXSconstUV("Net::Inet::IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP, file);
543 #else
544 newmissing(missing, "Net::Inet::IP_DROP_MEMBERSHIP", file);
545 #endif
546 #ifdef IP_HDRINCL
547 newXSconstUV("Net::Inet::IP_HDRINCL", IP_HDRINCL, file);
548 #else
549 newmissing(missing, "Net::Inet::IP_HDRINCL", file);
550 #endif
551 newXSconstUV("Net::Inet::IP_MAXPACKET", IP_MAXPACKET, file);
552 #ifdef IP_MAX_MEMBERSHIPS
553 newXSconstUV("Net::Inet::IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS, file);
554 #else
555 newmissing(missing, "Net::Inet::IP_MAX_MEMBERSHIPS", file);
556 #endif
557 newXSconstUV("Net::Inet::IP_MF", IP_MF, file);
558 newXSconstUV("Net::Inet::IP_MSS", IP_MSS, file);
559 #ifdef IP_MULTICAST_IF
560 newXSconstUV("Net::Inet::IP_MULTICAST_IF", IP_MULTICAST_IF, file);
561 #else
562 newmissing(missing, "Net::Inet::IP_MULTICAST_IF", file);
563 #endif
564 #ifdef IP_MULTICAST_LOOP
565 newXSconstUV("Net::Inet::IP_MULTICAST_LOOP", IP_MULTICAST_LOOP, file);
566 #else
567 newmissing(missing, "Net::Inet::IP_MULTICAST_LOOP", file);
568 #endif
569 #ifdef IP_MULTICAST_TTL
570 newXSconstUV("Net::Inet::IP_MULTICAST_TTL", IP_MULTICAST_TTL, file);
571 #else
572 newmissing(missing, "Net::Inet::IP_MULTICAST_TTL", file);
573 #endif
574 #ifdef IP_OPTIONS
575 newXSconstUV("Net::Inet::IP_OPTIONS", IP_OPTIONS, file);
576 #else
577 newmissing(missing, "Net::Inet::IP_OPTIONS", file);
578 #endif
579 #ifdef IP_RECVDSTADDR
580 newXSconstUV("Net::Inet::IP_RECVDSTADDR", IP_RECVDSTADDR, file);
581 #else
582 newmissing(missing, "Net::Inet::IP_RECVDSTADDR", file);
583 #endif
584 #ifdef IP_RECVOPTS
585 newXSconstUV("Net::Inet::IP_RECVOPTS", IP_RECVOPTS, file);
586 #else
587 newmissing(missing, "Net::Inet::IP_RECVOPTS", file);
588 #endif
589 #ifdef IP_RECVRETOPTS
590 newXSconstUV("Net::Inet::IP_RECVRETOPTS", IP_RECVRETOPTS, file);
591 #else
592 newmissing(missing, "Net::Inet::IP_RECVRETOPTS", file);
593 #endif
594 #ifdef IP_RETOPTS
595 newXSconstUV("Net::Inet::IP_RETOPTS", IP_RETOPTS, file);
596 #else
597 newmissing(missing, "Net::Inet::IP_RETOPTS", file);
598 #endif
599 #ifdef IP_TOS
600 newXSconstUV("Net::Inet::IP_TOS", IP_TOS, file);
601 #else
602 newmissing(missing, "Net::Inet::IP_TOS", file);
603 #endif
604 #ifdef IP_TTL
605 newXSconstUV("Net::Inet::IP_TTL", IP_TTL, file);
606 #else
607 newmissing(missing, "Net::Inet::IP_TTL", file);
608 #endif
609 newXSconstUV("Net::Inet::MAXTTL", MAXTTL, file);
610 newXSconstUV("Net::Inet::MAX_IPOPTLEN", MAX_IPOPTLEN, file);
611 newXSconstUV("Net::Inet::MINTTL", MINTTL, file);
612 #ifdef SUBNETSHIFT
613 newXSconstUV("Net::Inet::SUBNETSHIFT", SUBNETSHIFT, file);
614 #else
615 newmissing(missing, "Net::Inet::SUBNETSHIFT", file);
616 #endif
617 {
618 struct in_addr ina;
619 ina.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
620 newXSconstPVN("Net::Inet::INADDR_ALLHOSTS_GROUP",
621 (char*)&ina, sizeof ina, file);
622 ina.s_addr = htonl(INADDR_ALLRTRS_GROUP);
623 newXSconstPVN("Net::Inet::INADDR_ALLRTRS_GROUP",
624 (char*)&ina, sizeof ina, file);
625 ina.s_addr = htonl(INADDR_MAX_LOCAL_GROUP);
626 newXSconstPVN("Net::Inet::INADDR_MAX_LOCAL_GROUP",
627 (char*)&ina, sizeof ina, file);
628 ina.s_addr = htonl(INADDR_UNSPEC_GROUP);
629 newXSconstPVN("Net::Inet::INADDR_UNSPEC_GROUP",
630 (char*)&ina, sizeof ina, file);
631 }
632
633
634 MODULE = Net::Gen PACKAGE = Net::Inet
635
636 bool
637 IN_CLASSA(hostaddr)
638 sv_inaddr_t hostaddr
639
640 bool
641 IN_CLASSB(hostaddr)
642 sv_inaddr_t hostaddr
643
644 bool
645 IN_CLASSC(hostaddr)
646 sv_inaddr_t hostaddr
647
648 bool
649 IN_CLASSD(hostaddr)
650 sv_inaddr_t hostaddr
651
652 bool
653 IN_MULTICAST(hostaddr)
654 sv_inaddr_t hostaddr
655
656 bool
657 IN_EXPERIMENTAL(hostaddr)
658 sv_inaddr_t hostaddr
659
660 bool
661 IN_BADCLASS(hostaddr)
662 sv_inaddr_t hostaddr
663
664 bool
665 IPOPT_COPIED(ipopt)
666 U8 ipopt
667
668 U8
669 IPOPT_CLASS(ipopt)
670 U8 ipopt
671
672 U8
673 IPOPT_NUMBER(ipopt)
674 U8 ipopt
675
676 bool
677 ICMP_INFOTYPE(icmp_code)
678 U8 icmp_code
679
680 void
681 _pack_sockaddr_in(family,port,address)
682 U8 family
683 U16 port
684 SV * address
685 PREINIT:
686 struct sockaddr_in sin;
687 char * adata;
688 STRLEN adlen;
689 PPCODE:
690 Zero(&sin, sizeof sin, char);
691 sin.sin_family = family;
692 adata = SvPV(address, adlen);
693 sin.sin_port = htons(port);
694 if (adlen == sizeof sin.sin_addr) {
695 Copy(adata, &sin.sin_addr, sizeof sin.sin_addr, char);
696 ST(0) = sv_2mortal(newSVpv((char*)&sin, sizeof sin));
697 }
698 else {
699 SV *adsv = sv_2mortal(newSVpv((char*)&sin,
700 STRUCT_OFFSET(struct sockaddr_in,
701 sin_addr)));
702 sv_catpvn(adsv, adata, adlen);
703 ST(0) = adsv;
704 }
705 XSRETURN(1);
706
707 void
708 unpack_sockaddr_in(sad)
709 SV * sad
710 PREINIT:
711 char * cp;
712 struct sockaddr_in sin;
713 STRLEN len;
714 PPCODE:
715 if ((cp = SvPV(sad, len)) != (char*)0 && len >= sizeof sin) {
716 U16 family;
717 U16 port;
718 char * adata;
719 STRLEN addrlen;
720
721 Copy(cp, &sin, sizeof sin, char);
722 family = sin.sin_family;
723 if (family > 255) { /* 4.4BSD anyone? */
724 U8 famlen1, famlen2;
725 famlen1 = family & 255;
726 famlen2 = (family >> 8) & 255;
727 if (famlen1 == famlen2) {
728 family = famlen1;
729 }
730 else if (famlen1 == len) {
731 family = famlen2;
732 }
733 else if (famlen2 == len) {
734 family = famlen1;
735 }
736 else if (famlen1 == AF_INET || famlen2 == AF_INET) {
737 family = AF_INET;
738 }
739 else if (famlen1 < famlen2) {
740 family = famlen1;
741 }
742 else {
743 family = famlen2;
744 }
745 }
746 port = ntohs(sin.sin_port);
747 /* now work on the address */
748 cp += STRUCT_OFFSET(struct sockaddr_in, sin_addr);
749 addrlen = len - STRUCT_OFFSET(struct sockaddr_in, sin_addr);
750 if (family == AF_INET && len == sizeof sin)
751 addrlen = sizeof sin.sin_addr;
752
753 EXTEND(sp,3);
754 PUSHs(sv_2mortal(newSViv((IV)family)));
755 PUSHs(sv_2mortal(newSViv((IV)port)));
756 PUSHs(sv_2mortal(newSVpv(cp, addrlen)));
757 }
758
759
760 MODULE = Net::Gen PACKAGE = Net::Gen PREFIX = f_ic_
761
762 BOOT:
763 #ifdef EOF_NONBLOCK
764 #define f_ic_EOF_NONBLOCK 1
765 #else
766 #define f_ic_EOF_NONBLOCK 0
767 #endif
768 newXSconstIV("Net::Gen::EOF_NONBLOCK", f_ic_EOF_NONBLOCK, file);
769 #ifdef RD_NODATA
770 newXSconstIV("Net::Gen::RD_NODATA", RD_NODATA, file);
771 #else
772 newmissing(missing, "Net::Gen::RD_NODATA", file);
773 #endif
774 newXSconstIV("Net::Gen::SHUT_RD", SHUT_RD, file);
775 newXSconstIV("Net::Gen::SHUT_WR", SHUT_WR, file);
776 newXSconstIV("Net::Gen::SHUT_RDWR", SHUT_RDWR, file);
777
778
779 MODULE = Net::Gen PACKAGE = Net::Gen PREFIX = f_uc_
780
781 BOOT:
782 #ifdef VAL_O_NONBLOCK
783 newXSconstUV("Net::Gen::VAL_O_NONBLOCK", VAL_O_NONBLOCK, file);
784 #else
785 newmissing(missing, "Net::Gen::VAL_O_NONBLOCK", file);
786 #endif
787 #ifdef VAL_EAGAIN
788 newXSconstUV("Net::Gen::VAL_EAGAIN", VAL_EAGAIN, file);
789 #else
790 newmissing(missing, "Net::Gen::VAL_EAGAIN", file);
791 #endif
792 newXSconstUV("Net::Gen::MSG_OOB", MSG_OOB, file);
793 #ifdef SO_ACCEPTCONN
794 newXSconstUV("Net::Gen::SO_ACCEPTCONN", SO_ACCEPTCONN, file);
795 #else
796 newmissing(missing, "Net::Gen::SO_ACCEPTCONN", file);
797 #endif
798 #ifdef SO_BROADCAST
799 newXSconstUV("Net::Gen::SO_BROADCAST", SO_BROADCAST, file);
800 #else
801 newmissing(missing, "Net::Gen::SO_BROADCAST", file);
802 #endif
803 #ifdef SO_DEBUG
804 newXSconstUV("Net::Gen::SO_DEBUG", SO_DEBUG, file);
805 #else
806 newmissing(missing, "Net::Gen::SO_DEBUG", file);
807 #endif
808 #ifdef SO_DONTROUTE
809 newXSconstUV("Net::Gen::SO_DONTROUTE", SO_DONTROUTE, file);
810 #else
811 newmissing(missing, "Net::Gen::SO_DONTROUTE", file);
812 #endif
813 #ifdef SO_ERROR
814 newXSconstUV("Net::Gen::SO_ERROR", SO_ERROR, file);
815 #else
816 newmissing(missing, "Net::Gen::SO_ERROR", file);
817 #endif
818 #ifdef SO_EXPANDED_RIGHTS
819 newXSconstUV("Net::Gen::SO_EXPANDED_RIGHTS", SO_EXPANDED_RIGHTS, file);
820 #else
821 newmissing(missing, "Net::Gen::SO_EXPANDED_RIGHTS", file);
822 #endif
823 #ifdef SO_KEEPALIVE
824 newXSconstUV("Net::Gen::SO_KEEPALIVE", SO_KEEPALIVE, file);
825 #else
826 newmissing(missing, "Net::Gen::SO_KEEPALIVE", file);
827 #endif
828 #ifdef SO_OOBINLINE
829 newXSconstUV("Net::Gen::SO_OOBINLINE", SO_OOBINLINE, file);
830 #else
831 newmissing(missing, "Net::Gen::SO_OOBINLINE", file);
832 #endif
833 #ifdef SO_PAIRABLE
834 newXSconstUV("Net::Gen::SO_PAIRABLE", SO_PAIRABLE, file);
835 #else
836 newmissing(missing, "Net::Gen::SO_PAIRABLE", file);
837 #endif
838 #ifdef SO_REUSEADDR
839 newXSconstUV("Net::Gen::SO_REUSEADDR", SO_REUSEADDR, file);
840 #else
841 newmissing(missing, "Net::Gen::SO_REUSEADDR", file);
842 #endif
843 #ifdef SO_REUSEPORT
844 newXSconstUV("Net::Gen::SO_REUSEPORT", SO_REUSEPORT, file);
845 #else
846 newmissing(missing, "Net::Gen::SO_REUSEPORT", file);
847 #endif
848 #ifdef SO_USELOOPBACK
849 newXSconstUV("Net::Gen::SO_USELOOPBACK", SO_USELOOPBACK, file);
850 #else
851 newmissing(missing, "Net::Gen::SO_USELOOPBACK", file);
852 #endif
853 #ifdef SO_XSE
854 newXSconstUV("Net::Gen::SO_XSE", SO_XSE, file);
855 #else
856 newmissing(missing, "Net::Gen::SO_XSE", file);
857 #endif
858 #ifdef SO_RCVBUF
859 newXSconstUV("Net::Gen::SO_RCVBUF", SO_RCVBUF, file);
860 #else
861 newmissing(missing, "Net::Gen::SO_RCVBUF", file);
862 #endif
863 #ifdef SO_SNDBUF
864 newXSconstUV("Net::Gen::SO_SNDBUF", SO_SNDBUF, file);
865 #else
866 newmissing(missing, "Net::Gen::SO_SNDBUF", file);
867 #endif
868 #ifdef SO_RCVTIMEO
869 newXSconstUV("Net::Gen::SO_RCVTIMEO", SO_RCVTIMEO, file);
870 #else
871 newmissing(missing, "Net::Gen::SO_RCVTIMEO", file);
872 #endif
873 #ifdef SO_SNDTIMEO
874 newXSconstUV("Net::Gen::SO_SNDTIMEO", SO_SNDTIMEO, file);
875 #else
876 newmissing(missing, "Net::Gen::SO_SNDTIMEO", file);
877 #endif
878 #ifdef SO_RCVLOWAT
879 newXSconstUV("Net::Gen::SO_RCVLOWAT", SO_RCVLOWAT, file);
880 #else
881 newmissing(missing, "Net::Gen::SO_RCVLOWAT", file);
882 #endif
883 #ifdef SO_SNDLOWAT
884 newXSconstUV("Net::Gen::SO_SNDLOWAT", SO_SNDLOWAT, file);
885 #else
886 newmissing(missing, "Net::Gen::SO_SNDLOWAT", file);
887 #endif
888 #ifdef SO_TYPE
889 newXSconstUV("Net::Gen::SO_TYPE", SO_TYPE, file);
890 #else
891 newmissing(missing, "Net::Gen::SO_TYPE", file);
892 #endif
893 #ifdef SO_STATE
894 newXSconstUV("Net::Gen::SO_STATE", SO_STATE, file);
895 #else
896 newmissing(missing, "Net::Gen::SO_STATE", file);
897 #endif
898 #ifdef SO_FAMILY
899 newXSconstUV("Net::Gen::SO_FAMILY", SO_FAMILY, file);
900 #else
901 newmissing(missing, "Net::Gen::SO_FAMILY", file);
902 #endif
903 #ifdef SO_LINGER
904 newXSconstUV("Net::Gen::SO_LINGER", SO_LINGER, file);
905 #else
906 newmissing(missing, "Net::Gen::SO_LINGER", file);
907 #endif
908 #ifdef SOL_SOCKET
909 newXSconstUV("Net::Gen::SOL_SOCKET", SOL_SOCKET, file);
910 #else
911 newmissing(missing, "Net::Gen::SOL_SOCKET", file);
912 #endif
913 #ifdef SOCK_STREAM
914 newXSconstUV("Net::Gen::SOCK_STREAM", SOCK_STREAM, file);
915 #else
916 newmissing(missing, "Net::Gen::SOCK_STREAM", file);
917 #endif
918 #ifdef SOCK_DGRAM
919 newXSconstUV("Net::Gen::SOCK_DGRAM", SOCK_DGRAM, file);
920 #else
921 newmissing(missing, "Net::Gen::SOCK_DGRAM", file);
922 #endif
923 #ifdef SOCK_RAW
924 newXSconstUV("Net::Gen::SOCK_RAW", SOCK_RAW, file);
925 #else
926 newmissing(missing, "Net::Gen::SOCK_RAW", file);
927 #endif
928 #ifdef SOCK_RDM
929 newXSconstUV("Net::Gen::SOCK_RDM", SOCK_RDM, file);
930 #else
931 newmissing(missing, "Net::Gen::SOCK_RDM", file);
932 #endif
933 #ifdef SOCK_SEQPACKET
934 newXSconstUV("Net::Gen::SOCK_SEQPACKET", SOCK_SEQPACKET, file);
935 #else
936 newmissing(missing, "Net::Gen::SOCK_SEQPACKET", file);
937 #endif
938 #ifndef AF_UNSPEC
939 #define AF_UNSPEC 0
940 #endif
941 newXSconstUV("Net::Gen::AF_UNSPEC", AF_UNSPEC, file);
942 #ifndef PF_UNSPEC
943 #define PF_UNSPEC 0
944 #endif
945 newXSconstUV("Net::Gen::PF_UNSPEC", PF_UNSPEC, file);
946 #ifdef AF_INET
947 newXSconstUV("Net::Gen::AF_INET", AF_INET, file);
948 #else
949 newmissing(missing, "Net::Gen::AF_INET", file);
950 #endif
951 #ifdef PF_INET
952 newXSconstUV("Net::Gen::PF_INET", PF_INET, file);
953 #else
954 newmissing(missing, "Net::Gen::PF_INET", file);
955 #endif
956 #ifndef AF_UNIX
957 #ifdef AF_LOCAL
958 #define AF_UNIX AF_LOCAL
959 #endif
960 #endif
961 #ifndef PF_UNIX
962 #ifdef PF_LOCAL
963 #define PF_UNIX PF_LOCAL
964 #endif
965 #endif
966 #ifndef AF_LOCAL
967 #ifdef AF_UNIX
968 #define AF_LOCAL AF_UNIX
969 #endif
970 #endif
971 #ifndef PF_LOCAL
972 #ifdef PF_UNIX
973 #define PF_LOCAL PF_UNIX
974 #endif
975 #endif
976 #ifdef AF_UNIX
977 newXSconstUV("Net::Gen::AF_UNIX", AF_UNIX, file);
978 #else
979 newmissing(missing, "Net::Gen::AF_UNIX", file);
980 #endif
981 #ifdef PF_UNIX
982 newXSconstUV("Net::Gen::PF_UNIX", PF_UNIX, file);
983 #else
984 newmissing(missing, "Net::Gen::PF_UNIX", file);
985 #endif
986 #ifdef AF_LOCAL
987 newXSconstUV("Net::Gen::AF_LOCAL", AF_LOCAL, file);
988 #else
989 newmissing(missing, "Net::Gen::AF_LOCAL", file);
990 #endif
991 #ifdef PF_LOCAL
992 newXSconstUV("Net::Gen::PF_LOCAL", PF_LOCAL, file);
993 #else
994 newmissing(missing, "Net::Gen::PF_LOCAL", file);
995 #endif
996 #ifdef AF_IMPLINK
997 newXSconstUV("Net::Gen::AF_IMPLINK", AF_IMPLINK, file);
998 #else
999 newmissing(missing, "Net::Gen::AF_IMPLINK", file);
1000 #endif
1001 #ifdef PF_IMPLINK
1002 newXSconstUV("Net::Gen::PF_IMPLINK", PF_IMPLINK, file);
1003 #else
1004 newmissing(missing, "Net::Gen::PF_IMPLINK", file);
1005 #endif
1006 #ifdef AF_PUP
1007 newXSconstUV("Net::Gen::AF_PUP", AF_PUP, file);
1008 #else
1009 newmissing(missing, "Net::Gen::AF_PUP", file);
1010 #endif
1011 #ifdef PF_PUP
1012 newXSconstUV("Net::Gen::PF_PUP", PF_PUP, file);
1013 #else
1014 newmissing(missing, "Net::Gen::PF_PUP", file);
1015 #endif
1016 #ifdef AF_CHAOS
1017 newXSconstUV("Net::Gen::AF_CHAOS", AF_CHAOS, file);
1018 #else
1019 newmissing(missing, "Net::Gen::AF_CHAOS", file);
1020 #endif
1021 #ifdef PF_CHAOS
1022 newXSconstUV("Net::Gen::PF_CHAOS", PF_CHAOS, file);
1023 #else
1024 newmissing(missing, "Net::Gen::PF_CHAOS", file);
1025 #endif
1026 #ifdef AF_NS
1027 newXSconstUV("Net::Gen::AF_NS", AF_NS, file);
1028 #else
1029 newmissing(missing, "Net::Gen::AF_NS", file);
1030 #endif
1031 #ifdef PF_NS
1032 newXSconstUV("Net::Gen::PF_NS", PF_NS, file);
1033 #else
1034 newmissing(missing, "Net::Gen::PF_NS", file);
1035 #endif
1036 #ifdef AF_ISO
1037 newXSconstUV("Net::Gen::AF_ISO", AF_ISO, file);
1038 #else
1039 newmissing(missing, "Net::Gen::AF_ISO", file);
1040 #endif
1041 #ifdef PF_ISO
1042 newXSconstUV("Net::Gen::PF_ISO", PF_ISO, file);
1043 #else
1044 newmissing(missing, "Net::Gen::PF_ISO", file);
1045 #endif
1046 #ifdef AF_OSI
1047 newXSconstUV("Net::Gen::AF_OSI", AF_OSI, file);
1048 #else
1049 newmissing(missing, "Net::Gen::AF_OSI", file);
1050 #endif
1051 #ifdef PF_OSI
1052 newXSconstUV("Net::Gen::PF_OSI", PF_OSI, file);
1053 #else
1054 newmissing(missing, "Net::Gen::PF_OSI", file);
1055 #endif
1056 #ifdef AF_ECMA
1057 newXSconstUV("Net::Gen::AF_ECMA", AF_ECMA, file);
1058 #else
1059 newmissing(missing, "Net::Gen::AF_ECMA", file);
1060 #endif
1061 #ifdef PF_ECMA
1062 newXSconstUV("Net::Gen::PF_ECMA", PF_ECMA, file);
1063 #else
1064 newmissing(missing, "Net::Gen::PF_ECMA", file);
1065 #endif
1066 #ifdef AF_DATAKIT
1067 newXSconstUV("Net::Gen::AF_DATAKIT", AF_DATAKIT, file);
1068 #else
1069 newmissing(missing, "Net::Gen::AF_DATAKIT", file);
1070 #endif
1071 #ifdef PF_DATAKIT
1072 newXSconstUV("Net::Gen::PF_DATAKIT", PF_DATAKIT, file);
1073 #else
1074 newmissing(missing, "Net::Gen::PF_DATAKIT", file);
1075 #endif
1076 #ifdef AF_CCITT
1077 newXSconstUV("Net::Gen::AF_CCITT", AF_CCITT, file);
1078 #else
1079 newmissing(missing, "Net::Gen::AF_CCITT", file);
1080 #endif
1081 #ifdef PF_CCITT
1082 newXSconstUV("Net::Gen::PF_CCITT", PF_CCITT, file);
1083 #else
1084 newmissing(missing, "Net::Gen::PF_CCITT", file);
1085 #endif
1086 #ifdef AF_SNA
1087 newXSconstUV("Net::Gen::AF_SNA", AF_SNA, file);
1088 #else
1089 newmissing(missing, "Net::Gen::AF_SNA", file);
1090 #endif
1091 #ifdef PF_SNA
1092 newXSconstUV("Net::Gen::PF_SNA", PF_SNA, file);
1093 #else
1094 newmissing(missing, "Net::Gen::PF_SNA", file);
1095 #endif
1096 #ifdef AF_DECnet
1097 newXSconstUV("Net::Gen::AF_DECnet", AF_DECnet, file);
1098 #else
1099 newmissing(missing, "Net::Gen::AF_DECnet", file);
1100 #endif
1101 #ifdef PF_DECnet
1102 newXSconstUV("Net::Gen::PF_DECnet", PF_DECnet, file);
1103 #else
1104 newmissing(missing, "Net::Gen::PF_DECnet", file);
1105 #endif
1106 #ifdef AF_DLI
1107 newXSconstUV("Net::Gen::AF_DLI", AF_DLI, file);
1108 #else
1109 newmissing(missing, "Net::Gen::AF_DLI", file);
1110 #endif
1111 #ifdef PF_DLI
1112 newXSconstUV("Net::Gen::PF_DLI", PF_DLI, file);
1113 #else
1114 newmissing(missing, "Net::Gen::PF_DLI", file);
1115 #endif
1116 #ifdef AF_LAT
1117 newXSconstUV("Net::Gen::AF_LAT", AF_LAT, file);
1118 #else
1119 newmissing(missing, "Net::Gen::AF_LAT", file);
1120 #endif
1121 #ifdef PF_LAT
1122 newXSconstUV("Net::Gen::PF_LAT", PF_LAT, file);
1123 #else
1124 newmissing(missing, "Net::Gen::PF_LAT", file);
1125 #endif
1126 #ifdef AF_HYLINK
1127 newXSconstUV("Net::Gen::AF_HYLINK", AF_HYLINK, file);
1128 #else
1129 newmissing(missing, "Net::Gen::AF_HYLINK", file);
1130 #endif
1131 #ifdef PF_HYLINK
1132 newXSconstUV("Net::Gen::PF_HYLINK", PF_HYLINK, file);
1133 #else
1134 newmissing(missing, "Net::Gen::PF_HYLINK", file);
1135 #endif
1136 #ifdef AF_APPLETALK
1137 newXSconstUV("Net::Gen::AF_APPLETALK", AF_APPLETALK, file);
1138 #else
1139 newmissing(missing, "Net::Gen::AF_APPLETALK", file);
1140 #endif
1141 #ifdef PF_APPLETALK
1142 newXSconstUV("Net::Gen::PF_APPLETALK", PF_APPLETALK, file);
1143 #else
1144 newmissing(missing, "Net::Gen::PF_APPLETALK", file);
1145 #endif
1146 #ifdef AF_ROUTE
1147 newXSconstUV("Net::Gen::AF_ROUTE", AF_ROUTE, file);
1148 #else
1149 newmissing(missing, "Net::Gen::AF_ROUTE", file);
1150 #endif
1151 #ifdef PF_ROUTE
1152 newXSconstUV("Net::Gen::PF_ROUTE", PF_ROUTE, file);
1153 #else
1154 newmissing(missing, "Net::Gen::PF_ROUTE", file);
1155 #endif
1156 #ifdef AF_LINK
1157 newXSconstUV("Net::Gen::AF_LINK", AF_LINK, file);
1158 #else
1159 newmissing(missing, "Net::Gen::AF_LINK", file);
1160 #endif
1161 #ifdef PF_LINK
1162 newXSconstUV("Net::Gen::PF_LINK", PF_LINK, file);
1163 #else
1164 newmissing(missing, "Net::Gen::PF_LINK", file);
1165 #endif
1166 #ifdef AF_NETMAN
1167 newXSconstUV("Net::Gen::AF_NETMAN", AF_NETMAN, file);
1168 #else
1169 newmissing(missing, "Net::Gen::AF_NETMAN", file);
1170 #endif
1171 #ifdef PF_NETMAN
1172 newXSconstUV("Net::Gen::PF_NETMAN", PF_NETMAN, file);
1173 #else
1174 newmissing(missing, "Net::Gen::PF_NETMAN", file);
1175 #endif
1176 #ifdef AF_X25
1177 newXSconstUV("Net::Gen::AF_X25", AF_X25, file);
1178 #else
1179 newmissing(missing, "Net::Gen::AF_X25", file);
1180 #endif
1181 #ifdef PF_X25
1182 newXSconstUV("Net::Gen::PF_X25", PF_X25, file);
1183 #else
1184 newmissing(missing, "Net::Gen::PF_X25", file);
1185 #endif
1186 #ifdef AF_CTF
1187 newXSconstUV("Net::Gen::AF_CTF", AF_CTF, file);
1188 #else
1189 newmissing(missing, "Net::Gen::AF_CTF", file);
1190 #endif
1191 #ifdef PF_CTF
1192 newXSconstUV("Net::Gen::PF_CTF", PF_CTF, file);
1193 #else
1194 newmissing(missing, "Net::Gen::PF_CTF", file);
1195 #endif
1196 #ifdef AF_WAN
1197 newXSconstUV("Net::Gen::AF_WAN", AF_WAN, file);
1198 #else
1199 newmissing(missing, "Net::Gen::AF_WAN", file);
1200 #endif
1201 #ifdef PF_WAN
1202 newXSconstUV("Net::Gen::PF_WAN", PF_WAN, file);
1203 #else
1204 newmissing(missing, "Net::Gen::PF_WAN", file);
1205 #endif
1206 #ifdef AF_USER
1207 newXSconstUV("Net::Gen::AF_USER", AF_USER, file);
1208 #else
1209 newmissing(missing, "Net::Gen::AF_USER", file);
1210 #endif
1211 #ifdef PF_USER
1212 newXSconstUV("Net::Gen::PF_USER", PF_USER, file);
1213 #else
1214 newmissing(missing, "Net::Gen::PF_USER", file);
1215 #endif
1216 #ifdef AF_LAST
1217 newXSconstUV("Net::Gen::AF_LAST", AF_LAST, file);
1218 #else
1219 newmissing(missing, "Net::Gen::AF_LAST", file);
1220 #endif
1221 #ifdef PF_LAST
1222 newXSconstUV("Net::Gen::PF_LAST", PF_LAST, file);
1223 #else
1224 newmissing(missing, "Net::Gen::PF_LAST", file);
1225 #endif
1226 newXSconstUV("Net::Gen::ENOENT", ENOENT, file);
1227 newXSconstUV("Net::Gen::EINVAL", EINVAL, file);
1228 newXSconstUV("Net::Gen::EBADF", EBADF, file);
1229 newXSconstUV("Net::Gen::EAGAIN", EAGAIN, file);
1230 newXSconstUV("Net::Gen::EWOULDBLOCK", EWOULDBLOCK, file);
1231 newXSconstUV("Net::Gen::EINPROGRESS", EINPROGRESS, file);
1232 newXSconstUV("Net::Gen::EALREADY", EALREADY, file);
1233 newXSconstUV("Net::Gen::ENOTSOCK", ENOTSOCK, file);
1234 newXSconstUV("Net::Gen::EDESTADDRREQ", EDESTADDRREQ, file);
1235 newXSconstUV("Net::Gen::EMSGSIZE", EMSGSIZE, file);
1236 newXSconstUV("Net::Gen::EPROTOTYPE", EPROTOTYPE, file);
1237 newXSconstUV("Net::Gen::ENOPROTOOPT", ENOPROTOOPT, file);
1238 newXSconstUV("Net::Gen::EPROTONOSUPPORT", EPROTONOSUPPORT, file);
1239 newXSconstUV("Net::Gen::ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, file);
1240 newXSconstUV("Net::Gen::EOPNOTSUPP", EOPNOTSUPP, file);
1241 newXSconstUV("Net::Gen::EPFNOSUPPORT", EPFNOSUPPORT, file);
1242 newXSconstUV("Net::Gen::EAFNOSUPPORT", EAFNOSUPPORT, file);
1243 newXSconstUV("Net::Gen::EADDRINUSE", EADDRINUSE, file);
1244 newXSconstUV("Net::Gen::EADDRNOTAVAIL", EADDRNOTAVAIL, file);
1245 newXSconstUV("Net::Gen::ENETDOWN", ENETDOWN, file);
1246 newXSconstUV("Net::Gen::ENETUNREACH", ENETUNREACH, file);
1247 newXSconstUV("Net::Gen::ENETRESET", ENETRESET, file);
1248 newXSconstUV("Net::Gen::ECONNABORTED", ECONNABORTED, file);
1249 newXSconstUV("Net::Gen::ECONNRESET", ECONNRESET, file);
1250 newXSconstUV("Net::Gen::ENOBUFS", ENOBUFS, file);
1251 newXSconstUV("Net::Gen::EISCONN", EISCONN, file);
1252 newXSconstUV("Net::Gen::ENOTCONN", ENOTCONN, file);
1253 newXSconstUV("Net::Gen::ESHUTDOWN", ESHUTDOWN, file);
1254 newXSconstUV("Net::Gen::ETOOMANYREFS", ETOOMANYREFS, file);
1255 newXSconstUV("Net::Gen::ETIMEDOUT", ETIMEDOUT, file);
1256 newXSconstUV("Net::Gen::ECONNREFUSED", ECONNREFUSED, file);
1257 newXSconstUV("Net::Gen::EHOSTDOWN", EHOSTDOWN, file);
1258 newXSconstUV("Net::Gen::EHOSTUNREACH", EHOSTUNREACH, file);
1259 newXSconstUV("Net::Gen::ENOSR", ENOSR, file);
1260 newXSconstUV("Net::Gen::ETIME", ETIME, file);
1261 newXSconstUV("Net::Gen::EBADMSG", EBADMSG, file);
1262 newXSconstUV("Net::Gen::EPROTO", EPROTO, file);
1263 newXSconstUV("Net::Gen::ENODATA", ENODATA, file);
1264 newXSconstUV("Net::Gen::ENOSTR", ENOSTR, file);
1265 newXSconstUV("Net::Gen::SOMAXCONN", SOMAXCONN, file);
1266
1267
1268 MODULE = Net::Gen PACKAGE = Net::Gen
1269
1270 BOOT:
1271 }
1272
1273 void
1274 pack_sockaddr(family,address)
1275 U8 family
1276 SV * address
1277 PREINIT:
1278 struct sockaddr sad;
1279 char * adata;
1280 STRLEN adlen;
1281 PPCODE:
1282 Zero(&sad, sizeof sad, char);
1283 sad.sa_family = family;
1284 adata = SvPV(address, adlen);
1285 if (adlen > sizeof(sad.sa_data)) {
1286 SV * rval = sv_newmortal();
1287 sv_setpvn(rval, (char*)&sad, sizeof sad - sizeof sad.sa_data);
1288 sv_catpvn(rval, adata, adlen);
1289 ST(0) = rval;
1290 }
1291 else {
1292 Copy(adata, &sad.sa_data, adlen, char);
1293 ST(0) = sv_2mortal(newSVpv((char*)&sad, sizeof sad));
1294 }
1295 XSRETURN(1);
1296
1297 void
1298 unpack_sockaddr(sad)
1299 SV * sad
1300 PREINIT:
1301 char * cp;
1302 STRLEN len;
1303 PPCODE:
1304 if ((cp = SvPV(sad, len)) != (char*)0) {
1305 struct sockaddr sa;
1306 U16 family;
1307 SV * famsv;
1308 SV * datsv;
1309
1310 if (len < sizeof sa - sizeof sa.sa_data)
1311 Zero(&sa, sizeof sa - sizeof sa.sa_data, char);
1312 Copy(cp, &sa, len < sizeof sa ? len : sizeof sa, char);
1313 family = sa.sa_family;
1314 if (family > 255) { /* 4.4bsd anyone? */
1315 U8 famlen1, famlen2;
1316 famlen1 = family & 255;
1317 famlen2 = family >> 8;
1318 if (famlen1 == famlen2)
1319 family = famlen1;
1320 else if (famlen1 == len)
1321 family = famlen2;
1322 else if (famlen2 == len)
1323 family = famlen1;
1324 }
1325 famsv = sv_2mortal(newSViv(family));
1326 if (len >= sizeof sa - sizeof sa.sa_data) {
1327 len -= sizeof sa - sizeof sa.sa_data;
1328 datsv = sv_2mortal(newSVpv(cp + (sizeof sa - sizeof sa.sa_data),
1329 len));
1330 }
1331 else {
1332 datsv = sv_mortalcopy(&PL_sv_undef);
1333 }
1334 EXTEND(sp, 2);
1335 PUSHs(famsv);
1336 PUSHs(datsv);
1337 }
1338
1339