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.