Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

sockets - Unpack a buffer which is packed by perl with template "N/a* N/a*" in golang

I am new to perl. I need to write a golang code which read UDP package sent from a perl UDP socket client. Basically, the perl client packs data using the template "N/a* N/a*" like the following:

$them = pack($sockaddr,&AF_INET, $data_port, $broadaddr);
$actual_data = pack("N/a* N/a*", $string1, $string2);
send(S,$actual_data,0,$them) || die $!;

My question is:

  1. What does "N/a* N/a*" actually means? A simple explanation would be helpful. How two strings are actually packed?
  2. How i can write a similar packing function in golang given two unicode strings; and if I got a packed buffer sent from perl UDP client, how i can write a corresponding function "in golang" to unpack it. Is there any library which can handle this so that I can use golang on par with perl for socket programming.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...