Ethereal-dev: [Ethereal-dev] extracting http

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: F Lace <flace9@xxxxxxxxx>
Date: Thu, 19 May 2005 13:54:14 +0530
Hi
I am trying to extract the http content following the example of
udpdump.c available in WpdPack_3_01_a. I tried the following, and
pkt_data doesnt seem to contain anything. Any pointers in the right
direction will be helpful. Thanks.

// 20 bytes TCP Header
typedef struct tcp_header {
 u_short sport; // Source port
 u_short dport; // Destination port
 u_int seqnum; // Sequence Number
 u_int acknum; // Acknowledgement number
 u_char hlen; // Header length
 u_char flags; // packet flags
 u_short win; // Window size
 u_short crc; // Header Checksum
 u_short urgptr; // Urgent pointer...still don't know what this is...
}tcp_header;


    /* retireve the position of the ip header */
    ih = (ip_header *) (pkt_data +
        14); //length of ethernet header

    /* retireve the position of the tcp header */
    ip_len = (ih->ver_ihl & 0xf) * 4;
    th = (tcp_header *) ((u_char*)ih + ip_len);

    /* convert from network byte order to host byte order */
    sport = ntohs( th->sport );
    dport = ntohs( th->dport );

    http_data = (char *) (th + (int)th->hlen + 8*2*5);
    ZeroMemory (httpstr, sizeof(httpstr));
    snprintf (httpstr, sizeof(httpstr)-1, "src: %d, dst: %d, th->hlen:
%d\n, %s\n", sport, dport, (int)th->hlen, http_data);
    httpstr[255] = 0;
    fprintf  (http_fp, "%s\n", httpstr);