[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Binary data in perl
- Subject: [ale] Binary data in perl
- From: cfowler at outpostsentinel.com (Chris Fowler)
- Date: 21 Apr 2003 09:24:09 -0400
Got a question for you guys. Below is a snippet of C code that creates
a binary packet of data. I am receiving this data in Java but would
like to in perl. Can someone tell me how to parse binary data such as
this into readable ascii data?
// Clean out the packet
bzero(&packet, 2048);
et = (int *)&packet;
n += sizeof(int);
ident = (int *)&packet[n];
n += sizeof(int);
pid = (int *)&packet[n];
n += sizeof(int);
tm = (int *)&packet[n];
n += sizeof(int);
ms = (int *)&packet[n];
n += sizeof(int);
msg = (char *)&packet[n];
*et = htonl(eventType);
*ident = htonl(m->identity);
*pid = htonl(m->pid);
*tm = htonl(m->tm);
*ms = htonl(m->msgSize);
memcpy(msg, m->message, m->msgSize);
n += m->msgSize;
ss = (int *)&packet[n];
n += sizeof(int);
*ss = htonl(m->subjSize);
subj = (char *)&packet[n];
memcpy(subj, m->subject, m->subjSize);
n += m->subjSize;
if(len) *len = n;
return packet;
Thanks,
Chris
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale