Ahoy, Monks ..
Here is some working code that I'd like to make better/more efficient. It has to do with decoding DNS and Netbios names in captured packets (pcap).
I freely admit that the current method uses brute-force and inefficient methods. If someone has done something in this arena, please enlighten. tia .
sub Decode_DNS_Name(){
#DNS/Netbios Name decoder
# This homegrown crazy bit of code developed by packet observation
+ only.
my $nameref = shift;
my ($retval, $namelen, $b1, $b2, $lastchar);
$namelen = ord(substr($$nameref,0,1));
for (my $i=1; $i <= $namelen; $i+=2){
$b1=(ord(substr($$nameref,$i,1))) - 0x41; #Don't ask me why .
+.
$b2=(ord(substr($$nameref,$i+1,1))) - 0x41; # It just works thi
+s way!!
$retval .= chr( ($b1 << 4)+$b2);
}
# Last byte of NB name is the "Type". chop it if it is ..
if (($lastchar = chop($retval)) gt ' '){
# Ooops ... That was a real part of the name ..Need to restore i
+t..
$retval .= $lastchar;
};
#Trim trailing blanks
$retval =~s/\s*$//;
return $retval ; #.
}
Yes - I know - I should post sample Input and output strings .. Will get to that soon.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|