Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to TCP statistics/information per socket possible? (C/C++)

I require some informations like the amount of resend packages/packet-loss occurred for a specific TCP-Socket I created. Does somebody know a way how to access or request such informations directly from my C/C++ program? Maybe something Linux specific?

Or do I need (as a workaround) to capture and analyze my own traffic?

Thanks in advance!

like image 507
NoName Avatar asked Nov 17 '10 10:11

NoName


People also ask

What is a socket C?

A socket is a generalized interprocess communication channel. Like a pipe, a socket is represented as a file descriptor. Unlike pipes sockets support communication between unrelated processes, and even between processes running on different machines that communicate over a network.

What are TCP sockets?

A socket programming interface provides the routines required for interprocess communication between applications, either on the local system or spread in a distributed, TCP/IP based network environment.

How does send () work in C?

The send() function shall initiate transmission of a message from the specified socket to its peer. The send() function shall send a message only when the socket is connected (including when the peer of a connectionless socket has been set via connect()). Specifies the socket file descriptor.


1 Answers

By using getsockopt() to get or setsockopt() to set TCP socket options, you can use TCP_INFO option on linux machines in order to get information about a socket. This option should be avoided if you want the code to be portable.

What you will get back is a struct tcp_info from the kernel that contains information such as retransmissions, lost packets, states etc.

like image 148
Milan Avatar answered Sep 25 '22 00:09

Milan