Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This works for the majority of IP's except when there is a 10 in the first, second or thrid position in the IP ie 10.10.10.1. This packs correctly, but fails after sending it to the server. Where it does the following.pack("a4", inet_aton("192.168.1.1"));
I am including a sample client:unpack("a4", inet_ntoa($buffer);
Here is a sample server that exhibits the same error.use IO::Socket; $IP_Address = '10.10.10.1'; $buffer = inet_aton($IP_Address); $buffer = pack("a4", $buffer); my $sock = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => '7070', Proto => 'tcp' ); die "Could not create socket: $!\n" unless $sock; print $sock $buffer; close($sock);
Thank You for your wisdom.use IO::Socket; my $new_sock; my $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; while ($new_sock = $sock->accept()){ while(defined($buffer = <$new_sock>)) { $buffer = unpack("a4", $buffer); $buffer = inet_ntoa($buffer); print $buffer, "\n"; } } close($sock);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is the best way to pack an ip address?
by Juerd (Abbot) on Jan 14, 2002 at 03:05 UTC | |
|
Re: What is the best way to pack an ip address?
by chipmunk (Parson) on Jan 14, 2002 at 06:38 UTC | |
|
Re: What is the best way to pack an ip address?
by metadoktor (Hermit) on Jan 14, 2002 at 02:37 UTC |