i am working with libpcap(gcc, linux) and for some reason i want to extract the packet length from the u_char packet[]
, saving it in an integer; say the packet length stored in packet[38] packet[39]
. something like:
#include <stdio.h>
#include <netdb.h>
int main(int argc, char *argv[]) {
u_char packet[2] = {0xaa, 0xfc};
int length = 0xaafc; // how to do that ?
printf("%d\n", length);
}
so far i have tried this :
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
int main(void)
{
u_char packet[2] = {0xaa, 0xfc};
int l = packet[0] | (packet[1]<<8);
printf("%d\n", l);
}
but no success !
so how to accomplish this in c ? also if i should post the whole code here, just name it ...
thanks.