Here are two solutions and the problem.
cheako@arcadia:~$ perl warn unpack("B620",pack( 'B8 C3 N10 B32', '00100011', '0', '0', '0', '0', '0', '0', '0', '0', 1425691777, 761152, '0', '0', 1425691777, 761152 )); 00100011000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 00000000000010111001110101000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 10111000000000000000000000000000 at - line 1. Different output, but identical input :/. cheako@arcadia:~$ perl warn unpack("B620",pack( 'B8 C3 N11', '00100011', '0', '0', '0', '0', '0', '0', '0', '0', 1425691777, 761152, '0', '0', 1425691777, 761152 )); cheako@arcadia:~$ perl warn unpack("B620",pack( 'B8 C3 N11', '00100011', '0', '0', '0', '0', '0', '0', '0', '0', 1425691777, 761152, '0', '0', 1425691777, 761152 )); 00100011000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 00000000000010111001110101000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 00000000000010111001110101000000 at - line 1. cheako@arcadia:~$ perl warn unpack("B620",pack( 'B8 C3 N10 B32', '00100011', '0', '0', '0', '0', '0', '0', '0', '0', 1425691777, 761152, '0', '0', 1425691777, '00000000000010111001110101000000' )); 00100011000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 00000000000010111001110101000000 00000000000000000000000000000000 00000000000000000000000000000000 01010100111110100101010010000001 00000000000010111001110101000000 at - line 1.

I've a lot of experience with pack and unpack and every time I learn something new, seems they never behave the way one would think they should. Check it with a warn unpack("B384",$send_sntp_packet) the best thing you can do at times like this is add in warn every branch.

my@argsforpacksend_sntp_packet=($client_li_vm_mode , + $client_stratum , $client_poll , $client_precision , $client_root_de +lay , $client_dispersion , $client_reference_identifier , $client_ref +erence_timestamp_sec , $client_reference_timestamp_microsec , $client +_originate_timestamp_sec , $client_originate_timestamp_microsec , $cl +ient_receive_timestamp_sec , $client_receive_timestamp_microsec , $cl +ient_transmit_sec , $client_transmit_microsec); warn Dumper \@argsfo +rpacksend_sntp_packet; my $send_sntp_packet = pack "B8 C3 N10 B32", @argsforpacksend_sntp_p +acket; warn unpack("B384",$send_sntp_packet)
Wrap each call to pack/unpack like this and you'll see what's wrong.

In reply to Re: SNTP pack and unpack by cheako
in thread SNTP pack and unpack by thanos1983

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.