Solved

Socket Programming - Port Scanner. I Get Connection Timed Out, Why?

Posted on 2008-10-25
32
1,474 Views
Last Modified: 2012-05-05
When i put the target IP as 127.0.1.1, the program is working fine, can catch blocked & open ports. However, when i try to scan remotely, i get connection timed out! Can you tell me why?

Look at between where i put astriks - at the bottom.
#include<iostream>
#include<string>
#include<sstream>
#include<sys/types.h>
#include<sys/socket.h>
#include<netdb.h>
#include<arpa/inet.h>
#include<errno.h>
using namespace std;
 
 
struct addrinfo hints;      	//fill your host info - hints is input
struct addrinfo *results;	    //gets your host info - results is output
char *remoteIP = new char[40];  //holds inserted remote IP
string tempPort;                //holds ports temporarly
int startingPort;               //stores the starting range of port number
int status;                     //receives the status of your pc address
int currentPort;                //holds current port
 
//program description
void progDesc()
{
     cout<<"This is a simple port scanner, scan range of\n";
     cout<<"ports on your local machine...\n"<<endl;
 
}
 
 
//getaddrinfe locates your machine, more specific
//details of your host address is returned to results. 
void getAddrIn()
{
	status = getaddrinfo(remoteIP, NULL , &hints, &results);
 
	if(status != 0)
	{
		fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
		exit(1);
	}
}
 
//get host name of the remote IP
void grabHostName()
{
	//carries your target's host name
	char hostName[100];
	struct addrinfo *p;
	
	cout<<"Host name for \""<<remoteIP<<"\" is:";
 
	//print all your local IP Addresses
	for(p = results; p != NULL; p = p->ai_next)
	{
		void *addr;
		string ipVer;
		if(p->ai_family == AF_INET)
		{
			struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
			addr = &(ipv4->sin_addr);
			ipVer = "IPv4";
 
		}else{
			struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
			addr = &(ipv6->sin6_addr);
			ipVer = "IPv6";
		}
 
		//inet_ntop(p->ai_family, addr, ipString, sizeof ipString);
		cout<<""<<ipVer<<": ";
		//printf("%s\n", ipString);
		cout<<endl;
	}	
}
 
 
//Run the program
int main()
{
	int endingPort;                 //stores the ending rage of port number
 
	system("clear");
 
	//tell user what program does
	progDesc();
	
	//set size of hints to zero
	memset(&hints, 0, sizeof hints);
 
	//fill some of your host address info
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
 
	//ask for remote IP
	cout<<"Please enter your target IP: ";
	cin>>remoteIP;
 
	//call get addrinfo()
	getAddrIn();
 
	//ask port range from user
	cout<<"Enter Starting Port: ";
	cin>>startingPort;
 
	cout<<"Enter Ending Port: ";
	cin>>endingPort;
 
	cout<<endl;
 
	cout<<"Start Scanning: "<<endl;
 
	//check the status
	while(startingPort <= endingPort)
	{
		//call getaddrinfo()
		getAddrIn();
 
		//create a socket.
		int socketfd;
		socketfd = socket(results->ai_family, results->ai_socktype, results->ai_protocol);
 
		if(socketfd == -1 )
		{
			cout<<"Error: failed to create a socket.\n";
			return 2;
		}
 
		//********************************************************************
		//add a specific port, you want to connect to, for the remote host
		struct sockaddr_in *specifyPort = (struct sockaddr_in *)results->ai_addr;
		specifyPort->sin_port = htons(startingPort);
 
		//make connection to host IP/Port specified
		int connectStatus;
		connectStatus = connect(socketfd, results->ai_addr, results->ai_addrlen);
	
		if(connectStatus == -1 )
		{		
			if(errno == ECONNREFUSED)
				cout<<"Port "<<startingPort<<" is Closed or Blocked.\n";
			else if(errno == ETIMEDOUT)
				cout<<"The attempt to connect TIMED OUT before a connection was made."<<endl;
			else
				cout<<"Error: "<<strerror(errno)<<endl;
		}else{
			cout<<"Port "<<startingPort<<" is OPEN.\n";
		}
		//**********************************************************************
 
		close(socketfd);
	
		//move to the next port in the specified range
		startingPort++;
 
	}
 
	//deallocate memory
	delete[] remoteIP;
 
	//free linkedlist of struct addrinfo *results 
	freeaddrinfo(results);
 
	return 0;
}

