Reason for specified Error Occurence

R

Ranjit

Hi Perl pals,

Could any one let us know the reason why the below error is showing
from this code.

ERROR :

Use of uninitialized value in subroutine entry at C:/Perl/lib/
Socket.pm line 373.
Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4
at C:/Perl/lib/Socket.pm line 373.


#!/usr/bin/perl
use Socket;
$proto = getprotobyname('tcp');
$domain = PF_INET;
$type = SOCK_STREAM;
socket(CLIENT,$domain,$type,$proto);

$port = 0 ;
$ipaddr = INADDR_ANY;
$sockaddr = sockaddr_in($port,$ipaddr);
bind(CLIENT,$sockaddr);
print "sathi";

$host = 'www.yahoo.com';
$port = getservbyname('http','tcp');
$ip_addr= inet_aton($host);
$sockaddr = sockaddr_in($port,$ip_addr);
connect(CLIENT,$sockaddr);

Thanks in Advance

Regards,
Ranjit
 
D

Dr.Ruud

Ranjit schreef:
Could any one let us know the reason why the below error is showing
from this code.

ERROR :

Use of uninitialized value in subroutine entry at C:/Perl/lib/
Socket.pm line 373.
Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4
at C:/Perl/lib/Socket.pm line 373.


#!/usr/bin/perl

Missing:

use strict;
use warnings;

use Socket;
$proto = getprotobyname('tcp');
$domain = PF_INET;
$type = SOCK_STREAM;

printf "proto:%s, domain:%s, type:%s\n",
$proto, $domain, $type;
socket(CLIENT,$domain,$type,$proto);

Missing: test for succes.

$port = 0 ;
$ipaddr = INADDR_ANY;
$sockaddr = sockaddr_in($port,$ipaddr);

printf ...
bind(CLIENT,$sockaddr);

test ...
print "sathi";

$host = 'www.yahoo.com';
$port = getservbyname('http','tcp');
$ip_addr= inet_aton($host);

printf ...
$sockaddr = sockaddr_in($port,$ip_addr);

printf ...
connect(CLIENT,$sockaddr);

test ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top