bytes over network

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi All,
   I am sending some data over the network using IO::Socket::INET and
when I print the length of scalar it prints as 1464
my $size = length($send_buf);

But on the other side I see data coming in size of 4096 (from
tcpdump).But I want to send only 1464 bytes only.Kindly help

Ankur Goel

Re: bytes over network

On Tue, 16 Jun 2009 23:02:38 -0700 (PDT), ""

Quoted text here. Click to load it

Can you please read the doc's for that module and then post
your code. Nobody here is a mind reader!


Re: bytes over network

use IO::Socket;
use bytes;
use Time::HiRes qw(usleep nanosleep);
my $nfcapd_file = shift;
my $config_file = shift;

my $ip_addr = shift;
my $port_num = shift;
my $sock = IO::Socket::INET->new(PeerAddr => "$ip_addr",
                                 PeerPort => "$port_num",
                                 Proto    => 'udp');

`cp $nfcapd_file /tmp/$$.netflow`;
open NFCAP,"<$nfcapd_file" || die "Cannot open nfcapd file\n";
open TMPCAP ,"</tmp/$$.netflow"|| die "Cannot open tmp file\n";
binmode NFCAP;
binmode TMPCAP;
my ($buf, $data, $n);
while (($n = read NFCAP, $data,24 ) != 0)
        my $bytes = 24;
        my ($version,$records_num,$sys_uptime,$unix_sec,
$sample_interval) = unpack("n n N N N N C C n",$data);
        print "$version,$records_num\n";
        my $count = 0;
        while ($count < $records_num)
                $n = read NFCAP, $data,48;
                $bytes +=48;
                my ($src_addr,$dst_addr,$next_hop,$snmp_input,
                        $src_mask,$dst_mask,$pad2) = unpack("N N N n n
N N N N n n C C C C n n C C n",$data);
                #print "$src_addr\n";
        my $send_buf;
        $n = read TMPCAP,$send_buf,$bytes;
        my $pack_data = pack("a$bytes",$send_buf);
        print $sock $pack_data;

Re: bytes over network

Quoted text here. Click to load it

"Note that UDP datagrams are not a bytestream and should not be treated as such.
This makes using I/O mechanisms with internal buffering like stdio (i.e. print()
and friends)
especially cumbersome. Use syswrite(), or better send(), like in the example

Quoted text here. Click to load it

Site Timeline