Mailing List Archive

Re: Bus error in LWP/Perl5
> From: "Roy T. Fielding" <fielding@avron.ics.uci.edu>
>
> >> Nick, can you elaborate on the problems with IP addresses in URL's?
> >
> > How about this elaboration:
> ...
>
> > elsif ($host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
> > # numeric IP address
> > - $addr[0] = [$1, $2, $3, $4];
> > + $addr[0] = Socket::sockaddr_in(PF_INET, $port, $1, $2, $3, $4);
>
> Yeah, that should do it -- the addresses are unsigned 8bit integers
> packed into a 4-byte structure. The perl4 version used
>
> if ($host =~ /^\d+\.\d+\.\d+\.\d+$/)
> {
> $thataddr = pack('C4', split(/\./, $host));
> }
>
> and I'm glad to see that they put a real interface for it in perl5.

Sort off. The interface will probably change. I added it to Socket.pm
more as a place holder to encourage others to do more.

There is a very much enhanced Socket extension from Jack Shirazi
<JackS@slc.com> which will hopefully make it into Perl5.002.

Sadly, from your point of view, the sockaddr_in has been renamed
pack_sockaddr_in (there's also an unpack_sockaddr_in). Since the
sockaddr_in function was never exported or advertised (and was
simply a hard coded pack) I'd suggest you switch back for now
and wait till 5.002.

Tim.
Re: Bus error in LWP/Perl5 [ In reply to ]
Tim Bunce once wrote:
> > > + $addr[0] = Socket::sockaddr_in(PF_INET, $port, $1, $2, $3, $4);
> >
> > Yeah, that should do it -- the addresses are unsigned 8bit integers
> > packed into a 4-byte structure. The perl4 version used
> >
> > if ($host =~ /^\d+\.\d+\.\d+\.\d+$/)
> > {
> > $thataddr = pack('C4', split(/\./, $host));
> > }
> >
> > and I'm glad to see that they put a real interface for it in perl5.
>
> Sort off. The interface will probably change. I added it to Socket.pm
> more as a place holder to encourage others to do more.
>
> There is a very much enhanced Socket extension from Jack Shirazi
> <JackS@slc.com> which will hopefully make it into Perl5.002.
>
> Sadly, from your point of view, the sockaddr_in has been renamed
> pack_sockaddr_in (there's also an unpack_sockaddr_in). Since the
> sockaddr_in function was never exported or advertised (and was
> simply a hard coded pack) I'd suggest you switch back for now
> and wait till 5.002.

The Socket.pm module is new in perl5.001n, i.e. libwww-perl-5b6 will fail
using the newest unofficial patchlevel of perl. I would prefer if the new
Socket.pm module also provided the old interface so it did not break old
scripts. Put something like this (untested) into the new Socket.pm:

sub sockaddr_in # 5.001m compatibility
{
my($af, $port, @quad) = @_;
pack_sockaddr_in($af, $port, inet_aton(join('.', @quad)));
}



The following patch might be a reasonable fix for libwww-perl-5 until 5.002 is
out. Libwww-perl-5 will then switch over to the new interface. Unfortunately,
this did not make it into the 5b6 release.

NOTE: This patch is only needed if you want to run perl5.001n, but it should
not hurt for older versions of perl.

Index: Socket.pm
===================================================================
RCS file: /local/src/CVSROOT/perl/mods/libwww-perl/lib/LWP/Socket.pm,v
retrieving revision 1.17
diff -u -r1.17 Socket.pm
--- Socket.pm 1995/11/06 09:42:03 1.17
+++ Socket.pm 1995/11/07 09:57:16
@@ -313,6 +313,18 @@
# Private methods
#

+# Stolen from the Socket.pm module of perl5.001m. Perl5.001n (and
+# probably later version) has renamed this function to pack_sockaddr_in()
+# and changed the interface slightly. When 5.002 is out we will switch
+# to the new interface and remove this function from this module.
+sub Socket::sockaddr_in
+{
+ my($af, $port, @quad) = @_;
+ my $pack = 'S n C4 x8'; # lookup $pack from hash using $af?
+ pack($pack, $af, $port, @quad);
+}
+
+
=head2 _getaddress($h, $p)

Given a host and a port, it will return the address (sockaddr_in)
Re: Bus error in LWP/Perl5 [ In reply to ]
please hold off on this patch for a few hours. jack and i
are trying to work something out.

--tom
Re: Bus error in LWP/Perl5 [ In reply to ]
I think this, Socket-1.2, resolves and support all interfaces
(Jack's, Gisle's, and mine) and has better docs. I'll
updated the FMTEYEWTK on IPC tonight.

(Maybe this could you more type checking.)

--tom

#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: Socket-1.2 Socket-1.2/Makefile.PL Socket-1.2/Socket.pm
# Socket-1.2/Socket.xs
# Wrapped by tchrist@mox on Tue Nov 7 12:24:23 1995
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d 'Socket-1.2' ; then
echo shar: Creating directory \"'Socket-1.2'\"
mkdir 'Socket-1.2'
fi
if test -f 'Socket-1.2/Makefile.PL' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Socket-1.2/Makefile.PL'\"
else
echo shar: Extracting \"'Socket-1.2/Makefile.PL'\" \(56 characters\)
sed "s/^X//" >'Socket-1.2/Makefile.PL' <<'END_OF_FILE'
Xuse ExtUtils::MakeMaker;
XWriteMakefile(VERSION => 1.2);
END_OF_FILE
if test 56 -ne `wc -c <'Socket-1.2/Makefile.PL'`; then
echo shar: \"'Socket-1.2/Makefile.PL'\" unpacked with wrong size!
fi
# end of 'Socket-1.2/Makefile.PL'
fi
if test -f 'Socket-1.2/Socket.pm' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Socket-1.2/Socket.pm'\"
else
echo shar: Extracting \"'Socket-1.2/Socket.pm'\" \(6662 characters\)
sed "s/^X//" >'Socket-1.2/Socket.pm' <<'END_OF_FILE'
Xpackage Socket;
X
X=head1 NAME
X
XSocket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa - load the C
X socket.h defines and structure manipulators
X
X=head1 SYNOPSIS
X
X use Socket;
X
X $proto = getprotobyname('udp');
X socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto);
X $iaddr = gethostbyname('hishost.com');
X $port = getservbyname('time', 'udp');
X $sin = sockaddr_in($port, $iaddr);
X send(Socket_Handle, 0, 0, $sin);
X
X $proto = getprotobyname('tcp');
X socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
X $port = getservbyname('smtp');
X $sin = sockaddr_in($port,inet_aton("127.1"));
X $sin = sockaddr_in(7,inet_aton("localhost"));
X $sin = sockaddr_in(7,INADDR_LOOPBACK);
X connect(Socket_Handle,$sin);
X
X ($port, $iaddr) = sockaddr_in(getpeername(Socket_Handle));
X $peer_host = gethostbyaddr($iaddr, AF_INET);
X $peer_addr = inet_ntoa($iaddr);
X
X $proto = getprotobyname('tcp');
X socket(Socket_Handle, PF_UNIX, SOCK_STREAM, $proto);
X unlink('/tmp/usock');
X $sun = sockaddr_un('/tmp/usock');
X connect(Socket_Handle,$sun);
X
X=head1 DESCRIPTION
X
XThis module is just a translation of the C F<socket.h> file.
XUnlike the old mechanism of requiring a translated F<socket.ph>
Xfile, this uses the B<h2xs> program (see the Perl source distribution)
Xand your native C compiler. This means that it has a
Xfar more likely chance of getting the numbers right. This includes
Xall of the commonly used pound-defines like AF_INET, SOCK_STREAM, etc.
X
XIn addition, some structure manipulation functions are available:
X
X=item inet_aton HOSTNAME
X
XTakes a string giving the name of a host, and translates that
Xto the 4-byte string (structure). Takes arguments of both
Xthe 'rtfm.mit.edu' type and '18.181.0.24'. If the host name
Xcannot be resolved, returns undef.
X
X=item inet_ntoa IP_ADDRESS
X
XTakes a four byte ip address (as returned by inet_aton())
Xand translates it into a string of the form 'd.d.d.d'
Xwhere the 'd's are numbers less than 256 (the normal
Xreadable four dotted number notation for internet addresses).
X
X=item INADDR_ANY
X
XNote: does not return a number, but a packed string.
X
XReturns the 4-byte wildcard ip address which specifies any
Xof the hosts ip addresses. (A particular machine can have
Xmore than one ip address, each address corresponding to
Xa particular network interface. This wildcard address
Xallows you to bind to all of them simultaneously.)
XNormally equivalent to inet_aton('0.0.0.0').
X
X=item INADDR_LOOPBACK
X
XNote - does not return a number.
X
XReturns the 4-byte loopback address. Normally equivalent
Xto inet_aton('localhost').
X
X=item INADDR_NONE
X
XNote - does not return a number.
X
XReturns the 4-byte invalid ip address. Normally equivalent
Xto inet_aton('255.255.255.255').
X
X=item sockaddr_in PORT, ADDRESS
X
X=item sockaddr_in SOCKADDR_IN
X
XIn an array context, unpacks its SOCKADDR_IN argument and returns an array
Xconsisting of (PORT, ADDRESS). In a scalar context, packs its (PORT,
XADDRESS) arguments as a SOCKADDR_IN and returns it. If this is confusing,
Xuse pack_sockaddr_in() and unpack_sockaddr_in() explicitly.
X
X=item pack_sockaddr_in PORT, IP_ADDRESS
X
XTakes two arguments, a port number and a 4 byte IP_ADDRESS (as returned by
Xinet_aton()). Returns the sockaddr_in structure with those arguments
Xpacked in with AF_INET filled in. For internet domain sockets, this
Xstructure is normally what you need for the arguments in bind(),
Xconnect(), and send(), and is also returned by getpeername(),
Xgetsockname() and recv().
X
X=item unpack_sockaddr_in SOCKADDR_IN
X
XTakes a sockaddr_in structure (as returned by pack_sockaddr_in()) and
Xreturns an array of two elements: the port and the 4-byte ip-address.
XWill croak if the structure does not have AF_INET in the right place.
X
X=item sockaddr_un PATHNAME
X
X=item sockaddr_un SOCKADDR_UN
X
XIn an array context, unpacks its SOCKADDR_UN argument and returns an array
Xconsisting of (PATHNAME). In a scalar context, packs its PATHANE
Xarguments as a SOCKADDR_UN and returns it. If this is confusing, use
Xpack_sockaddr_un() and unpack_sockaddr_un() explicitly.
X
X=item pack_sockaddr_un PATH
X
XTakes one argument, a pathname. Returns the sockaddr_un structure with
Xthat path packed in with AF_UNIX filled in. For unix domain sockets, this
Xstructure is normally what you need for the arguments in bind(),
Xconnect(), and send(), and is also returned by getpeername(),
Xgetsockname() and recv().
X
X=item unpack_sockaddr_un SOCKADDR_UN
X
XTakes a sockaddr_un structure (as returned by pack_sockaddr_un())
Xand returns the pathname. Will croak if the structure does not
Xhave AF_UNIX in the right place.
X
X=cut
X
Xuse Carp;
X
Xrequire Exporter;
Xuse AutoLoader;
Xrequire DynaLoader;
X@ISA = qw(Exporter DynaLoader);
X@EXPORT = qw(
X inet_aton inet_ntoa pack_sockaddr_in unpack_sockaddr_in
X pack_sockaddr_un unpack_sockaddr_un
X sockaddr_in sockaddr_un
X INADDR_ANY INADDR_LOOPBACK INADDR_NONE
X AF_802
X AF_APPLETALK
X AF_CCITT
X AF_CHAOS
X AF_DATAKIT
X AF_DECnet
X AF_DLI
X AF_ECMA
X AF_GOSIP
X AF_HYLINK
X AF_IMPLINK
X AF_INET
X AF_LAT
X AF_MAX
X AF_NBS
X AF_NIT
X AF_NS
X AF_OSI
X AF_OSINET
X AF_PUP
X AF_SNA
X AF_UNIX
X AF_UNSPEC
X AF_X25
X MSG_DONTROUTE
X MSG_MAXIOVLEN
X MSG_OOB
X MSG_PEEK
X PF_802
X PF_APPLETALK
X PF_CCITT
X PF_CHAOS
X PF_DATAKIT
X PF_DECnet
X PF_DLI
X PF_ECMA
X PF_GOSIP
X PF_HYLINK
X PF_IMPLINK
X PF_INET
X PF_LAT
X PF_MAX
X PF_NBS
X PF_NIT
X PF_NS
X PF_OSI
X PF_OSINET
X PF_PUP
X PF_SNA
X PF_UNIX
X PF_UNSPEC
X PF_X25
X SOCK_DGRAM
X SOCK_RAW
X SOCK_RDM
X SOCK_SEQPACKET
X SOCK_STREAM
X SOL_SOCKET
X SOMAXCONN
X SO_ACCEPTCONN
X SO_BROADCAST
X SO_DEBUG
X SO_DONTLINGER
X SO_DONTROUTE
X SO_ERROR
X SO_KEEPALIVE
X SO_LINGER
X SO_OOBINLINE
X SO_RCVBUF
X SO_RCVLOWAT
X SO_RCVTIMEO
X SO_REUSEADDR
X SO_SNDBUF
X SO_SNDLOWAT
X SO_SNDTIMEO
X SO_TYPE
X SO_USELOOPBACK
X);
X
Xsub sockaddr_in {
X if (@_ == 6 && wantarray) { # perl5.001m compat; use this && die
X my($af, $port, @quad) = @_;
X pack_sockaddr_in($port, inet_aton(join('.', @quad)));
X } elsif (wantarray) {
X unpack_sockaddr_in($_[0])
X } else {
X pack_sockaddr_in(@_[0,1])
X }
X}
X
Xsub sockaddr_un {
X wantarray
X ? unpack_sockaddr_un($_[0])
X : pack_sockaddr_un($_[0])
X}
X
X
Xsub AUTOLOAD {
X local($constname);
X ($constname = $AUTOLOAD) =~ s/.*:://;
X $val = constant($constname, @_ ? $_[0] : 0);
X if ($! != 0) {
X if ($! =~ /Invalid/) {
X $AutoLoader::AUTOLOAD = $AUTOLOAD;
X goto &AutoLoader::AUTOLOAD;
X }
X else {
X ($pack,$file,$line) = caller;
X croak "Your vendor has not defined Socket macro $constname, used";
X }
X }
X eval "sub $AUTOLOAD { $val }";
X goto &$AUTOLOAD;
X}
X
Xbootstrap Socket;
X
X# Preloaded methods go here. Autoload methods go after __END__, and are
X# processed by the autosplit program.
X
X1;
X__END__
END_OF_FILE
if test 6662 -ne `wc -c <'Socket-1.2/Socket.pm'`; then
echo shar: \"'Socket-1.2/Socket.pm'\" unpacked with wrong size!
fi
# end of 'Socket-1.2/Socket.pm'
fi
if test -f 'Socket-1.2/Socket.xs' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Socket-1.2/Socket.xs'\"
else
echo shar: Extracting \"'Socket-1.2/Socket.xs'\" \(12939 characters\)
sed "s/^X//" >'Socket-1.2/Socket.xs' <<'END_OF_FILE'
X#include "EXTERN.h"
X#include "perl.h"
X#include "XSUB.h"
X
X#ifndef VMS
X# ifdef I_SYS_TYPES
X# include <sys/types.h>
X# endif
X#include <sys/socket.h>
X#include <sys/un.h>
X# ifdef I_NETINET_IN
X# include <netinet/in.h>
X# endif
X#include <netdb.h>
X#include <arpa/inet.h>
X#else
X#include "sockadapt.h"
X#endif
X
X#ifndef AF_NBS
X#undef PF_NBS
X#endif
X
X#ifndef AF_X25
X#undef PF_X25
X#endif
X
X#ifndef INADDR_NONE
X#define INADDR_NONE 0xffffffff
X#endif /* INADDR_NONE */
X#ifndef INADDR_LOOPBACK
X#define INADDR_LOOPBACK 0x7F000001
X#endif /* INADDR_LOOPBACK */
X
X
Xstatic int
Xnot_here(s)
Xchar *s;
X{
X croak("Socket::%s not implemented on this architecture", s);
X return -1;
X}
X
Xstatic double
Xconstant(name, arg)
Xchar *name;
Xint arg;
X{
X errno = 0;
X switch (*name) {
X case 'A':
X if (strEQ(name, "AF_802"))
X#ifdef AF_802
X return AF_802;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_APPLETALK"))
X#ifdef AF_APPLETALK
X return AF_APPLETALK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_CCITT"))
X#ifdef AF_CCITT
X return AF_CCITT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_CHAOS"))
X#ifdef AF_CHAOS
X return AF_CHAOS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_DATAKIT"))
X#ifdef AF_DATAKIT
X return AF_DATAKIT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_DECnet"))
X#ifdef AF_DECnet
X return AF_DECnet;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_DLI"))
X#ifdef AF_DLI
X return AF_DLI;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_ECMA"))
X#ifdef AF_ECMA
X return AF_ECMA;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_GOSIP"))
X#ifdef AF_GOSIP
X return AF_GOSIP;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_HYLINK"))
X#ifdef AF_HYLINK
X return AF_HYLINK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_IMPLINK"))
X#ifdef AF_IMPLINK
X return AF_IMPLINK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_INET"))
X#ifdef AF_INET
X return AF_INET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_LAT"))
X#ifdef AF_LAT
X return AF_LAT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_MAX"))
X#ifdef AF_MAX
X return AF_MAX;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_NBS"))
X#ifdef AF_NBS
X return AF_NBS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_NIT"))
X#ifdef AF_NIT
X return AF_NIT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_NS"))
X#ifdef AF_NS
X return AF_NS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_OSI"))
X#ifdef AF_OSI
X return AF_OSI;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_OSINET"))
X#ifdef AF_OSINET
X return AF_OSINET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_PUP"))
X#ifdef AF_PUP
X return AF_PUP;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_SNA"))
X#ifdef AF_SNA
X return AF_SNA;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_UNIX"))
X#ifdef AF_UNIX
X return AF_UNIX;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_UNSPEC"))
X#ifdef AF_UNSPEC
X return AF_UNSPEC;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "AF_X25"))
X#ifdef AF_X25
X return AF_X25;
X#else
X goto not_there;
X#endif
X break;
X case 'B':
X break;
X case 'C':
X break;
X case 'D':
X break;
X case 'E':
X break;
X case 'F':
X break;
X case 'G':
X break;
X case 'H':
X break;
X case 'I':
X break;
X case 'J':
X break;
X case 'K':
X break;
X case 'L':
X break;
X case 'M':
X if (strEQ(name, "MSG_DONTROUTE"))
X#ifdef MSG_DONTROUTE
X return MSG_DONTROUTE;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "MSG_MAXIOVLEN"))
X#ifdef MSG_MAXIOVLEN
X return MSG_MAXIOVLEN;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "MSG_OOB"))
X#ifdef MSG_OOB
X return MSG_OOB;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "MSG_PEEK"))
X#ifdef MSG_PEEK
X return MSG_PEEK;
X#else
X goto not_there;
X#endif
X break;
X case 'N':
X break;
X case 'O':
X break;
X case 'P':
X if (strEQ(name, "PF_802"))
X#ifdef PF_802
X return PF_802;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_APPLETALK"))
X#ifdef PF_APPLETALK
X return PF_APPLETALK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_CCITT"))
X#ifdef PF_CCITT
X return PF_CCITT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_CHAOS"))
X#ifdef PF_CHAOS
X return PF_CHAOS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_DATAKIT"))
X#ifdef PF_DATAKIT
X return PF_DATAKIT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_DECnet"))
X#ifdef PF_DECnet
X return PF_DECnet;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_DLI"))
X#ifdef PF_DLI
X return PF_DLI;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_ECMA"))
X#ifdef PF_ECMA
X return PF_ECMA;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_GOSIP"))
X#ifdef PF_GOSIP
X return PF_GOSIP;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_HYLINK"))
X#ifdef PF_HYLINK
X return PF_HYLINK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_IMPLINK"))
X#ifdef PF_IMPLINK
X return PF_IMPLINK;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_INET"))
X#ifdef PF_INET
X return PF_INET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_LAT"))
X#ifdef PF_LAT
X return PF_LAT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_MAX"))
X#ifdef PF_MAX
X return PF_MAX;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_NBS"))
X#ifdef PF_NBS
X return PF_NBS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_NIT"))
X#ifdef PF_NIT
X return PF_NIT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_NS"))
X#ifdef PF_NS
X return PF_NS;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_OSI"))
X#ifdef PF_OSI
X return PF_OSI;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_OSINET"))
X#ifdef PF_OSINET
X return PF_OSINET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_PUP"))
X#ifdef PF_PUP
X return PF_PUP;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_SNA"))
X#ifdef PF_SNA
X return PF_SNA;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_UNIX"))
X#ifdef PF_UNIX
X return PF_UNIX;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_UNSPEC"))
X#ifdef PF_UNSPEC
X return PF_UNSPEC;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "PF_X25"))
X#ifdef PF_X25
X return PF_X25;
X#else
X goto not_there;
X#endif
X break;
X case 'Q':
X break;
X case 'R':
X break;
X case 'S':
X if (strEQ(name, "SOCK_DGRAM"))
X#ifdef SOCK_DGRAM
X return SOCK_DGRAM;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOCK_RAW"))
X#ifdef SOCK_RAW
X return SOCK_RAW;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOCK_RDM"))
X#ifdef SOCK_RDM
X return SOCK_RDM;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOCK_SEQPACKET"))
X#ifdef SOCK_SEQPACKET
X return SOCK_SEQPACKET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOCK_STREAM"))
X#ifdef SOCK_STREAM
X return SOCK_STREAM;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOL_SOCKET"))
X#ifdef SOL_SOCKET
X return SOL_SOCKET;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SOMAXCONN"))
X#ifdef SOMAXCONN
X return SOMAXCONN;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_ACCEPTCONN"))
X#ifdef SO_ACCEPTCONN
X return SO_ACCEPTCONN;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_BROADCAST"))
X#ifdef SO_BROADCAST
X return SO_BROADCAST;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_DEBUG"))
X#ifdef SO_DEBUG
X return SO_DEBUG;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_DONTLINGER"))
X#ifdef SO_DONTLINGER
X return SO_DONTLINGER;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_DONTROUTE"))
X#ifdef SO_DONTROUTE
X return SO_DONTROUTE;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_ERROR"))
X#ifdef SO_ERROR
X return SO_ERROR;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_KEEPALIVE"))
X#ifdef SO_KEEPALIVE
X return SO_KEEPALIVE;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_LINGER"))
X#ifdef SO_LINGER
X return SO_LINGER;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_OOBINLINE"))
X#ifdef SO_OOBINLINE
X return SO_OOBINLINE;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_RCVBUF"))
X#ifdef SO_RCVBUF
X return SO_RCVBUF;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_RCVLOWAT"))
X#ifdef SO_RCVLOWAT
X return SO_RCVLOWAT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_RCVTIMEO"))
X#ifdef SO_RCVTIMEO
X return SO_RCVTIMEO;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_REUSEADDR"))
X#ifdef SO_REUSEADDR
X return SO_REUSEADDR;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_REUSEPORT"))
X#ifdef SO_REUSEPORT
X return SO_REUSEPORT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_SNDBUF"))
X#ifdef SO_SNDBUF
X return SO_SNDBUF;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_SNDLOWAT"))
X#ifdef SO_SNDLOWAT
X return SO_SNDLOWAT;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_SNDTIMEO"))
X#ifdef SO_SNDTIMEO
X return SO_SNDTIMEO;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_TYPE"))
X#ifdef SO_TYPE
X return SO_TYPE;
X#else
X goto not_there;
X#endif
X if (strEQ(name, "SO_USELOOPBACK"))
X#ifdef SO_USELOOPBACK
X return SO_USELOOPBACK;
X#else
X goto not_there;
X#endif
X break;
X case 'T':
X break;
X case 'U':
X break;
X case 'V':
X break;
X case 'W':
X break;
X case 'X':
X break;
X case 'Y':
X break;
X case 'Z':
X break;
X }
X errno = EINVAL;
X return 0;
X
Xnot_there:
X errno = ENOENT;
X return 0;
X}
X
X
XMODULE = Socket PACKAGE = Socket
X
Xdouble
Xconstant(name,arg)
X char * name
X int arg
X
X
Xvoid
Xinet_aton(host)
X char * host
X CODE:
X {
X struct in_addr ip_address;
X struct hostent * phe;
X
X if (phe = gethostbyname(host)) {
X Copy( phe->h_addr, &ip_address, phe->h_length, char );
X } else {
X ip_address.s_addr = inet_addr(host);
X }
X
X ST(0) = sv_newmortal();
X if(ip_address.s_addr != INADDR_NONE) {
X sv_setpvn( ST(0), (char *)&ip_address, sizeof ip_address );
X }
X }
X
Xvoid
Xinet_ntoa(ip_address_sv)
X SV * ip_address_sv
X CODE:
X {
X STRLEN addrlen;
X struct in_addr addr;
X char * addr_str;
X char * ip_address = SvPV(ip_address_sv,addrlen);
X if (addrlen != sizeof(addr)) {
X croak("Bad arg length for %s, length is %d, should be %d",
X "Socket::inet_ntoa",
X addrlen, sizeof(addr));
X }
X
X Copy( ip_address, &addr, sizeof addr, char );
X addr_str = inet_ntoa(addr);
X
X ST(0) = sv_2mortal(newSVpv(addr_str, strlen(addr_str)));
X }
X
Xvoid
Xpack_sockaddr_un(pathname)
X char * pathname
X CODE:
X {
X struct sockaddr_un sun_ad; /* fear using sun */
X Zero( &sun_ad, sizeof sun_ad, char );
X sun_ad.sun_family = AF_UNIX;
X Copy( pathname, sun_ad.sun_path, sizeof sun_ad.sun_path, char );
X ST(0) = sv_2mortal(newSVpv((char *)&sun_ad, sizeof sun_ad));
X }
X
Xvoid
Xunpack_sockaddr_un(sun_sv)
X SV * sun_sv
X PPCODE:
X {
X STRLEN sockaddrlen;
X struct sockaddr_un addr;
X char * sun_ad = SvPV(sun_sv,sockaddrlen);
X
X if (sockaddrlen != sizeof(addr)) {
X croak("Bad arg length for %s, length is %d, should be %d",
X "Socket::unpack_sockaddr_un",
X sockaddrlen, sizeof(addr));
X }
X
X Copy( sun_ad, &addr, sizeof addr, char );
X
X if ( addr.sun_family != AF_UNIX ) {
X croak("Bad address family for %s, got %d, should be %d",
X "Socket::unpack_sockaddr_un",
X addr.sun_family,
X AF_UNIX);
X }
X ST(0) = sv_2mortal(newSVpv(addr.sun_path, strlen(addr.sun_path)));
X }
X
Xvoid
Xpack_sockaddr_in(port,ip_address)
X short port
X char * ip_address
X CODE:
X {
X struct sockaddr_in sin;
X
X Zero( &sin, sizeof sin, char );
X sin.sin_family = AF_INET;
X sin.sin_port = htons(port);
X Copy( ip_address, &sin.sin_addr, sizeof sin.sin_addr, char );
X
X ST(0) = sv_2mortal(newSVpv((char *)&sin, sizeof sin));
X }
X
Xvoid
Xunpack_sockaddr_in(sin_sv)
X SV * sin_sv
X PPCODE:
X {
X STRLEN sockaddrlen;
X struct sockaddr_in addr;
X short port;
X struct in_addr ip_address;
X char * sin = SvPV(sin_sv,sockaddrlen);
X if (sockaddrlen != sizeof(addr)) {
X croak("Bad arg length for %s, length is %d, should be %d",
X "Socket::unpack_sockaddr_in",
X sockaddrlen, sizeof(addr));
X }
X Copy( sin, &addr,sizeof addr, char );
X if ( addr.sin_family != AF_INET ) {
X croak("Bad address family for %s, got %d, should be %d",
X "Socket::unpack_sockaddr_in",
X addr.sin_family,
X AF_INET);
X }
X port = ntohs(addr.sin_port);
X ip_address = addr.sin_addr;
X
X EXTEND(sp, 2);
X PUSHs(sv_2mortal(newSViv(port)));
X PUSHs(sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address)));
X }
X
Xvoid
XINADDR_ANY()
X CODE:
X {
X struct in_addr ip_address;
X ip_address.s_addr = htonl(INADDR_ANY);
X ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address ));
X }
X
Xvoid
XINADDR_LOOPBACK()
X CODE:
X {
X struct in_addr ip_address;
X ip_address.s_addr = htonl(INADDR_LOOPBACK);
X ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address));
X }
X
Xvoid
XINADDR_NONE()
X CODE:
X {
X struct in_addr ip_address;
X ip_address.s_addr = htonl(INADDR_NONE);
X ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address));
X }
END_OF_FILE
if test 12939 -ne `wc -c <'Socket-1.2/Socket.xs'`; then
echo shar: \"'Socket-1.2/Socket.xs'\" unpacked with wrong size!
fi
# end of 'Socket-1.2/Socket.xs'
fi
echo shar: End of shell archive.
exit 0