I am sending a request to DNS server and I think I am getting the packed reply back from the server,but I don't know how to unpack the reply and print it on the screen, pleae help , thanks
#!/usr/bin/perl use IO::Socket; &dnsQueryPacket($ARGV[0],$ARGV[1]); sub dnsQueryPacket{ my $hostname = $_[0]; # my @labels = split(/\./, $hostname) ; my $n = scalar(@labels) ; +my $question = pack("(C/a*)$n C n2", @labels, 0, 1, 1) ; my @labels; my $nlabels = 0; my @labels = split(/\./, $hostname) ; my $n = scalar(@labels) ; my $question = pack("(C/a*)$n C n2", @labels, 0, 1, 1) ; $header1 = &dnsheader; $server = '130.149.2.12'; $sock = new IO::Socket::INET (PeerAddr=>$server,PeerPort=>'53',Proto=>'udp') or die "Can't Connect" +; #sending request $sock->send($header1.$question); #receiveing request $sock->recv($buf,512); close($sock); } sub dnsheader{ $id = 1000; $qr_Opcode_aa_tc_rd = '00000000'; $ra_Z_Rcode = '00000000'; $Qdcount = 1; $Ancount = 0; $Nscount = 0; $Arcount = 0; $header = pack("n,b8,b8,n4",$id++, "$qr_Opcode_aa_tc_rd",#qr,opcode,aa,tc,rd fields "$ra_Z_Rcode",#ra,Z,Rcode fields "$Qdcount",#one question(Qdcount) "$Ancount",#no answers (ancount) "$Nscount", "$Arcount");#no addtl rr's return $header; }

In reply to how to get reply from dns server by tokhi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.