chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 1 Vote(s) - 5 Average


IP Header Basics filter_list
Author
Message
IP Header Basics #1
After writing the TCP header basics thread, I realized that parts of it required the IP header you guys might not already know about, so here it is.

Code:
struct IPHeader
{
     uint8_t ver_len; //both the version and the length
     uint8_t DSCP_ECN; //6-bit DSCP (ToS), 2 bit ECN (RFC.3168)
     uint16_t ident;
     uint16_t total_length;
     uint16_t flag_offset; //3-bit flags, 13-bit fragment offset
     uint8_t ttl;
     uint8_t protocol;
     uint16_t checksum;
     uint32_t source_addr;
     uint32_t dest_addr;
};
Following are the ability to have option fields, I won't go into them.

ver_len:
4 bit version (usually 0b0100)
4 bit header length:
Spoiler:
The header length is specified in 32-bit chunks, since the length field can have a maximum value of 15, we use 32-bit chunks, allowing a maximum header length of 480 bytes.

DSCP_ECN
DSCP added in RFC.2474 that replaces ToS (type-of-service). I don't know very much about DSCP, but you can google it (or read the RFC)
ECN is (not something I really care to talk about, assume these two bits are 0b00, they likely always are anyways).

total_size
the entire size of the packet (not just the fragment)

ident
Ident is 3 bits. The first of which always being 0, and only 1 of the others set.
bit 1: Don't fragment
bit 2: More fragments
makes sense.

fragment_offset
This is where math is involved that I won't play out (just trying to be basic here), it is just the packet's location in relative to the original datagram (all of the shit put together)

TTL
time to live (you here this a lot) it is NOT pronounced time to lieve. Grr that pissed me off in college... Measured in seconds until the packet expires.

Protocol
the type of protocol we are using. There is a list here

Checksum:
A sum of the packet header. For calculation these bits are 0x0000.

Source address:
ip address of the sender.

Destination address:
dest addr (ip)

Any questions? Shouldn't be much, this was intended to be VERY surface level just to get a concept. If anybody wants to elaborate this in another thread that would be really cool.

[+] 1 user Likes phyrrus9's post
Reply

RE: IP Header Basics #2
Are these defined for you in C++ when using either linuxs or windows socket library. Also can you give examples of when we might use these and for what purposes. Loving the tuts you got on your site. Thanks bud
“Lord, protect me from my friends; I can take care of my enemies.”  - Volitaire

Reply

RE: IP Header Basics #3
(01-20-2019, 07:35 AM)SickPsycko Wrote: Are these defined for you in C++ when using either linuxs or windows socket library. Also can you give examples of when we might use these and for what purposes. Loving the tuts you got on your site. Thanks bud

No, these are not defined for you, at least not in this form. What I've written here will work just fine if you want to create your own TCP stack, but odds are you'd rather use the POSI.X or WinSock stacks. If you google "C socket programming", you will probably find loads of materials that will be more helpful to you if you're writing software. Threads like this are simply to explain how those libraries everybody depends on work on the backend.

[+] 1 user Likes phyrrus9's post
Reply






Users browsing this thread: 1 Guest(s)