Re: Bus error in LWP/Perl5

Gisle Aas (aas@oslonett.no)
Tue, 07 Nov 1995 11:29:19 +0100


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)