Can anyone tell me why these errors are coming

i wrote the following code in visual studio 2010 and i am getting lot of errors
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
#include<Windows.h>
#include<WS2tcpip.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include <process.h>
#include<WinSock.h>
#include<WinSock2.h>
#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);
    }
}



c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(353) : see previous definition of 'IP_DONTFRAGMENT'
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2ipdef.h(193): error C2079: '_SOCKADDR_INET::Ipv4' uses undefined struct 'sockaddr_in'
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2ipdef.h(700): error C2011: 'ip_mreq' : 'struct' type redefinition
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(363) : see declaration of 'ip_mreq'
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(664): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(671): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(709): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(716): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(760): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(767): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(807): error C3861: 'WSASetLastError': identifier not found
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(814): error C3861: 'WSASetLastError': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You're trying to use Winsock version 1 and 2 at the same time.

To fix it, remove these lines:
1
2
#include<WinSock.h>
#pragma comment (lib, "Mswsock.lib") 

Move Windows.h after winsock2.h

You need to initialise the sockets library before you use it with:
1
2
WSADATA wsadata;
WSAStartup(MAKEWORD(2, 2), &wsadata);

This has no meaning on Windows:
 
"/proc/%d/net/tcp"

I haven't confirmed it, but that should do it.

EDIT: This is really bad as fp is uninitialised.
1
2
3
    FILE *fp;

    if (fp != 0)
Last edited on
Try this:


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);
    }
}
sir please help me on my program that contain the above code,i am running it on eclipse in windows

Here is the link
http://www.cplusplus.com/forum/general/76840/
Topic archived. No new replies allowed.