bytes over network

A

ankugoe7

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

Thanks
Ankur Goel
 
S

sln

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

Thanks
Ankur Goel

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

-sln
 
A

ankur

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,
$unix_nsec,$flow_seen,$engine_type,$engine_id,
$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,
$snmp_output,$packets_in_flow,$layer3_packets,
$sys_up_time,$sys_up_last,$src_port,$dst_port,
$unused_byte,$tcp_flag,$prot,$tos,$src_as,$dst_as,
$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);
$count++;
#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;
usleep(10000);
}
 
S

sln

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,
$unix_nsec,$flow_seen,$engine_type,$engine_id,
$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,
$snmp_output,$packets_in_flow,$layer3_packets,
$sys_up_time,$sys_up_last,$src_port,$dst_port,
$unused_byte,$tcp_flag,$prot,$tos,$src_as,$dst_as,
$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);
$count++;
#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;
^^^^^

file:///C:/Perl/html/lib/pods/perlipc.html#udp__message_passing
"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 below."
 

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top