16.01.2015 Views

Hacking

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

u_int16_t frag_off;<br />

u_int8_t ttl;<br />

u_int8_t protocol;<br />

u_int16_t check;<br />

u_int32_t saddr;<br />

u_int32_t daddr;<br />

/*The options start here. */<br />

};<br />

From RFC 791<br />

0 1 2 3<br />

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

|Version| IHL |Type of Service| Total Length |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Identification |Flags| Fragment Offset |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Time to Live | Protocol | Header Checksum |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Source Address |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Destination Address |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Options | Padding |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

Example Internet Datagram Header<br />

Each element in the structure corresponds to the fields shown in the<br />

RFC header diagram. Since the first two fields, Version and IHL (Internet<br />

Header Length) are only four bits in size and there aren’t any 4-bit variable<br />

types in C, the Linux header definition splits the byte differently depending<br />

on the byte order of the host. These fields are in the network byte order, so,<br />

if the host is little-endian, the IHL should come before Version since the byte<br />

order is reversed. For our purposes, we won’t really be using either of these<br />

fields, so we don’t even need to split up the byte.<br />

Added to hacking-network.h<br />

struct ip_hdr {<br />

unsigned char ip_version_and_header_length; // Version and header length<br />

unsigned char ip_tos;<br />

// Type of service<br />

unsigned short ip_len; // Total length<br />

unsigned short ip_id;<br />

// Identification number<br />

unsigned short ip_frag_offset; // Fragment offset and flags<br />

unsigned char ip_ttl;<br />

// Time to live<br />

unsigned char ip_type; // Protocol type<br />

unsigned short ip_checksum; // Checksum<br />

unsigned int ip_src_addr; // Source IP address<br />

unsigned int ip_dest_addr; // Destination IP address<br />

};<br />

232 0x400

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!