參考了 ss的源码

以及 netlink相关资料:http://blog.csdn.net/scdxmoe/article/details/27711205


实现结果为:

gcc netlink_dig_530_7.c -o netlink_dig_530_7
./netlink_dig_530_7

state      family     l.addr     l.port       r.addr     r.rport   
LISTEN     AF_INET   localhost      53         0.0.0.0        0         
LISTEN     AF_INET   (null)         21         0.0.0.0        0         
LISTEN     AF_INET   (null)         22         0.0.0.0        0         
LISTEN     AF_INET   (null)         22         0.0.0.0        0         
LISTEN     AF_INET   localhost      631        0.0.0.0        0         
LISTEN     AF_INET   (null)         12865      0.0.0.0        0         
ESTAB      AF_INET   ubuntu.local   59208      91.189.89.134  80        
ESTAB      AF_INET   ubuntu.local   22         192.168.0.248  9689      
ESTAB      AF_INET   ubuntu.local   22         192.168.0.248  9295      
ESTAB      AF_INET   ubuntu.local   35531      91.189.94.25   80        
ESTAB      AF_INET   ubuntu.local   22         192.168.0.248  9691  

本文的实验 并没有实现怎么样获取TCP的窗体值cwnd和RTT值,在ss源代码中我看到了他利用了/proc

文件来实现获取窗体和RTT值。怎么样用netlink套接字实现呢?还请教各位指点

源码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <asm/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/inet_diag.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include<arpa/inet.h>
struct sk_req {
    struct nlmsghdr nlh;
    struct inet_diag_req r;
};


typedef struct{
 __u8 family;
 __u8 bytelen;
 __s16 bitlen;
 __u32 flags;
 __u32 data[8];
} inet_prefix;

/*struct namerec
{
        struct namerec *next;
        const char *name;
        inet_prefix addr;
};*/

struct tcpstat
{
        inet_prefix

相关文章:

  • 2022-12-23
  • 2021-10-05
  • 2021-05-09
  • 2021-11-20
  • 2021-12-11
  • 2021-10-01
  • 2021-08-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2021-04-26
  • 2021-10-01
  • 2021-11-01
相关资源
相似解决方案