[ale] Binary data in perl

Chris Fowler cfowler at outpostsentinel.com
Mon Apr 21 09:24:09 EDT 2003


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





More information about the Ale mailing list