Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when is the push flag set in tcp segment

i asked this previous question here:

tcp two sides trying to connect simultaneously

i tried the method given in the solution and while sending while using netcat and sniffing packets with ethereal i observed that when i sent a "hello" string from one side to the other it was sent in a segment with the push flag set.

who decides to set the push flag? what are the rules for setting the push or urgent flag in a tcp segment? is it possible to do it using the sockets api?

like image 863
Rohit Banga Avatar asked Feb 15 '10 05:02

Rohit Banga


People also ask

When TCP Push flag is used?

PSH or PUSH flag is an option provided by TCP that allows the sending application to start sending the data even when the buffer is not full (contains data less than MTU). The application needs to set the PSH flag to true for the socket and with that TCP starts pushing the data immediately.

How do you set a push flag in TCP?

The setting of the Push Flag is usually not controlled by the sending application, but by the sending TCP layer. Most modern TCP/IP stacks set the PSH bit at the end of the buffer supplied to send() . The PSH flag is set on the entire outgoing segment, not 'at the end of the buffer'.

What does the PSH flag in TCP segment mean?

The PSH flag in the TCP header informs the receiving host that the data should be pushed up to the receiving application immediately.

What is urgent flag in TCP?

TCP offers the ability to flag certain bytes of data as “urgent.” This feature allows an application to process and forward any data that must be dealt with immediately, without the data having to sit in the send queue for processing.


2 Answers

The PUSH flag is used by the tcp stack to basically say "i'm done for now". It's just indicating the data segment is fully transmitted by the source.

There is no way to indicate or control it in userland (your socket api), as this is just the tcp stack/implementation to do it. As the URGENT flag.

(Source: Richard Stevens - Tcp/ip illustrated vol 1, chapter 20)

like image 91
Patrick Avatar answered Oct 15 '22 07:10

Patrick


You can set the URGENT flag using send() with the MSG_OOB flag set. As this implies, the data sent will be Out-Of-Band, meaning it will not normally be received by the calling side simply calling read(). The receiving side will get some indication of OOB data like the signal SIGURG, or the socket will become exceptional and can be checked as such using select().

Most of the time you don't want to set the URGENT flag.

like image 6
Eric Warmenhoven Avatar answered Oct 15 '22 09:10

Eric Warmenhoven