diff options
author | Andy Dougherty <doughera@lafcol.lafayette.edu> | 1995-10-31 03:33:09 +0000 |
---|---|---|
committer | Andy Dougherty <doughera@lafcol.lafayette.edu> | 1995-10-31 03:33:09 +0000 |
commit | 8e07c86ebc651fe92eb7e3b25f801f57cfb8dd6f (patch) | |
tree | bd67a65038befe4bef8b330a688bf7d915cab92f /ext/Socket | |
parent | e50aee73b3d4c555c37e4b4a16694765fb16c887 (diff) | |
download | perl-8e07c86ebc651fe92eb7e3b25f801f57cfb8dd6f.tar.gz |
This is my patch patch.1n for perl5.001.perl-5.001n
To apply, change to your perl directory, run the command above, then
apply with
patch -p1 -N < thispatch.
This is a consolidation patch. It contains many of the most commonly
applied or agreed-to patches that have been circulating since
patch.1m.
It also changes the 'unofficial patchlevel' in perl.c.
There are some problems (see items marked with '***').
I will attempt to address those in a patch.1o in a few days.
This patch contains the following packages:
My Jumbo Configure patch vs. 1m, with subsequent patches 1, 2, and 3.
Mainly, this provides easier use of local libraries, documents
the installation process in a new INSTALL file, moves important
questions towards the beginning, and improves detection of
signal names (mostly for Linux).
xsubpp-1.922.
Patches from Larry:
eval "1" memory leak patch (as modified by GSAR to apply to 5.001m).
NETaa14551 Infinite loop in formats,
NETaa13729 scope.c patch (fixed problems on AIX and others)
NETaa14138 "substr() & s///" (pp_hot.c)
Patches from ftp.perl.com:
ftp://ftp.perl.com/pub/perl/src/patches/closure-bug.patch,
version of 20 Sep 1995
Includes fix for NETaa14347 (32k limit in regex), and other
fixes.
ftp://ftp.perl.com/pub/perl/src/patches/debugger.patch,
version of 27 Aug 1995
ftp://ftp.perl.com/pub/perl/src/patches/glob-undef.patch,
version of 4 Sep 1995
NETaa14421 $_ doesn't undef
ftp://ftp.perl.com/pub/perl/src/patches/op-segfault.patch,
version of 21 Aug 1995
ftp://ftp.perl.com/pub/perl/src/patches/warn-ref-hash-key.patch,
version of 5 Jun 1995
Tim Bunce's Jumbo DynaLoader patch for Perl5.001m, which is
NETaa14636 Jumbo DynaLoader patch for Perl5.001m, and
Additional patch for NETaa14636 Jumbo DynaLoader patch for Perl5.001m
version of 09 Oct 1995.
***This needs some additional parentheses.***
MakeMaker-5.00. Supercedes NETaa13540 (VMS MakeMaker patches).
(Updates minimod.PL as well.)
***This has a couple of minor problems.
pod2man is run even if it isn't available.
LD_RUN_PATH gets set to some mysterious values.***
NETaa14657 Paul Marquess Net::Ping patch. I've included
Net-Ping-1.00.
NETaa14661 Dean Roehrich DProf. Installed as ext/Devel/DProf.
Configure should pick this up automatically. (5 Apr 1995
version.)
NETaa13742 Jack Shirazi Socket in 5.001. I've also included
his socket.t test in t/lib/socket.t.
c2ph-1.7.
Dean's perlapi patches of Oct 12, 1995, which superceded those
of Oct 8, 1995. This is the one that did
mv perlapi.pid perlxs.pod.
NETaa14310 Tim Bunce A trivial patch for configpm (handy for shell scripts)
DB_File-1.0 patch from Paul Marquess (pmarquess@bfsec.bt.co.uk)
last modified 7th October 1995
version 1.0
Added or updated the following hints files:
hints/hpux.sh
hints/ncr_tower.sh
hints/netbsd.sh
hints/ultrix.sh
Patch and enjoy.
Andy Dougherty doughera@lafcol.lafayette.edu
Dept. of Physics
Lafayette College, Easton PA 18042
Diffstat (limited to 'ext/Socket')
-rw-r--r-- | ext/Socket/Socket.pm | 79 | ||||
-rw-r--r-- | ext/Socket/Socket.xs | 134 |
2 files changed, 198 insertions, 15 deletions
diff --git a/ext/Socket/Socket.pm b/ext/Socket/Socket.pm index 86cc86c6b7..5a4b486a22 100644 --- a/ext/Socket/Socket.pm +++ b/ext/Socket/Socket.pm @@ -2,14 +2,19 @@ package Socket; =head1 NAME -Socket - load the C socket.h defines +Socket - load the C socket.h defines and structure manipulators =head1 SYNOPSIS use Socket; $proto = (getprotobyname('udp'))[2]; - socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto); + socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto); + $sockaddr_in = pack_sockaddr_in(AF_INET,7,inet_aton("localhost")); + $sockaddr_in = pack_sockaddr_in(AF_INET,7,INADDR_LOOPBACK); + connect(Socket_Handle,$sockaddr_in); + $peer = inet_ntoa((unpack_sockaddr_in(getpeername(Socket_Handle)))[2]); + =head1 DESCRIPTION @@ -19,10 +24,62 @@ file, this uses the B<h2xs> program (see the Perl source distribution) and your native C compiler. This means that it has a far more likely chance of getting the numbers right. -=head1 NOTE +In addition, some structure manipulation functions are available: + +=item inet_aton HOSTNAME + +Takes a string giving the name of a host, and translates that +to the 4-byte string (structure). Takes arguments of both +the 'rtfm.mit.edu' type and '18.181.0.24'. If the host name +cannot be resolved, returns undef. + +=item inet_ntoa IP_ADDRESS + +Takes a four byte ip address (as returned by inet_aton()) +and translates it into a string of the form 'd.d.d.d' +where the 'd's are numbers less than 256 (the normal +readable four dotted number notation for internet addresses). + +=item INADDR_ANY + +Note - does not return a number. + +Returns the 4-byte wildcard ip address which specifies any +of the hosts ip addresses. (A particular machine can have +more than one ip address, each address corresponding to +a particular network interface. This wildcard address +allows you to bind to all of them simultaneously.) +Normally equivalent to inet_aton('0.0.0.0'). + +=item INADDR_LOOPBACK + +Note - does not return a number. + +Returns the 4-byte loopback address. Normally equivalent +to inet_aton('localhost'). -Only C<#define> symbols get translated; you must still correctly -pack up your own arguments to pass to bind(), etc. +=item INADDR_NONE + +Note - does not return a number. + +Returns the 4-byte invalid ip address. Normally equivalent +to inet_aton('255.255.255.255'). + +=item pack_sockaddr_in FAMILY, PORT, IP_ADDRESS + +Takes three arguments, an address family (normally AF_INET), +a port number, and a 4 byte IP_ADDRESS (as returned by +inet_aton()). Returns the sockaddr_in structure with those +arguments packed in. For internet domain sockets, this structure +is normally what you need for the arguments in bind(), connect(), +and send(), and is also returned by getpeername(), getsockname() +and recv(). + +=item unpack_sockaddr_in SOCKADDR_IN + +Takes a sockaddr_in structure (as returned by pack_sockaddr_in()) +and returns an array of three elements: the address family, +the port, and the 4-byte ip-address. =cut @@ -33,6 +90,8 @@ use AutoLoader; require DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT = qw( + inet_aton inet_ntoa pack_sockaddr_in unpack_sockaddr_in + INADDR_ANY INADDR_LOOPBACK INADDR_NONE AF_802 AF_APPLETALK AF_CCITT @@ -130,16 +189,6 @@ sub AUTOLOAD { goto &$AUTOLOAD; } - -# pack a sockaddr_in structure for use in bind() calls. -# (here to hide the 'S n C4 x8' magic from applications) -sub sockaddr_in{ - my($af, $port, @quad) = @_; - my $pack = 'S n C4 x8'; # lookup $pack from hash using $af? - pack($pack, $af, $port, @quad); -} - - bootstrap Socket; # Preloaded methods go here. Autoload methods go after __END__, and are diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs index 7a0bf465b2..1f32dab79c 100644 --- a/ext/Socket/Socket.xs +++ b/ext/Socket/Socket.xs @@ -2,7 +2,19 @@ #include "perl.h" #include "XSUB.h" +#ifndef VMS +# ifdef I_SYS_TYPES +# include <sys/types.h> +# endif #include <sys/socket.h> +# ifdef I_NETINET_IN +# include <netinet/in.h> +# endif +#include <netdb.h> +#include <arpa/inet.h> +#else +#include "sockadapt.h" +#endif #ifndef AF_NBS #undef PF_NBS @@ -12,6 +24,14 @@ #undef PF_X25 #endif +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif /* INADDR_NONE */ +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7F000001 +#endif /* INADDR_LOOPBACK */ + + static int not_here(s) char *s; @@ -556,6 +576,7 @@ not_there: return 0; } + MODULE = Socket PACKAGE = Socket double @@ -563,3 +584,116 @@ constant(name,arg) char * name int arg + +void +inet_aton(host) + char * host + CODE: + { + struct in_addr ip_address; + struct hostent * phe; + + if (phe = gethostbyname(host)) { + Copy( phe->h_addr, &ip_address, phe->h_length, char ); + } else { + ip_address.s_addr = inet_addr(host); + } + + ST(0) = sv_newmortal(); + if(ip_address.s_addr != INADDR_NONE) { + sv_setpvn( ST(0), (char *)&ip_address, sizeof ip_address ); + } + } + +void +inet_ntoa(ip_address_sv) + SV * ip_address_sv + CODE: + { + STRLEN addrlen; + struct in_addr addr; + char * addr_str; + char * ip_address = SvPV(ip_address_sv,addrlen); + if (addrlen != sizeof(addr)) { + croak("Bad arg length for %s, length is %d, should be %d", + "Socket::inet_ntoa", + addrlen, sizeof(addr)); + } + + Copy( ip_address, &addr, sizeof addr, char ); + addr_str = inet_ntoa(addr); + + ST(0) = sv_2mortal(newSVpv(addr_str, strlen(addr_str))); + } + +void +pack_sockaddr_in(family,port,ip_address) + short family + short port + char * ip_address + CODE: + { + struct sockaddr_in sin; + + Zero( &sin, sizeof sin, char ); + sin.sin_family = family; + sin.sin_port = htons(port); + Copy( ip_address, &sin.sin_addr, sizeof sin.sin_addr, char ); + + ST(0) = sv_2mortal(newSVpv((char *)&sin, sizeof sin)); + } + +void +unpack_sockaddr_in(sin_sv) + SV * sin_sv + PPCODE: + { + STRLEN sockaddrlen; + struct sockaddr_in addr; + short family; + short port; + struct in_addr ip_address; + char * sin = SvPV(sin_sv,sockaddrlen); + if (sockaddrlen != sizeof(addr)) { + croak("Bad arg length for %s, length is %d, should be %d", + "Socket::unpack_sockaddr_in", + sockaddrlen, sizeof(addr)); + } + + Copy( sin, &addr,sizeof addr, char ); + family = addr.sin_family; + port = ntohs(addr.sin_port); + ip_address = addr.sin_addr; + + EXTEND(sp, 3); + PUSHs(sv_2mortal(newSViv(family))); + PUSHs(sv_2mortal(newSViv(port))); + PUSHs(sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address))); + } + +void +INADDR_ANY() + CODE: + { + struct in_addr ip_address; + ip_address.s_addr = htonl(INADDR_ANY); + ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address )); + } + +void +INADDR_LOOPBACK() + CODE: + { + struct in_addr ip_address; + ip_address.s_addr = htonl(INADDR_LOOPBACK); + ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address)); + } + +void +INADDR_NONE() + CODE: + { + struct in_addr ip_address; + ip_address.s_addr = htonl(INADDR_NONE); + ST(0) = sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address)); + } |