The TCP and UDP segment format

Putting this here just for reference as repeating Stanford Networking course.

Some of important fields in TCP Segment :

Destination port – tells the TCP layer which application should get the bytes on ether end.

Source port Says where the data should get back, when app starts sending the data it generates unique source port number – to be able to receive the data back. (to differentiate the connection between host A and B)

Sequence number Indicates the position of the byte stream in TCP Data field.

Acknowledgment Sequence Tells the other end which byte we are expecting next, also says that until now we have received all data correctly.

16 Bit Checksum – To detect corrupt data, bit errors on the wire for example.

Header length Tells how long the header is, also shows how many options are present.

Flags : ack, urg, push bit, reset flag, syn, fin 

Window Size – Could be 1 – means stop and wait, could be 0 means connection will be closed, could be 1500 or other value means that much of bytes we can send without the acknowledge.

The unique id of a TCP connection.

In IPv4 Header we have IP Dest. A.; IP Source A., Protocol ID=TCP = 104-bit globally unique ID.

As the first steps host a increments source port for every new connection.

Then TCP picks ISN (initial sequence number) to avoid overlap with previous connection with same ID.


UDP has only 4 header fields unlike TCP which as 10.

Fields :

Source port, Destination PortLength, Checksum(Optional field) if it’s used then it’s calculated with UDP header and data otherwise it’s filled with 0 fields.

In a nutshell UDP is unreliable delivery – no acks, no way to detect missing datagrams, no flow control, packets may show up in any order, TCP has all those function and the issue of TCP is that TCP datagram is much bigger than UDP and carries a lot of features which might be not needed for apps like video streaming or DNS or features like flow control might be already implemented in APP itself. For example right now we are observing more and more intensive usage of protocol QUIC in network.



Big and Little Endian

Big endianmost significant byte stored in smallest address,  read from left to right.

Let’s take a 32-bit value :

0x09080706 :


byte address : x|x+1|x+2|x+3

For example 32-bit value 5 writing as 0x00000005 is a Big endian.

Little endianleast significant byte is stored in smallest address, read from right to left.

32-bit value would be stored in memory in following way :

0x09080706 :


byte address : x|x+1|x+2|x+3

For example little endian value would be 16-bit value 53  in 0x3500

Useful info about this :


Learning how to learn

Would like to share a great course about interesting approaches to understand our mind  how it is working and how to be more effective in learning new things.

Absolutely free course, enjoy it !

I’ve went through it a long time ago but didn’t took any notes, on pastebin found pretty good summarized notes of this course : 


Small how to setup a WiFI device on your FreeBSD machine.

Scanning for wifi networks :
ifconfig wlan0 up scan

Setting up your wifi device :Network-Wireless

This example shows the Atheros ath0 wireless adapter.Add an entry for this network to /etc/wpa_supplicant.conf. If the file does not exist, create it. Replace myssidand mypsk with the SSID and PSK provided by the network administrator.


ssid=”myssid” psk=”mypsk”


Add entries to /etc/rc.conf to configure the network on startup:

ifconfig_wlan0=”WPA SYNCDHCP”

Restart the computer, or restart the network service to connect to the network:
# service netif restart
After 8.0v, it is necessary to create a wlan clone device of the actual wifi card :
# ifconfig wlan0 create wlandev ath0
# ifconfig wlan0 up list scan


Apt-get/Yum through proxy


In case if your access is going through proxy server you need to provide the credentials to APT.

Just create an apt.conf file in /etc/apt/ and add there the following entry :

Acquire::http::Proxy “http://proxyadd:port”;

In case if authentication is needed :

Acquire::http::Proxy “http://username:password@proxyadd:port”;





First post

int main()


printf (”

This is my first blog and first blogging experience, most likely I will abandon and forget it, but nevertheless this needs to be at least tried. I will try to blog about design, troubleshooting, configuration and automation of networks + everything else what I’m trying to learn and master (C, Embedded systems, Python, Security, Computer Architecture)

To make this entry useful would like to share two great podcasts about networking and technology, the idea about blogging came to me after listening one of the series on Packetpushers, thanks guys for providing an outstanding content !

Pretty new blog but with an awesome content and deep technical dive is :

Network Collective

Take your time and check out those links !

“The only true wisdom is in knowing you know nothing.” – Socrates