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