Don't know if it actually solves your problem (untested!):
# creating the packet chunks
my $packet_eth = $ethernet->encode();
my $packet_ip = $ip->encode();
my $packet = $packet_eth
. (0 x (60 - length($packet_eth) - length($packet_ip)))
. $packet_ip;
The "x" operator does the right thing when (60 - length($packet_eth) - length($packet_ip)) isn't positive, of course.
30-sec-after update: it would probably pad with character '0' instead of nulls as you want; a quick hack could be:
# creating the packet chunks
my $packet_eth = $ethernet->encode();
my $packet_ip = $ip->encode();
my $packet = $packet_eth
. (pack 'H*', ('00' x (60 - length($packet_eth) - length($packet_ip
+)))) # Note 0 -> 00
. $packet_ip;
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.
| [reply] [d/l] [select] |
Thanks a lot guys, it was very helpful !
Mosh.
| [reply] |
A quick one on CPAN, lists a few interesting possibilities:
packet
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
| [reply] |
sub padr{ substr $_[ 0 ] . $_[ 1 ] x $_[ 2 ], 0, $_[ 2 ]}
sub padl{ substr $_[ 1 ] x $_[ 2 ] . $_[ 0 ], -$_[ 2 ] }
print padl 'fred', '.', 20;
................fred
print padr 'fred', '.', 20;
fred................
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] |
| [reply] |
| [reply] [d/l] |
# ...
$packet = sprintf("%-60s",$packet);
$packet =~ s/\s/\0/sg; #<-- kludgey
#...
I couldn't get sprintf to pad with a certain character and left-justify at the same time - maybe someone else can suggest something? | [reply] [d/l] |
| [reply] |
Hi all,
Sorry if I'm missing something, but isn't this what pack() is for? E.g.
my $packet = pack "a60", $data;
I'm afraid I don't know anything about packet structures.
Jim | [reply] [d/l] [select] |