NAT檢測的類

2021-09-30 06:28:04 字數 2092 閱讀 7889

#include "stdafx.h"   

#include

#include

#include

#include "winsock2.h"

#include "./include/packet.h"

#pragma comment(lib,"./lib/wininet.lib") 

#pragma comment(lib,"wsock32.lib") 

#include "ws2tcpip.h" 

#include "string.h" 

#define n_supernode 5

#define n_natcheckrequestqueue 20

#define port_server_natcheck 8888

#define port_server_natcheck_1 8889

#define port_client_natcheck 7777

#define port_server_client_info 4444

#define n_checktime 5 //最多檢測次數

socket sclient,sserver;//客戶端和服務端的socket號

struct sockaddr_in sn1_addr,sn2_addr,sn_addr,client_addr;

struct sockaddr_in client_addr_deal;

struct in_addr in_addr_tmp,in_addr_tmp1;

file *fp; //客戶端讀取hostcache.txt檔案指標

int i=0,j=0;

unsigned long int snip[n_supernode];//讀取的sn的ip位址列表

char ch;

char ip_return[15];

/* 本client的網路型別:

* 0 = public net

* 1 = full cone nat

* 2 = symmetric nat

* 3 = restricted cone nat

* 4 = port restricted cone nat

*/unsigned long int myid=0,friendid=26;//本client和friend的使用者id

char mynettype=-1,friendnettype=-1;

unsigned long int mypubip,friendpubip,mypriip,friendpriip;

unsigned short int mypubport,friendpubport,mypriport,friendpriport;

//natcheck請求包結構

struct natcheckpacketnatcheckpacket;

typedef struct natcheckpacket ncp;

char buff[sizeof(natcheckpacket)];//發包用的緩衝區

//natcheck請求資料結構

struct natcheckrequestnatcheckrequest;

typedef struct natcheckrequest ncr;

struct netinforesponsepacketnetinforesponsepacket;

typedef struct netinforesponsepacket nirp;

//natcheck請求資料迴圈佇列

ncr natcheckrequestqueue[n_natcheckrequestqueue];

ncr * h_natcheckrequestqueue,* t_natcheckrequestqueue;

/** 獲得本地主機ip位址

*/char * getownip()

}sleep(300);

}  } 

//  

//   終止   windows   sockets   api  

wsacleanup(); 

return 0;

}

NAT型別 及其 檢測 詳解

p2p的nat研究 第一部分 nat介紹 第二部分 nat型別檢測 第一部分 nat介紹 各種不同型別的nat according to rfc full cone nat 內網主機建立乙個udp socket localip localport 第一次使用這個socket給外部主機傳送資料時nat...

路由器NAT 型別檢測實現

完全圓錐型nat full cone nat 受限圓錐型nat address restricted cone nat 埠受限圓錐型nat port restricted cone nat 對稱型nat symmetric nat 又稱為雙向nat,大型公司網路中經常採用的 所謂圓錐型nat是指內網...

NAT的四種型別及型別檢測

考慮到udp的無狀態特性,目前針對其的nat實現大致可分為full cone restricted cone port restricted cone和symmetric nat四種。值得指出的是,對於tcp協議而言,一般來說,目前nat中針對tcp的實現基本上是一致的,其間並不存在太大差異,這是因...