1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
//#include<Windows.h>
#include<WS2tcpip.h> //include this header first
#include<Windows.h> //then include this one.
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include <process.h>
//#include<WinSock.h> //Don't need to specifically inclue this one??
//#include<WinSock2.h> //Don't need to specifically inclue this one??
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
#define BUFFERSIZE 256
int main()
{
char buf[BUFFERSIZE*2];
struct in_addr laddr, raddr;
struct in6_addr laddr6, raddr6;
struct in6_addr swapladdr6, swapraddr6;
unsigned lport, rport, state, uid;//, txq, rxq, num;
int n;
FILE *fp;
sprintf(buf, "/proc/%d/net/tcp", getpid());
fp = fopen(buf, "r");
if(fp != 0)
{
fgets(buf, BUFFERSIZE*2, fp);
while(fgets(buf, BUFFERSIZE*2, fp))
{
n = sscanf(buf, " %*d: %x:%x %x:%x %x %*x:%*x %*x:%*x %*x %d",
&laddr.s_addr, &lport, &raddr.s_addr ,&rport,
&state, &uid);
/*if(n == 6)
net_list_add("TCP", &laddr, lport, &raddr, rport, state, uid, 0);*/
}
fclose(fp);
}
}
|