TCP_INFO信息查询

查看当前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 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值