#include #include typedef struct Tcphdr Tcphdr; struct Tcphdr { int tid; int proto; int len; int sa; }; Tcphdr* tcphdr(uchar *buf, int blen) { if( blen != 7 || buf == 0) return 0; Tcphdr th; memset(&th, 0, sizeof(Tcphdr)); th.tid = buf[0] << 8 | buf[1] << 0; th.proto = buf[2] << 8 | buf[3] << 0; th.len = buf[4] << 8 | buf[5] << 0; th.sa = buf[6] << 0; return &th; } void main(int argc, char *argv[]) { Tcphdr *th; uchar buf[512] = {0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x16}; th = tcphdr(buf, 7); print("tid: %d \n", th->tid); print("proto: %d \n", th->proto); print("len: %d \n", th->len); print("sa: %d \n", th->sa); exits(nil); }