查看当前TCP信息
更多字段可以查询/uer/include/netinet/tcp.h文件
#include<stdio.h>
2 #include<sys/socket.h>3 #include<string.h>
4 #include<unistd.h>
5 #include<stdlib.h>
6 #include<sys/types.h>
7 #include<netinet/in.h>
8 #include<sys/time.h>
9 #include<arpa/inet.h>
10 #include<netinet/tcp.h>
11 void read_cwnd(int fd)
12 {
13 struct tcp_info info;
14 int length=sizeof(struct tcp_info);
15 if(getsockopt(fd,IPPROTO_TCP,TCP_INFO,(void*)&info,(socklen_t*)&length)==0)
16 {
17 /* printf("%u,%u,%u\n",
18 info.tcpi_snd_cwnd,
19 info.tcpi_snd_ssthresh,
20 info.tcpi_rcv_ssthresh
21 );
22 */
23 printf("tcp_snd_cwnd:%u\t\t\n",info.tcpi_snd_cwnd);
24 printf("tcp_snd_ssthresh:%u\t\t\n",info.tcpi_snd_ssthresh);
25 printf("tcp_rcv_ssthresh_cwnd:%u\t\t\n",info.tcpi_rcv_ssthresh);
26 }
27 }
28
29
30 int main(int argc,char **argv)
31 {
32 struct sockaddr_in addr;
33 memset(&addr,0,sizeof(addr));
34 addr.sin_family=AF_INET;
35 addr.sin_port=htons(8888);
36 addr.sin_addr.s_addr=INADDR_ANY;
37 int ret=1;
38 int fd=socket(AF_INET,SOCK_STREAM,0);
39 read_cwnd(fd);
40 return 0;
41
42 }