我們親自來實現獲取所有的tcp與udp的網路鏈結。
[cpp]
[cpp]
定義協議格式
定義協議中使用的巨集
#ifndef __protoinfo_h__
#define __protoinfo_h__
#define ethertype_ip 0x0800
#define ethertype_arp 0x0806
typedef struct _etheader // 14位元組的以太頭
etheader, *petheader;
#define arphrd_ether 1
// arp協議opcodes
#define arpop_request 1 // arp 請求
#define arpop_reply 2 // arp 響應
typedef struct _arpheader // 28位元組的arp頭
arpheader, *parpheader;
// 協議
#define proto_icmp 1
#define proto_igmp 2
#define proto_tcp 6
#define proto_udp 17
typedef struct _ipheader // 20位元組的ip頭
ipheader, *pipheader;
// 定義tcp標誌
#define tcp_fin 0x01
#define tcp_syn 0x02
#define tcp_rst 0x04
#define tcp_psh 0x08
#define tcp_ack 0x10
#define tcp_urg 0x20
#define tcp_ace 0x40
#define tcp_cwr 0x80
typedef struct _tcpheader // 20位元組的tcp頭
tcpheader, *ptcpheader;
typedef struct _udpheader
udpheader, *pudpheader;
#endif // __protoinfo_h__
#include
#include
#include
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
pmib_tcptable mygettcptable(bool border);
pmib_udptable mygetudptable(bool border);
void myfreetcptable(pmib_tcptable ptcptable);
void myfreeudptable(pmib_udptable pudptable);
int main()
// 本地位址
inadlocal.s_addr = ptcptable->table[i].dwlocaladdr;
// 遠端埠
if (strcmp(strstate, "listen") != 0)
else
dwremoteport = 0;
// 遠端ip位址
inadremote.s_addr = ptcptable->table[i].dwremoteaddr;
strcpy(szlocalip, inet_ntoa(inadlocal));
strcpy(szremip, inet_ntoa(inadremote));
printf("%20s %10u %20s %10u %s\n",
szlocalip, ntohs((unsigned short)(0x0000ffff & ptcptable->table[i].dwlocalport)),
szremip, ntohs((unsigned short)(0x0000ffff & dwremoteport)),
strstate);
} myfreetcptable(ptcptable);
} printf(" \n\n");
// 列印udp監聽表資訊
pmib_udptable pudptable = mygetudptable(true);
if(pudptable != null)
myfreeudptable(pudptable);
} return 0; }
pmib_tcptable mygettcptable(bool border)
return null; }
void myfreetcptable(pmib_tcptable ptcptable)
pmib_udptable mygetudptable(bool border)
return null; }
void myfreeudptable(pmib_udptable pudptable)
獲取Redis所有的鍵值對
redis命令級別實現 scan cursor match pattern count count 1spring data redis實現 override public list getallredisval1 zset型別的鍵值獲取 if redistemplate.type key code...
獲取所有的預設值列表
獲取所有的預設值列表 select object name c.id as 表名 c.name as 欄位名 t.name as 資料型別 c.prec as 長度 p.value as 字段說明 m.text as 預設值 from syscolumns c inner join systypes...
獲取本機所有的ADSL連線名稱
真鬱悶呀,就這點 費半天勁,dotras怎麼會沒有這個功能呢?dotras的就只有乙個獲取dotras.rasconnection.getactiveconnections這應該是活動連線 呼叫方法 dim stradsl as string ras.listadsl if stradsl then...