Print OutputTCP congestion window
In the kernel function tcp_getsockoptCodeYou can see that this option tcp_info returns almost all parameters, and there are many other parameters to get some other information. For more information about each parameter, see the kernel annotations.
Example
# Include <string>
# Include <string. h>
# Include <cstdlib>
# Include <ctime>
# Include <unistd. h>
# Include <stdio. h>
# Include <sys/types. h>
# Include <sys/socket. h>
# Include <netinet/tcp. h>
# Include <netinet/in. h>
# Include <ARPA/inet. h>
# Include <unistd. h>
# Include <sys/time. h>
# Include <Linux/IP. h>
Void read_cwnd (INT tcp_socket)
{
Struct tcp_info Info;
Int length = sizeof (struct tcp_info );
If (getsockopt (tcp_socket, ipproto_tcp, tcp_info, (void *) & info, (socklen_t *) & length) = 0)
{
Printf ("% u \ n ",
Info. tcpi_snd_cwnd,
Info. tcpi_snd_ssthresh,
Info. tcpi_rcv_ssthresh,
Info. tcpi_rtt,
Info. tcpi_rttvar,
Info. tcpi_unacked,
Info. tcpi_sacked,
Info. tcpi_lost,
Info. tcpi_retrans,
Info. tcpi_fackets,
Info. tcpi_ca_state,
Info. tcpi_reordering
);
}
}
Int main ()
{
Sockaddr_in;
Memset (& in, '\ 0', sizeof (in ));
In. sin_family = af_inet;
In. sin_port = htons (8888 );
In. sin_addr.s_addr = inaddr_any;
Int reuse0 = 1;
Int serv = socket (af_inet, sock_stream, 0 );
Read_cwnd (SERV );
Return 1;
}
Original
Http://www.cnblogs.com/fll/archive/2009/03/20/1418091.html