Path: blob/main/ftp/mirror/files/patch-lchat.pl
16461 views
--- lchat.pl.orig 1998-05-29 12:05:46.000000000 -07001+++ lchat.pl 2009-02-20 09:33:47.000000000 -08002@@ -66,6 +66,7 @@3# Perl 5 has a special way of getting them via the 'use Socket'4# above.5$main'pf_inet = &Socket'PF_INET;6+ $main'af_inet = &Socket'AF_INET;7$main'sock_stream = &Socket'SOCK_STREAM;8local($name, $aliases, $proto) = getprotobyname( 'tcp' );9$main'tcp_proto = $proto;10@@ -74,6 +75,7 @@11# Perl 4 needs to have the socket.ph file created when perl was12# installed.13$main'pf_inet = &'PF_INET;14+ $main'af_inet = &'AF_INET;15$main'sock_stream = &'SOCK_STREAM;16local($name, $aliases, $proto) = getprotobyname( 'tcp' );17$main'tcp_proto = $proto;18@@ -85,6 +87,7 @@19# Use hardwired versions20# but who the heck would change these anyway? (:-)21$main'pf_inet = 2;22+ $main'af_inet = 2;23$main'sock_stream = 1; # Sigh... On Solaris set this to 224$main'tcp_proto = 6;25warn "lchat.pl: using hardwired in network constantants";26@@ -93,7 +96,6 @@27# Are we using the SOCKS version of perl?28$using_socks = 0; # 0=no (default), 1=yes2930-$sockaddr = 'S n a4 x8';31if( ! $on_win ){32chop( $thishost = `hostname` );33if( $thishost eq '' ){34@@ -107,6 +109,54 @@35$thishost = 'localhost';36}3738+#39+# $packedsocketname = _pack_sin($portnumber, $ipaddress)40+#41+sub _pack_sin42+{43+ my $packed;44+45+ if ( $] =~ /^5\.\d+$/ ) {46+ #47+ # FreeBSD has a slightly different (from the rest of the world)48+ # sockaddr_in definition, so rely on Socket module to handle it.49+ #50+ $packed = &Socket'pack_sockaddr_in(@_[0,1]);51+ } else {52+ #53+ # Old-fashioned way to set up sockaddr_in structure. Not54+ # correct for "modern" FreeBSD (>= 5.X ?)55+ #56+ $packed = pack('S n a4 x8', $main'af_inet, 0, $thisaddr);57+ }58+ return $packed;59+}60+61+#62+# ($port, $ipaddress) = _unpack_sin($packedsocketname)63+#64+sub _unpack_sin65+{66+ my @PA;67+68+ if ( $] =~ /^5\.\d+$/ ) {69+ #70+ # FreeBSD has a slightly different (from the rest of the world)71+ # sockaddr_in definition, so rely on Socket module to handle it.72+ # Docs say "Will croak if the structure does not have AF_INET in73+ # the right place."74+ #75+ @PA = &Socket'unpack_sockaddr_in($_[0]);76+ } else {77+ #78+ # Old-fashioned way to parse sockaddr_in structure. Not79+ # correct for "modern" FreeBSD (>= 5.X ?)80+ #81+ (undef, @PA) = unpack('S n a4 x8', $_[0]);82+ }83+ return @PA;84+}85+8687## &chat'open_port("server.address",$port_number);88## opens a named or numbered TCP server89@@ -117,7 +167,7 @@9091# We may be multi-homed, start with 0, fixup once connexion is made92$thisaddr = "\0\0\0\0" ;93- $thisproc = pack($sockaddr, 2, 0, $thisaddr);94+ $thisproc = &_pack_sin(0, $thisaddr);9596if ($server =~ /^(\d+)+\.(\d+)\.(\d+)\.(\d+)$/) {97$serveraddr = pack('C4', $1, $2, $3, $4);98@@ -128,7 +178,7 @@99}100$serveraddr = $x[4];101}102- $serverproc = pack($sockaddr, 2, $port, $serveraddr);103+ $serverproc = &_pack_sin($port, $serveraddr);104unless (socket(S, $main'pf_inet, $main'sock_stream, $main'tcp_proto)) {105($!) = ($!, close(S)); # close S while saving $!106return undef;107@@ -150,9 +200,9 @@108# We opened with the local address set to ANY, at this stage we know109# which interface we are using. This is critical if our machine is110# multi-homed, with IP forwarding off, so fix-up.111- local($fam,$lport);112- ($fam,$lport,$thisaddr) = unpack($sockaddr, getsockname(S));113- $thisproc = pack($sockaddr, 2, 0, $thisaddr);114+ local($lport);115+ ($lport,$thisaddr) = &_unpack_sin(getsockname(S));116+ $thisproc = &_pack_sin(0, $thisaddr);117# end of post-connect fixup118select((select(S), $| = 1)[0]);119return 1;120@@ -161,13 +211,13 @@121# Similar to open_port, but does less. Used for PASV code with ftp.pl122# -Erez Zadok.123sub open_newport { ## public124- local($server, $port, $newsock) = @_;125+ local($server, $port, *newsock) = @_;126127local($serveraddr,$serverproc);128129# We may be multi-homed, start with 0, fixup once connexion is made130$thisaddr = "\0\0\0\0" ;131- $thisproc = pack($sockaddr, 2, 0, $thisaddr);132+ $thisproc = &_pack_sin(0, $thisaddr);133134if ($server =~ /^(\d+)+\.(\d+)\.(\d+)\.(\d+)$/) {135$serveraddr = pack('C4', $1, $2, $3, $4);136@@ -178,20 +228,20 @@137}138$serveraddr = $x[4];139}140- $serverproc = pack($sockaddr, 2, $port, $serveraddr);141+ $serverproc = &_pack_sin($port, $serveraddr);142143- unless (connect($newsock, $serverproc)) {144- ($!) = ($!, close($newsock)); # close newsock while saving $!145+ unless (connect(newsock, $serverproc)) {146+ ($!) = ($!, close(newsock)); # close newsock while saving $!147return undef;148}149# We opened with the local address set to ANY, at this stage we know150# which interface we are using. This is critical if our machine is151# multi-homed, with IP forwarding off, so fix-up.152- local($fam,$lport);153- ($fam,$lport,$thisaddr) = unpack($sockaddr, getsockname($newsock));154- $thisproc = pack($sockaddr, 2, 0, $thisaddr);155+ local($lport);156+ ($lport,$thisaddr) = &_unpack_sin(getsockname(newsock));157+ $thisproc = &_pack_sin(0, $thisaddr);158# end of post-connect fixup159- select((select($newsock), $| = 1)[0]);160+ select((select(newsock), $| = 1)[0]);161return 1;162}163##############################################################################164165166