xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/ext/Socket/Socket.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage Socket;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateour($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
4*0Sstevel@tonic-gate$VERSION = "1.77";
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate=head1 NAME
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gateSocket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa - load the C socket.h defines and structure manipulators
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gate=head1 SYNOPSIS
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gate    use Socket;
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate    $proto = getprotobyname('udp');
15*0Sstevel@tonic-gate    socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto);
16*0Sstevel@tonic-gate    $iaddr = gethostbyname('hishost.com');
17*0Sstevel@tonic-gate    $port = getservbyname('time', 'udp');
18*0Sstevel@tonic-gate    $sin = sockaddr_in($port, $iaddr);
19*0Sstevel@tonic-gate    send(Socket_Handle, 0, 0, $sin);
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gate    $proto = getprotobyname('tcp');
22*0Sstevel@tonic-gate    socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
23*0Sstevel@tonic-gate    $port = getservbyname('smtp', 'tcp');
24*0Sstevel@tonic-gate    $sin = sockaddr_in($port,inet_aton("127.1"));
25*0Sstevel@tonic-gate    $sin = sockaddr_in(7,inet_aton("localhost"));
26*0Sstevel@tonic-gate    $sin = sockaddr_in(7,INADDR_LOOPBACK);
27*0Sstevel@tonic-gate    connect(Socket_Handle,$sin);
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate    ($port, $iaddr) = sockaddr_in(getpeername(Socket_Handle));
30*0Sstevel@tonic-gate    $peer_host = gethostbyaddr($iaddr, AF_INET);
31*0Sstevel@tonic-gate    $peer_addr = inet_ntoa($iaddr);
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate    $proto = getprotobyname('tcp');
34*0Sstevel@tonic-gate    socket(Socket_Handle, PF_UNIX, SOCK_STREAM, $proto);
35*0Sstevel@tonic-gate    unlink('/var/run/usock');
36*0Sstevel@tonic-gate    $sun = sockaddr_un('/var/run/usock');
37*0Sstevel@tonic-gate    connect(Socket_Handle,$sun);
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate=head1 DESCRIPTION
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gateThis module is just a translation of the C F<socket.h> file.
42*0Sstevel@tonic-gateUnlike the old mechanism of requiring a translated F<socket.ph>
43*0Sstevel@tonic-gatefile, this uses the B<h2xs> program (see the Perl source distribution)
44*0Sstevel@tonic-gateand your native C compiler.  This means that it has a
45*0Sstevel@tonic-gatefar more likely chance of getting the numbers right.  This includes
46*0Sstevel@tonic-gateall of the commonly used pound-defines like AF_INET, SOCK_STREAM, etc.
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gateAlso, some common socket "newline" constants are provided: the
49*0Sstevel@tonic-gateconstants C<CR>, C<LF>, and C<CRLF>, as well as C<$CR>, C<$LF>, and
50*0Sstevel@tonic-gateC<$CRLF>, which map to C<\015>, C<\012>, and C<\015\012>.  If you do
51*0Sstevel@tonic-gatenot want to use the literal characters in your programs, then use
52*0Sstevel@tonic-gatethe constants provided here.  They are not exported by default, but can
53*0Sstevel@tonic-gatebe imported individually, and with the C<:crlf> export tag:
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate    use Socket qw(:DEFAULT :crlf);
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gateIn addition, some structure manipulation functions are available:
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate=over 4
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate=item inet_aton HOSTNAME
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gateTakes a string giving the name of a host, and translates that to an
64*0Sstevel@tonic-gateopaque string (if programming in C, struct in_addr). Takes arguments
65*0Sstevel@tonic-gateof both the 'rtfm.mit.edu' type and '18.181.0.24'. If the host name
66*0Sstevel@tonic-gatecannot be resolved, returns undef.  For multi-homed hosts (hosts with
67*0Sstevel@tonic-gatemore than one address), the first address found is returned.
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gateFor portability do not assume that the result of inet_aton() is 32
70*0Sstevel@tonic-gatebits wide, in other words, that it would contain only the IPv4 address
71*0Sstevel@tonic-gatein network order.
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate=item inet_ntoa IP_ADDRESS
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gateTakes a string (an opaque string as returned by inet_aton(),
76*0Sstevel@tonic-gateor a v-string representing the four octets of the IPv4 address in
77*0Sstevel@tonic-gatenetwork order) and translates it into a string of the form 'd.d.d.d'
78*0Sstevel@tonic-gatewhere the 'd's are numbers less than 256 (the normal human-readable
79*0Sstevel@tonic-gatefour dotted number notation for Internet addresses).
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate=item INADDR_ANY
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gateNote: does not return a number, but a packed string.
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gateReturns the 4-byte wildcard ip address which specifies any
86*0Sstevel@tonic-gateof the hosts ip addresses.  (A particular machine can have
87*0Sstevel@tonic-gatemore than one ip address, each address corresponding to
88*0Sstevel@tonic-gatea particular network interface. This wildcard address
89*0Sstevel@tonic-gateallows you to bind to all of them simultaneously.)
90*0Sstevel@tonic-gateNormally equivalent to inet_aton('0.0.0.0').
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate=item INADDR_BROADCAST
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gateNote: does not return a number, but a packed string.
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gateReturns the 4-byte 'this-lan' ip broadcast address.
97*0Sstevel@tonic-gateThis can be useful for some protocols to solicit information
98*0Sstevel@tonic-gatefrom all servers on the same LAN cable.
99*0Sstevel@tonic-gateNormally equivalent to inet_aton('255.255.255.255').
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate=item INADDR_LOOPBACK
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gateNote - does not return a number.
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gateReturns the 4-byte loopback address.  Normally equivalent
106*0Sstevel@tonic-gateto inet_aton('localhost').
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate=item INADDR_NONE
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gateNote - does not return a number.
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gateReturns the 4-byte 'invalid' ip address.  Normally equivalent
113*0Sstevel@tonic-gateto inet_aton('255.255.255.255').
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate=item sockaddr_family SOCKADDR
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gateTakes a sockaddr structure (as returned by pack_sockaddr_in(),
118*0Sstevel@tonic-gatepack_sockaddr_un() or the perl builtin functions getsockname() and
119*0Sstevel@tonic-gategetpeername()) and returns the address family tag.  It will match the
120*0Sstevel@tonic-gateconstant AF_INET for a sockaddr_in and AF_UNIX for a sockaddr_un.  It
121*0Sstevel@tonic-gatecan be used to figure out what unpacker to use for a sockaddr of
122*0Sstevel@tonic-gateunknown type.
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate=item sockaddr_in PORT, ADDRESS
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate=item sockaddr_in SOCKADDR_IN
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gateIn a list context, unpacks its SOCKADDR_IN argument and returns an array
129*0Sstevel@tonic-gateconsisting of (PORT, ADDRESS).  In a scalar context, packs its (PORT,
130*0Sstevel@tonic-gateADDRESS) arguments as a SOCKADDR_IN and returns it.  If this is confusing,
131*0Sstevel@tonic-gateuse pack_sockaddr_in() and unpack_sockaddr_in() explicitly.
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate=item pack_sockaddr_in PORT, IP_ADDRESS
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gateTakes two arguments, a port number and an opaque string, IP_ADDRESS
136*0Sstevel@tonic-gate(as returned by inet_aton(), or a v-string).  Returns the sockaddr_in
137*0Sstevel@tonic-gatestructure with those arguments packed in with AF_INET filled in.  For
138*0Sstevel@tonic-gateInternet domain sockets, this structure is normally what you need for
139*0Sstevel@tonic-gatethe arguments in bind(), connect(), and send(), and is also returned
140*0Sstevel@tonic-gateby getpeername(), getsockname() and recv().
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate=item unpack_sockaddr_in SOCKADDR_IN
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gateTakes a sockaddr_in structure (as returned by pack_sockaddr_in()) and
145*0Sstevel@tonic-gatereturns an array of two elements: the port and an opaque string
146*0Sstevel@tonic-gaterepresenting the IP address (you can use inet_ntoa() to convert the
147*0Sstevel@tonic-gateaddress to the four-dotted numeric format).  Will croak if the
148*0Sstevel@tonic-gatestructure does not have AF_INET in the right place.
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate=item sockaddr_un PATHNAME
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate=item sockaddr_un SOCKADDR_UN
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gateIn a list context, unpacks its SOCKADDR_UN argument and returns an array
155*0Sstevel@tonic-gateconsisting of (PATHNAME).  In a scalar context, packs its PATHNAME
156*0Sstevel@tonic-gatearguments as a SOCKADDR_UN and returns it.  If this is confusing, use
157*0Sstevel@tonic-gatepack_sockaddr_un() and unpack_sockaddr_un() explicitly.
158*0Sstevel@tonic-gateThese are only supported if your system has E<lt>F<sys/un.h>E<gt>.
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate=item pack_sockaddr_un PATH
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gateTakes one argument, a pathname. Returns the sockaddr_un structure with
163*0Sstevel@tonic-gatethat path packed in with AF_UNIX filled in. For unix domain sockets, this
164*0Sstevel@tonic-gatestructure is normally what you need for the arguments in bind(),
165*0Sstevel@tonic-gateconnect(), and send(), and is also returned by getpeername(),
166*0Sstevel@tonic-gategetsockname() and recv().
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate=item unpack_sockaddr_un SOCKADDR_UN
169*0Sstevel@tonic-gate
170*0Sstevel@tonic-gateTakes a sockaddr_un structure (as returned by pack_sockaddr_un())
171*0Sstevel@tonic-gateand returns the pathname.  Will croak if the structure does not
172*0Sstevel@tonic-gatehave AF_UNIX in the right place.
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate=back
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate=cut
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gateuse Carp;
179*0Sstevel@tonic-gateuse warnings::register;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gaterequire Exporter;
182*0Sstevel@tonic-gateuse XSLoader ();
183*0Sstevel@tonic-gate@ISA = qw(Exporter);
184*0Sstevel@tonic-gate@EXPORT = qw(
185*0Sstevel@tonic-gate	inet_aton inet_ntoa
186*0Sstevel@tonic-gate	sockaddr_family
187*0Sstevel@tonic-gate	pack_sockaddr_in unpack_sockaddr_in
188*0Sstevel@tonic-gate	pack_sockaddr_un unpack_sockaddr_un
189*0Sstevel@tonic-gate	sockaddr_in sockaddr_un
190*0Sstevel@tonic-gate	INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
191*0Sstevel@tonic-gate	AF_802
192*0Sstevel@tonic-gate	AF_AAL
193*0Sstevel@tonic-gate	AF_APPLETALK
194*0Sstevel@tonic-gate	AF_CCITT
195*0Sstevel@tonic-gate	AF_CHAOS
196*0Sstevel@tonic-gate	AF_CTF
197*0Sstevel@tonic-gate	AF_DATAKIT
198*0Sstevel@tonic-gate	AF_DECnet
199*0Sstevel@tonic-gate	AF_DLI
200*0Sstevel@tonic-gate	AF_ECMA
201*0Sstevel@tonic-gate	AF_GOSIP
202*0Sstevel@tonic-gate	AF_HYLINK
203*0Sstevel@tonic-gate	AF_IMPLINK
204*0Sstevel@tonic-gate	AF_INET
205*0Sstevel@tonic-gate	AF_INET6
206*0Sstevel@tonic-gate	AF_ISO
207*0Sstevel@tonic-gate	AF_KEY
208*0Sstevel@tonic-gate	AF_LAST
209*0Sstevel@tonic-gate	AF_LAT
210*0Sstevel@tonic-gate	AF_LINK
211*0Sstevel@tonic-gate	AF_MAX
212*0Sstevel@tonic-gate	AF_NBS
213*0Sstevel@tonic-gate	AF_NIT
214*0Sstevel@tonic-gate	AF_NS
215*0Sstevel@tonic-gate	AF_OSI
216*0Sstevel@tonic-gate	AF_OSINET
217*0Sstevel@tonic-gate	AF_PUP
218*0Sstevel@tonic-gate	AF_ROUTE
219*0Sstevel@tonic-gate	AF_SNA
220*0Sstevel@tonic-gate	AF_UNIX
221*0Sstevel@tonic-gate	AF_UNSPEC
222*0Sstevel@tonic-gate	AF_USER
223*0Sstevel@tonic-gate	AF_WAN
224*0Sstevel@tonic-gate	AF_X25
225*0Sstevel@tonic-gate	IOV_MAX
226*0Sstevel@tonic-gate	MSG_BCAST
227*0Sstevel@tonic-gate	MSG_BTAG
228*0Sstevel@tonic-gate	MSG_CTLFLAGS
229*0Sstevel@tonic-gate	MSG_CTLIGNORE
230*0Sstevel@tonic-gate	MSG_CTRUNC
231*0Sstevel@tonic-gate	MSG_DONTROUTE
232*0Sstevel@tonic-gate	MSG_DONTWAIT
233*0Sstevel@tonic-gate	MSG_EOF
234*0Sstevel@tonic-gate	MSG_EOR
235*0Sstevel@tonic-gate	MSG_ERRQUEUE
236*0Sstevel@tonic-gate	MSG_ETAG
237*0Sstevel@tonic-gate	MSG_FIN
238*0Sstevel@tonic-gate	MSG_MAXIOVLEN
239*0Sstevel@tonic-gate	MSG_MCAST
240*0Sstevel@tonic-gate	MSG_NOSIGNAL
241*0Sstevel@tonic-gate	MSG_OOB
242*0Sstevel@tonic-gate	MSG_PEEK
243*0Sstevel@tonic-gate	MSG_PROXY
244*0Sstevel@tonic-gate	MSG_RST
245*0Sstevel@tonic-gate	MSG_SYN
246*0Sstevel@tonic-gate	MSG_TRUNC
247*0Sstevel@tonic-gate	MSG_URG
248*0Sstevel@tonic-gate	MSG_WAITALL
249*0Sstevel@tonic-gate	MSG_WIRE
250*0Sstevel@tonic-gate	PF_802
251*0Sstevel@tonic-gate	PF_AAL
252*0Sstevel@tonic-gate	PF_APPLETALK
253*0Sstevel@tonic-gate	PF_CCITT
254*0Sstevel@tonic-gate	PF_CHAOS
255*0Sstevel@tonic-gate	PF_CTF
256*0Sstevel@tonic-gate	PF_DATAKIT
257*0Sstevel@tonic-gate	PF_DECnet
258*0Sstevel@tonic-gate	PF_DLI
259*0Sstevel@tonic-gate	PF_ECMA
260*0Sstevel@tonic-gate	PF_GOSIP
261*0Sstevel@tonic-gate	PF_HYLINK
262*0Sstevel@tonic-gate	PF_IMPLINK
263*0Sstevel@tonic-gate	PF_INET
264*0Sstevel@tonic-gate	PF_INET6
265*0Sstevel@tonic-gate	PF_ISO
266*0Sstevel@tonic-gate	PF_KEY
267*0Sstevel@tonic-gate	PF_LAST
268*0Sstevel@tonic-gate	PF_LAT
269*0Sstevel@tonic-gate	PF_LINK
270*0Sstevel@tonic-gate	PF_MAX
271*0Sstevel@tonic-gate	PF_NBS
272*0Sstevel@tonic-gate	PF_NIT
273*0Sstevel@tonic-gate	PF_NS
274*0Sstevel@tonic-gate	PF_OSI
275*0Sstevel@tonic-gate	PF_OSINET
276*0Sstevel@tonic-gate	PF_PUP
277*0Sstevel@tonic-gate	PF_ROUTE
278*0Sstevel@tonic-gate	PF_SNA
279*0Sstevel@tonic-gate	PF_UNIX
280*0Sstevel@tonic-gate	PF_UNSPEC
281*0Sstevel@tonic-gate	PF_USER
282*0Sstevel@tonic-gate	PF_WAN
283*0Sstevel@tonic-gate	PF_X25
284*0Sstevel@tonic-gate	SCM_CONNECT
285*0Sstevel@tonic-gate	SCM_CREDENTIALS
286*0Sstevel@tonic-gate	SCM_CREDS
287*0Sstevel@tonic-gate	SCM_RIGHTS
288*0Sstevel@tonic-gate	SCM_TIMESTAMP
289*0Sstevel@tonic-gate	SHUT_RD
290*0Sstevel@tonic-gate	SHUT_RDWR
291*0Sstevel@tonic-gate	SHUT_WR
292*0Sstevel@tonic-gate	SOCK_DGRAM
293*0Sstevel@tonic-gate	SOCK_RAW
294*0Sstevel@tonic-gate	SOCK_RDM
295*0Sstevel@tonic-gate	SOCK_SEQPACKET
296*0Sstevel@tonic-gate	SOCK_STREAM
297*0Sstevel@tonic-gate	SOL_SOCKET
298*0Sstevel@tonic-gate	SOMAXCONN
299*0Sstevel@tonic-gate	SO_ACCEPTCONN
300*0Sstevel@tonic-gate	SO_ATTACH_FILTER
301*0Sstevel@tonic-gate	SO_BACKLOG
302*0Sstevel@tonic-gate	SO_BROADCAST
303*0Sstevel@tonic-gate	SO_CHAMELEON
304*0Sstevel@tonic-gate	SO_DEBUG
305*0Sstevel@tonic-gate	SO_DETACH_FILTER
306*0Sstevel@tonic-gate	SO_DGRAM_ERRIND
307*0Sstevel@tonic-gate	SO_DONTLINGER
308*0Sstevel@tonic-gate	SO_DONTROUTE
309*0Sstevel@tonic-gate	SO_ERROR
310*0Sstevel@tonic-gate	SO_FAMILY
311*0Sstevel@tonic-gate	SO_KEEPALIVE
312*0Sstevel@tonic-gate	SO_LINGER
313*0Sstevel@tonic-gate	SO_OOBINLINE
314*0Sstevel@tonic-gate	SO_PASSCRED
315*0Sstevel@tonic-gate	SO_PASSIFNAME
316*0Sstevel@tonic-gate	SO_PEERCRED
317*0Sstevel@tonic-gate	SO_PROTOCOL
318*0Sstevel@tonic-gate	SO_PROTOTYPE
319*0Sstevel@tonic-gate	SO_RCVBUF
320*0Sstevel@tonic-gate	SO_RCVLOWAT
321*0Sstevel@tonic-gate	SO_RCVTIMEO
322*0Sstevel@tonic-gate	SO_REUSEADDR
323*0Sstevel@tonic-gate	SO_REUSEPORT
324*0Sstevel@tonic-gate	SO_SECURITY_AUTHENTICATION
325*0Sstevel@tonic-gate	SO_SECURITY_ENCRYPTION_NETWORK
326*0Sstevel@tonic-gate	SO_SECURITY_ENCRYPTION_TRANSPORT
327*0Sstevel@tonic-gate	SO_SNDBUF
328*0Sstevel@tonic-gate	SO_SNDLOWAT
329*0Sstevel@tonic-gate	SO_SNDTIMEO
330*0Sstevel@tonic-gate	SO_STATE
331*0Sstevel@tonic-gate	SO_TYPE
332*0Sstevel@tonic-gate	SO_USELOOPBACK
333*0Sstevel@tonic-gate	SO_XOPEN
334*0Sstevel@tonic-gate	SO_XSE
335*0Sstevel@tonic-gate	UIO_MAXIOV
336*0Sstevel@tonic-gate);
337*0Sstevel@tonic-gate
338*0Sstevel@tonic-gate@EXPORT_OK = qw(CR LF CRLF $CR $LF $CRLF
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate	       IPPROTO_TCP
341*0Sstevel@tonic-gate	       TCP_KEEPALIVE
342*0Sstevel@tonic-gate	       TCP_MAXRT
343*0Sstevel@tonic-gate	       TCP_MAXSEG
344*0Sstevel@tonic-gate	       TCP_NODELAY
345*0Sstevel@tonic-gate	       TCP_STDURG);
346*0Sstevel@tonic-gate
347*0Sstevel@tonic-gate%EXPORT_TAGS = (
348*0Sstevel@tonic-gate    crlf    => [qw(CR LF CRLF $CR $LF $CRLF)],
349*0Sstevel@tonic-gate    all     => [@EXPORT, @EXPORT_OK],
350*0Sstevel@tonic-gate);
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gateBEGIN {
353*0Sstevel@tonic-gate    sub CR   () {"\015"}
354*0Sstevel@tonic-gate    sub LF   () {"\012"}
355*0Sstevel@tonic-gate    sub CRLF () {"\015\012"}
356*0Sstevel@tonic-gate}
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate*CR   = \CR();
359*0Sstevel@tonic-gate*LF   = \LF();
360*0Sstevel@tonic-gate*CRLF = \CRLF();
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gatesub sockaddr_in {
363*0Sstevel@tonic-gate    if (@_ == 6 && !wantarray) { # perl5.001m compat; use this && die
364*0Sstevel@tonic-gate	my($af, $port, @quad) = @_;
365*0Sstevel@tonic-gate	warnings::warn "6-ARG sockaddr_in call is deprecated"
366*0Sstevel@tonic-gate	    if warnings::enabled();
367*0Sstevel@tonic-gate	pack_sockaddr_in($port, inet_aton(join('.', @quad)));
368*0Sstevel@tonic-gate    } elsif (wantarray) {
369*0Sstevel@tonic-gate	croak "usage:   (port,iaddr) = sockaddr_in(sin_sv)" unless @_ == 1;
370*0Sstevel@tonic-gate        unpack_sockaddr_in(@_);
371*0Sstevel@tonic-gate    } else {
372*0Sstevel@tonic-gate	croak "usage:   sin_sv = sockaddr_in(port,iaddr))" unless @_ == 2;
373*0Sstevel@tonic-gate        pack_sockaddr_in(@_);
374*0Sstevel@tonic-gate    }
375*0Sstevel@tonic-gate}
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gatesub sockaddr_un {
378*0Sstevel@tonic-gate    if (wantarray) {
379*0Sstevel@tonic-gate	croak "usage:   (filename) = sockaddr_un(sun_sv)" unless @_ == 1;
380*0Sstevel@tonic-gate        unpack_sockaddr_un(@_);
381*0Sstevel@tonic-gate    } else {
382*0Sstevel@tonic-gate	croak "usage:   sun_sv = sockaddr_un(filename)" unless @_ == 1;
383*0Sstevel@tonic-gate        pack_sockaddr_un(@_);
384*0Sstevel@tonic-gate    }
385*0Sstevel@tonic-gate}
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gatesub AUTOLOAD {
388*0Sstevel@tonic-gate    my($constname);
389*0Sstevel@tonic-gate    ($constname = $AUTOLOAD) =~ s/.*:://;
390*0Sstevel@tonic-gate    croak "&Socket::constant not defined" if $constname eq 'constant';
391*0Sstevel@tonic-gate    my ($error, $val) = constant($constname);
392*0Sstevel@tonic-gate    if ($error) {
393*0Sstevel@tonic-gate	croak $error;
394*0Sstevel@tonic-gate    }
395*0Sstevel@tonic-gate    *$AUTOLOAD = sub { $val };
396*0Sstevel@tonic-gate    goto &$AUTOLOAD;
397*0Sstevel@tonic-gate}
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gateXSLoader::load 'Socket', $VERSION;
400*0Sstevel@tonic-gate
401*0Sstevel@tonic-gate1;
402