Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new to perl, I have requirement that Perl script has to send UDP Packet to other machine where C application receives the PDU. I know how to decode the PDU in C application after receiving from the socket, but not sure how to encode the PDU in perl script, could anybody help me here ? At the sender side(Perl) has to send three unsigned 32 bit numbers followed by one unsinged 16bit number in the PDU, At the receiving end(C application) has the following code snippet n= recvfrom(sd,msg,MAX_MSG,0,(struct sockaddr*)&cliAddr,&cliLen); char* ptr=msg; printf("1st value %d ",ntohl(*(int*)ptr)); ptr=ptr+sizeof(int); printf("2nd value %d",ntohl(*(int*)ptr)); ptr=ptr+sizeof(int); printf("3rd value %d",ntohl(*(int*)ptr)); ptr=ptr+sizeof(int); pritnf("final value %d",ntohs(*(unsigned short)ptr)); How to encode the PDU in perl script sothat the above decode statements correctly receives values. can 'pack' api in perl achieves that ????

Replies are listed 'Best First'.
Re: Perl socket programming
by peter (Sexton) on Mar 25, 2008 at 15:46 UTC
Re: Perl socket programming
by zentara (Cardinal) on Mar 25, 2008 at 19:46 UTC