Packet Parsing

I'm writting a bunch of standards for interpreting net communication,
and built my first icmp echo request interpreter, and wanted to
release it to the public, it may be of some use to someone... I will
post back the entire class, but this was just a quick sandbox code I
wrote up just to understand the protocol standard...

<?php

$data = "\x08\x00\x19\x2f\x00\x00\x00\x00\x70\x69\x6e\x67";

/*
8 bits in a byte
strlen() returns length of a string in bytes.
*/

//$data = "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";

echo 'String $data is ' . strlen($data) . ' bytes in size, or ' .
(strlen($data) * 8) . ' bits in size' . "\n";

var_dump($data);

var_dump(unpack("Ctype/Ccode/Cchecksum/nidentifier/nsequence Number/
Ndata", $data));

print_r(unpack("Ctype/Ccode/Cchecksum/nidentifier/nsequenceN umber/
Ndata", $data));

echo implode(' ', unpack('C*', $data)) . "\n";

foreach (unpack("Ctype/Ccode/Cchecksum/nidentifier/nsequenceNumber/ [at] 8/
c*data", $data) as $key => $string) {
echo $key . ' => '. str_pad(dechex($string), 2, '0', STR_PAD_LEFT) .
"\n";
}

?>

Comments are welcome... please!
d43m0n at shaw dot ca [ Fr, 04 Mai 2007 11:04 ] [ ID #1704698 ]
PHP » alt.php » Packet Parsing

Vorheriges Thema: Using SendMail in Forms w/PHP HTML
Nächstes Thema: Login and remember me