zoukankan      html  css  js  c++  java
  • 打印输出tcp拥塞窗口

    打印输出tcp拥塞窗口

    在内核的函数tcp_getsockopt的代码中,可以看到这个选项TCP_INFO,返回了几乎所有的参数,同时还有其他的许多参数可以得到一些其他的信息。具体每个参数的含义可以参考内核中的注释。

    示例

    #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 %u %u %u %u %u %u %u %u %u %u %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 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;
    }

    原文

    http://www.cnblogs.com/fll/archive/2009/03/20/1418091.html

  • 相关阅读:
    HTML学习笔记之二(回到顶部 与 回究竟部)
    初次使用cocoapods注意事项
    struts2在web.xml中配置详情
    hdu 3631 Shortest Path(Floyd)
    bullet HashMap 内存紧密的哈希表
    论文摘抄
    oracle中从指定日期中获取月份或者部分数据
    漫谈机器学习经典算法—特征提取与特征选择
    为什么NULL能多次free
    栈的效率为什么比堆高?
  • 原文地址:https://www.cnblogs.com/mydomain/p/3027664.html
Copyright © 2011-2022 走看看