Open in new window

0
Comment
Question by:F-J-K
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 13
32 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22802806
That means the connection request didn't make it to the target machine. It might have been blocked by a firewall between your machine and the target machine.

You are testing this on one of your own machines, aren't you ?

What will this port scanner be used for ?
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22802858
Of course, on my machine. I'm doing this port scanner to test my capabilities in writing network applications. To practice on what i have learned so far in socket programming. My main goal to move to client-server application to create real-life applications. Port scanner is a good way to get used to network programming asin here  i'm dealing on one side only. Once i get comfortable with it, i will move to client-server applications, such as chat apps, which deals in two sides.

So is the algorithm is right? Is the logic between the astriks right?

If yes, i will just move on. If not, i will have to know why, so i do not make such mistakes later on.

Thanks for asking!
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22802863
I got an account in UNIX. I test it against my home PC from the terminal
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22802892
>> I test it against my home PC from the terminal

Meaning that the connection passes over the internet, and through a few routers/firewalls along the way. Does the network where you have the UNIX account allow outgoing connections ? Do you have a router at home ? How about your ISP ? Does it block incoming connections ?


>> Is the logic between the astriks right?

It looks ok on first sight (I haven't checked it in detail). Try testing it on a local machine (on the same network) - after getting the permission to do so of course.
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22802989
>>Meaning that the connection passes over the internet, and through a few routers/firewalls along the way. Does the network where you have the UNIX account allow outgoing connections ? Do you have a router at home ? How about your ISP ? Does it block incoming connections ?

I do have router at home. I think this got to do with Firewalls. Anyhow, its not a big deal. All i care about is the logic.

>>It looks ok on first sight (I haven't checked it in detail). Try testing it on a local machine (on the same network) - after getting the permission to do so of course.

hmmm i got several PC's at home under a wireless router, it wouldbe great to test internally. I must port the code to Windows which would take time. I will port it later. Hopefully its going to work.

My code so far works under Unix & Linux
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22803017
>> I must port the code to Windows which would take time.

It's not as hard as you might think. The main difference is that Windows requires some extra initialization. Other than that, your code won't have to be changed much. More info here :

        http://www.beej.us/guide/bgnet/output/html/singlepage/bgnet.html#windows
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22803193
There is no proper documentation on how link to winsock.lib! Any idea?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22803214
>> There is no proper documentation on how link to winsock.lib! Any idea?

What compiler are you using ?
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22803309
VC++
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22803359
Then you should add the library in the linker settings.
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22803504
Useless, i can not find any winsock.lib! :-/
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22803611
Anyway, i will see what i can do. Thanks anyway
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22803752
>> Useless, i can not find any winsock.lib! :-/

It should come installed with your compiler. It's probably named wsock32.lib or ws2_32.lib
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22803850
I open an empty project - CLR Console Application, i dumped my winsock code in it. I went to Projects tab -> fileName Properties -> Configuration Properties -> Linker -> I DID EVERY THING IN HERE - I saw lists that has WindowsSDKDir, etc, i did not find winsock.lib or anything related.

I did all i can, Nothing helped. Kind of wasted my time. If anybody here can guide me in step by step, i will appreciate it so much...

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22803913
Well, I haven't got VC++, so I can't give you a step-by-step process to follow, just that you need to find the winsock library, and link to it ;) (you can search your hard disk for the file - try the names I mentioned too).
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805333
I have them under

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\WinSock.h
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\WinSock2.h

I went to Projects tab -> fileName Properties -> Configuration Properties -> Linker -> Additional Dependencies -> I should do something in here! I kept looking for winsock.lib, none in there, so i put the whole link C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\WinSock.h in the field, the program still don't compile. If you know it, give  hint.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22805335
winsock.h is the include file, not the library. You need to link to the library. Did you look for it ? Did you find it ? It should be there (especially since you found the winsock. header file)
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805367
Oh i found it under lib...

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\WSock32

Now, i will go to Projects tab -> fileName Properties -> Configuration Properties -> Linker -> Additional Dependencies -> and put the C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\WSock32 in the filed

Hopefully it will work
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805390
I did it, i get such errors:

------ Rebuild All started: Project: vvv, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'vvv', configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
vvv.cpp
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(3) : warning C4627: '#include <sstream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(4) : warning C4627: '#include <winsock2.h>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(178) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Build log was saved at "file://c:\Documents and Settings\Fahmi\My Documents\Visual Studio 2008\Projects\vvv\vvv\Debug\BuildLog.htm"
vvv - 1 error(s), 4 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Open in new window

0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805394
I added #include "stdafx.h"

I get this errors!
------ Rebuild All started: Project: vvv, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'vvv', configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
vvv.cpp
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : error C2079: 'hints' uses undefined struct 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(20) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(21) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(30) : error C3861: 'getaddrinfo': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(34) : error C3861: 'gai_strerror': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(46) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2227: left of '->ai_next' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2027: use of undefined type 'grabHostName::sockaddr_in6'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : see declaration of 'grabHostName::sockaddr_in6'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2227: left of '->sin6_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(66) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(68) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(68) : error C2563: mismatch in formal parameter list
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(68) : error C2568: '<<' : unable to resolve function overload
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(103) : error C2228: left of '.ai_family' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(104) : error C2228: left of '.ai_socktype' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(107) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(108) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(114) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(115) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(117) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(118) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(120) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(120) : error C2563: mismatch in formal parameter list
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(120) : error C2568: '<<' : unable to resolve function overload
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(122) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_socktype' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_protocol' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(136) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addrlen' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(151) : error C2065: 'ECONNREFUSED' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(152) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(153) : error C2065: 'ETIMEDOUT' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(154) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(156) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(158) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(173) : error C3861: 'freeaddrinfo': identifier not found
Build log was saved at "file://c:\Documents and Settings\Fahmi\My Documents\Visual Studio 2008\Projects\vvv\vvv\Debug\BuildLog.htm"
vvv - 52 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22805395
>> fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

... Pretty straightforward, no ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22805397
>> I get this errors!

Take the warnings/errors one at a time ... Start with the first.
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805399
I changed the location of #include"stdafx.h", i get this
------ Build started: Project: vvv, Configuration: Debug Win32 ------
Compiling...
vvv.cpp
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(3) : warning C4627: '#include <sstream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(4) : warning C4627: '#include <winsock2.h>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(6) : error C2871: 'std' : a namespace with this name does not exist
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : error C2079: 'hints' uses undefined struct 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(12) : error C2146: syntax error : missing ';' before identifier 'tempPort'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(20) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(21) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(21) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(30) : error C3861: 'getaddrinfo': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(34) : error C3861: 'gai_strerror': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(35) : error C3861: 'exit': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(46) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2227: left of '->ai_next' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(52) : error C2146: syntax error : missing ';' before identifier 'ipVer'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(52) : error C2065: 'ipVer' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2065: 'AF_INET' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(56) : error C2027: use of undefined type 'grabHostName::sockaddr_in'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : see declaration of 'grabHostName::sockaddr_in'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(56) : error C2227: left of '->sin_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(57) : error C2065: 'ipVer' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2027: use of undefined type 'grabHostName::sockaddr_in6'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : see declaration of 'grabHostName::sockaddr_in6'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2227: left of '->sin6_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(62) : error C2065: 'ipVer' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(66) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(66) : error C2065: 'ipVer' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(68) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(68) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(78) : error C2065: 'WORD' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(78) : error C2146: syntax error : missing ';' before identifier 'wVersionRequested'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(78) : error C2065: 'wVersionRequested' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(79) : error C2065: 'WSADATA' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(79) : error C2146: syntax error : missing ';' before identifier 'wsaData'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(79) : error C2065: 'wsaData' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(83) : error C2065: 'wVersionRequested' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(83) : error C3861: 'MAKEWORD': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(85) : error C2065: 'wVersionRequested' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(85) : error C2065: 'wsaData' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(85) : error C3861: 'WSAStartup': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(94) : error C3861: 'system': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(100) : error C3861: 'memset': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(103) : error C2228: left of '.ai_family' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(103) : error C2065: 'AF_UNSPEC' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(104) : error C2228: left of '.ai_socktype' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(104) : error C2065: 'SOCK_STREAM' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(107) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(108) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(114) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(115) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(117) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(118) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(120) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(120) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(122) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(122) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_socktype' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_protocol' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C3861: 'socket': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(136) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(143) : error C2027: use of undefined type 'main::sockaddr_in'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : see declaration of 'main::sockaddr_in'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(143) : error C2227: left of '->sin_port' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(143) : error C3861: 'htons': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addrlen' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C3861: 'connect': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(151) : error C2065: 'errno' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(151) : error C2065: 'ECONNREFUSED' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(152) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(153) : error C2065: 'errno' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(153) : error C2065: 'ETIMEDOUT' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(154) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(154) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(156) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(156) : error C2065: 'errno' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(156) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(156) : error C3861: 'strerror': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(158) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(162) : error C3861: 'closesocket': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(173) : error C3861: 'freeaddrinfo': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(175) : error C3861: 'WSACleanup': identifier not found
Build log was saved at "file://c:\Documents and Settings\Fahmi\My Documents\Visual Studio 2008\Projects\vvv\vvv\Debug\BuildLog.htm"
vvv - 93 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Open in new window

0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805406
Such errors does not make sense

c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(104) : error C2065: 'SOCK_STREAM' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(107) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(108) : error C2065: 'cin' : undeclared identifier

since i had all the headers!
winsock.h
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22805407
As I said : follow the instructions of the warnings/errors one at a time - starting with the first.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22805411
>> Such errors does not make sense

Always solve the first warnings/errors first. The others might simply be indirect cosequences of those.
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805413
here are my headers

#include<iostream>
#include<string>
#include<sstream>
#include<winsock.h>
#include"stdafx.h"

0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805414
Alright...I will give it a try
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22805423
I put #include "stdafx.h" at the first line.

I got fewer errors which most of them about undefineds. This is confuses me, because i declared all the following variables as globals:

struct addrinfo hints;            
struct addrinfo *results;       
char *remoteIP = new char[40];  
string tempPort;              
int startingPort;              
int status;                    
int currentPort;        
------ Build started: Project: vvv, Configuration: Debug Win32 ------
Compiling...
vvv.cpp
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : error C2079: 'hints' uses undefined struct 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(30) : error C3861: 'getaddrinfo': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(34) : error C3861: 'gai_strerror': identifier not found
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(49) : error C2227: left of '->ai_next' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(53) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(55) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2027: use of undefined type 'grabHostName::sockaddr_in6'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(60) : see declaration of 'grabHostName::sockaddr_in6'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(61) : error C2227: left of '->sin6_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(103) : error C2228: left of '.ai_family' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(104) : error C2228: left of '.ai_socktype' must have class/struct/union
        type is 'int'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_family' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_socktype' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(132) : error C2227: left of '->ai_protocol' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(142) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addr' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2027: use of undefined type 'addrinfo'
        c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(9) : see declaration of 'addrinfo'
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(147) : error C2227: left of '->ai_addrlen' must point to class/struct/union/generic type
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(151) : error C2065: 'ECONNREFUSED' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(153) : error C2065: 'ETIMEDOUT' : undeclared identifier
c:\documents and settings\fahmi\my documents\visual studio 2008\projects\vvv\vvv\vvv.cpp(173) : error C3861: 'freeaddrinfo': identifier not found
Build log was saved at "file://c:\Documents and Settings\Fahmi\My Documents\Visual Studio 2008\Projects\vvv\vvv\Debug\BuildLog.htm"
vvv - 30 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Open in new window

0
 
LVL 1

Author Comment

by:F-J-K
ID: 22806184
It Compiled.....I had to make the header as follows:

#include<iostream>
#include<string>
#include<sstream>
#include<Ws2tcpip.h>
#include<Winerror.h>
//#include"WinSock.h" *****HOW COME IT COMPILES WITHOUT USING WINSOCK!**** Odd, isn't it?!

Anyhow, the executed program does not work! It crashes immediately...

Anyway, thanks for help. I will just ignore this project.
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22806427
DONE....PHEW Worked....Thx for your support anyway....It helped me
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22806460
>> //#include"WinSock.h" *****HOW COME IT COMPILES WITHOUT USING WINSOCK!**** Odd, isn't it?!

Probably, because you have this one :

>> #include<Ws2tcpip.h>


>> Anyhow, the executed program does not work! It crashes immediately...

You need to find out at what line it crashes. I don't know what code you used on the Windows machine, so ...


>> DONE....PHEW Worked....Thx for your support anyway....It helped me

Nice ;)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question