Hi I have the .h file of a program that spits out a data file which is Binary Output. The binary file is a series of fixed length records. In C, each record has the format which is in the script.
I thought I could use unpack to read the data, and I am having no success. PLEASE let me know if I'm using unpack correctly: #!/bin/perl use strict; use POSIX 'strftime'; use warnings; # #struct binary_log_entry { # int major_protocol; /* eg. ETHERTYPE_IP */ # int minor_protocol; /* eg. IPPROTO_TCP */ # u_long src_ipaddress; /* Source IP Address */ # u_long dst_ipaddress; /* Destination IP Address */ # u_short src_port; /* Source port (if UDP or TCP) */ # u_short dst_port; /* Desintation port (if UDP or TCP) */ # time_t quanta_start; /* UNIX GMT time at start of quanta */ # time_t quanta_end; /* UNIX GMT time at end of quanta */ # u_long bytes_xfered; /* Number of bytes transfered during quanta */ #}; # this is the template we're going to feed to unpack( ) my $template = "i i A16 A16 s s l l A16"; #$template = "C*"; # open the file open(FILE,"/tmp/testiplog/file.binout") or die "Unable to open FILE:$!\n"; # read it in one record at a time while (<FILE>) { # unpack it, using our template my ($eth,$itcp,$src,$dst,$sport,$dport,$qstart,$qend,$bytes)=unpack($template,$_); #print "$eth,$itcp,$src,$dst,$sport,$dport,$qstart,$qend,$bytes\n"; print "$src,$dst,$sport,$dport,$qstart,$qend,$bytes\n"; } # close the file close(FILE); my current output: bash-2.03# ./ipbinread.pl |more 2048,17,[EMAIL PROTECTED] ÿ,3119,11382,-2139904511,5293878,@½ ÿ [EMAIL PROTECTED] ÿ†, [EMAIL PROTECTED],½ ©@,-17139,-256,155904,524288,† ¿?AÜà P@ 553648136,0,[EMAIL PROTECTED]@½ ÿ^L,1664,29476,-1346197450,872865792,[EMAIL PROTECTED] should be something like: 111.111.111.111, 222.222.222.222,5412,22,1086190725,1086191025,1160 Im stuck... Any help is really appreciated. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>