Hi, you can use two package: Socket, and Net::RawIP (needs libpcap);
With Net::RawIP you can built packet (ip,udp,tcp) how you want and to
analize the
packet.
Ex.
use Net::RawIP qw(:pcap);
use Socket;
$a=new Net::RawIP;
$|=1;
$filtro='ip proto \\tcp and (dst host '.$host.' or src host '.$host.')';
##$host is a variabile that contains the host in dot , or simbolic nane
notation
$tout=60;
$size=1500;
$pcap=$a->pcapinit('eth0',$filtro,$size,$tout);
$offset=linkoffset($pcap);
for(;;){
$pc=&next($pcap,$t);
if($pc){
$a->bset(substr($pc,$offset));
##you can read the packet;
($ipsg)=$a->get({ip=>['saddr']}); ##(IP address source)
$ipsg=inet_ntoa(pack("N",$ipsg)); ## Trasform the bynary
pack
in a dot
notation
($ipdst)=$a->get({ip=>['daddr']}); ##(IP address destination)
$ipdst=inet_ntoa(pack("N",$ipdst));
($portsg)=$a->get({tcp=>['source']}); #port source
($portdst)=$a->get({tcp=>['dest']}); ## port destination
($syn)=$a->get({tcp=>['syn']}); #es: rst,ack,psh....
($seq)=$a->get({tcp=>['seq']}); ###seq number
$seq=sprintf("%u",$seq);
##
($ack_seq)=$a->get({tcp=>['ack_seq']}); ### ack number
$ack_seq=sprintf("%u",$ack_seq);
($data)=$a->get({tcp=>['data']}); ### data !!!!
$d1=substr $data,0,1 ##extract the first byte
($h1)=unpack("H2",$d1); ##convert in HEX format
}
}
you can built packet es:
$b=new Net::RawIP;
$b->set(ip=>{saddr=>$sip,daddr=>$dip},tcp=>{source=>$ports,dest=>$ports,ack=>1,syn=>,seq=>$x,ack_seq=>$y,data=>$dt}});
$b->send;
Bye
>
> I was wondering if any of you guys could help me out with some insight
> on building a data structure for sending and receiving binary data.
>
> Here is what I am doing:
> 1. building a tcp client to query a server with data
> 2. the client sends the binary data stream, and then receives binary
> data stream from server, and closes the socket
> 3. I would like to be able to build a structure where I can modify
> certain bytes (whether decimal, hex, or binary) before sending the
> stream, such as to create a "message", and then sending the message to
the server.
>
> 4. When the message is received, I would like to be able to read it
> into an ordered structure so that I can retrieve certain bits after I
> have decoded the stream into decimal or hex ASCII representations.
>
> For example, my packet sniffer is showing the following:
> 0000: 000a c844 0000 f00a 0401 0008 0009 c844 ...D...........D
> 0010: 0000 f00b 0000 0000 07c8 4080 00dc a000 ..........@.....
>
> I need to read each one of these bytes in a de-limited way.
>
> Has anyone done this before or can give me any kind of insight? Is
> there another list that would be better for this? I would GREATLY
> appreciate any and all insight.
>
> Thanks,
> Jason O.
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]