En el ejemplo de la pagina, usa esto:
#include <netinet/ip.h>
#include <netinet/tcp.h>
...
...
/* Cabecera IP */
struct iphdr *ip = (struct iphdr *)buffer;
/* Cabecera TCP */
struct tcphdr *tcp = (struct tcphdr *)(buffer + sizeof(struct iphdr));
...
...
Ahora, usando Google, llegamos a un .h que contiene una de las structs:
http://freebsd.active-venture.com/FreeBSD-srctree/newsrc/netinet/tcp.h.htmlAhi está definida la estructura tcphdr en C:
struct tcphdr {
u_short th_sport; /* source port */
u_short th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
#if BYTE_ORDER == LITTLE_ENDIAN
u_int th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if BYTE_ORDER == BIG_ENDIAN
u_int th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
u_char th_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
#define TH_ECE 0x40
#define TH_CWR 0x80
#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
u_short th_win; /* window */
u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */
};
Inicializa todo con ceros y listo (ojo los tamaños).
Saludos!
PD: Otra fuente:
http://ranger.uta.edu/~odell/TCP.HTen en cuenta que justo despues de la estructura IP viene la TCP (para eso usa el tamaño de la estructura ip con sizeof).