Thread: Does VS not like copypasta?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    28

    Does VS not like copypasta?

    I found a port scanner online that I wanted to plug into the compiler to tinker with


    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <winsock.h>
    #include <algorithm>
    using namespace std;
    
    // declare globals
    SOCKET sock;
    ofstream outfile;
    //Connecttohost connects to a remote host
    
    
    bool ConnectToHost(int PortNo, char* IPAddress) {
    //start up winsock
    WSADATA wsadata;
    
    int error = WSAStartup(0×0202, &wsadata);
    
    //error did something happen
    if (error) {
    return false;
    }
    
    
    
    // check if we get the right winsock version
    if (wsadata.wVersion != 0×0202) {
    if (wsadata.wVersion != 0×0202) {
    
    WSACleanup();
    return false;
    }
    
    SOCKADDR_IN target;
    
    target.sin_family = AF_INET;
    target.sin_port = htons (PortNo);
    target.sin_addr.s_addr = inet_addr (IPAddress);
    
    sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // create socket
    if (sock == INVALID_SOCKET)
    {
    return false; // could not create the socket
    }
    
    // try connecting
    
    if (connect(sock, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
    {
    cout << "false" << endl;
    outfile << "false" << endl;
    return false; //couldn’t connect
    }
    else {
    cout << "true" << endl;
    outfile << "true" << endl;
    return true; // success
    }
    }
    
    void CloseConnection () {
    if (sock)
    closesocket(sock);
    
    WSACleanup();
    }
    
    char *convertStringToChar(const string &str)
    {
    char *retPtr(new char[str.length() + 1]);
    
    copy(str.begin(), str.end(), retPtr);
    retPtr[str.length()] = ”;
    
    return retPtr;
    }
    
    
    int main()
    {
    string line;
    int myport1;
    int myport2;
    int i;
    cout << "\n\n";
    cout << "Enter the starting PORT You wish to attempt a connection on, example: \t 21 \n" << endl;
    cin >> myport1;
    cout << "Enter the Ending PORT You wish to attempt a connection on, example: \t 25 \n" << endl;
    cin >> myport2;
    outfile.open("outfile.txt");
    ifstream myfile("input.txt");
    if (myfile.is_open())
    {
    while (!myfile.eof())
    {
    getline(myfile, line);
    for (i = myport1; i <= myport2; i++)
    {
    ConnectToHost(i, convertStringToChar(line));
    cout << i << " \t " << line << endl;
    outfile << i << " \t" << line << endl;
    
    }
    
    }
    myfile.close();
    outfile.close();
    }
    else cout << "Unable to open file input.txt\n\n";
    system("PAUSE");
    return EXIT_SUCCESS;
    }

    here are the errors I got

    1>------ Build started: Project: port scan, Configuration: Debug Win32 ------
    1> port scan.cpp
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(2): warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(3): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(4): warning C4627: '#include <fstream>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(5): warning C4627: '#include <string>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(6): warning C4627: '#include <winsock.h>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(7): warning C4627: '#include <algorithm>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(117): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Apparently it really wants this stdafx.h file so I included it and retried.


    Code:
    #include "stdafx.h"
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <winsock.h>
    #include <algorithm>
    using namespace std;
    
    // declare globals
    SOCKET sock;
    ofstream outfile;
    //Connecttohost connects to a remote host
    
    
    bool ConnectToHost(int PortNo, char* IPAddress) {
    //start up winsock
    WSADATA wsadata;
    
    int error = WSAStartup(0×0202, &wsadata);
    
    //error did something happen
    if (error) {
    return false;
    }
    
    
    
    // check if we get the right winsock version
    if (wsadata.wVersion != 0×0202) {
    if (wsadata.wVersion != 0×0202) {
    
    WSACleanup();
    return false;
    }
    
    SOCKADDR_IN target;
    
    target.sin_family = AF_INET;
    target.sin_port = htons (PortNo);
    target.sin_addr.s_addr = inet_addr (IPAddress);
    
    sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // create socket
    if (sock == INVALID_SOCKET)
    {
    return false; // could not create the socket
    }
    
    // try connecting
    
    if (connect(sock, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
    {
    cout << "false" << endl;
    outfile << "false" << endl;
    return false; //couldn’t connect
    }
    else {
    cout << "true" << endl;
    outfile << "true" << endl;
    return true; // success
    }
    }
    
    void CloseConnection () {
    if (sock)
    closesocket(sock);
    
    WSACleanup();
    }
    
    char *convertStringToChar(const string &str)
    {
    char *retPtr(new char[str.length() + 1]);
    
    copy(str.begin(), str.end(), retPtr);
    retPtr[str.length()] = ”;
    
    return retPtr;
    }
    
    
    int main()
    {
    string line;
    int myport1;
    int myport2;
    int i;
    cout << "\n\n";
    cout << "Enter the starting PORT You wish to attempt a connection on, example: \t 21 \n" << endl;
    cin >> myport1;
    cout << "Enter the Ending PORT You wish to attempt a connection on, example: \t 25 \n" << endl;
    cin >> myport2;
    outfile.open("outfile.txt");
    ifstream myfile("input.txt");
    if (myfile.is_open())
    {
    while (!myfile.eof())
    {
    getline(myfile, line);
    for (i = myport1; i <= myport2; i++)
    {
    ConnectToHost(i, convertStringToChar(line));
    cout << i << " \t " << line << endl;
    outfile << i << " \t" << line << endl;
    
    }
    
    }
    myfile.close();
    outfile.close();
    }
    else cout << "Unable to open file input.txt\n\n";
    system("PAUSE");
    return EXIT_SUCCESS;
    }

    again, a list of errors

    1>------ Build started: Project: port scan, Configuration: Debug Win32 ------
    1> port scan.cpp
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(20): error C2146: syntax error : missing ')' before identifier '×0202'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(20): error C2660: 'WSAStartup' : function does not take 1 arguments
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(20): error C2059: syntax error : ')'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(30): error C2146: syntax error : missing ')' before identifier '×0202'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(30): error C2059: syntax error : ')'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(30): error C2065: '×0202' : undeclared identifier
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(30): error C2143: syntax error : missing ';' before '{'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(31): error C2146: syntax error : missing ')' before identifier '×0202'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(31): error C2059: syntax error : ')'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(31): error C2065: '×0202' : undeclared identifier
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(31): error C2143: syntax error : missing ';' before '{'
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(64): error C2601: 'CloseConnection' : local function definitions are illegal
    1> c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(16): this line contains a '{' which has not yet been matched
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(72): error C2601: 'convertStringToChar' : local function definitions are illegal
    1> c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(16): this line contains a '{' which has not yet been matched
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(83): error C2601: 'main' : local function definitions are illegal
    1> c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(16): this line contains a '{' which has not yet been matched
    1>c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(117): fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(16)' was matched
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    And the first time I compiled it, it thought for some reason that words inside quotes didn't count as strings. Oddly enough, it recognised them when I deleted and reentered the quotes. Is the code wrong or does VS just not like it when you copy and paste? If someone can give me a simpler port scan, I'd appreciate it. That's all I want.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > int error = WSAStartup(0×0202, &wsadata);
    Look at that x
    Well it isn't an x, it's an ×

    Make sure you copy things formatted as code, not dumb/pretty HTML.

    Oh, and for stdafx.h, use the project settings to turn OFF precompiled headers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Apparently it really wants this stdafx.h file so I included it and retried.
    Turn off precompiled headers when you make your project.

    Oddly enough, it recognised them when I deleted and reentered the quotes.
    Quick check: does the "Find" tool find the quotes correctly? That is, if you do a search for the " character does it find the quotes? If not it's possible the source had a different encoding (very possible if it was from the web).

    EDIT: Beaten again! This forum moves fast.
    Consider this post signed

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    28
    Thanks. I turned off precompiled headers but I still get the errors. I would search for the quotes but I've already replaced them. Anyway, here is the site it came from

    C++ CMD Line Port Scanner | Flyninja Dot Net

    Probably right about encoding. I'm going to copy by hand and see what happens.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to turn off precompiled headers. They will speed up the compilation process.
    Just take all the headers in the file (copy them, don't move them) and put them in stdafx.h.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    PCH is only worth the hassle on large projects with a reasonably static group of header files that must be included in the vast majority of files.

    The single source noob homework file doesn't qualify.

    It promotes woolly thinking, because the easy cop-out is to throw everthing in the PCH file. But that leads to creeping dependencies (and a whole mess of work if you need to refactorise).

    If each module includes ONLY what it needs (and no more), then it's dead easy to spot when you're breaking your interface rules because it doesn't compile anymore.

    Plus, it's one of the top 5 "why doesn't VS blah, and what is stdafh.h all about" questions we get on a regular basis.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Since it's one of the top 5 questions, all the more reason to teach newbies to properly use them, if you ask me. It saves huge amount of time. Yes, even for n00b projects.
    Just try including a boost header.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    I turned off precompiled headers but I still get the errors.
    ...did you do what Salem said?, too?
    > int error = WSAStartup(0×0202, &wsadata);
    Look at that x
    Well it isn't an x, it's an ×
    Right, so the compiler thinks that ×0202 is either a variable or a macro (they're very lenient on how you name things) and that's not the case so it yells at you. Also because each case of ×0202 is preceded by a 0. The x (actual lowercase x) would signify that a hexadecimal number is being represented there, FYI.

    And as for the quotes, the problem is that there are forward quotes and backquotes, ie
    “\n\n”
    instead of "normal" quotes (like what shows up when typing in this forum).

    So, search and replace or copy by hand - whichever you prefer.
    Consider this post signed

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by bernt View Post
    ...did you do what Salem said?, too?
    This won't help a damn thing. Don't do it. Ignore it. Focus on fixing your errors instead.
    First off, as you already noticed, is your weird "x" symbol, which isn't the character x, which is what C++ wants. Do a search and replace.

    Second weird line is this
    Code:
    retPtr[str.length()] = ”;
    Again with the weird characters which C++ doesn't recognize. Plus the character literal is empty. That's not going to work. You have to assign something or nothing at all.

    And thirdly, your indentation sucks. And that is exactly why you get the last errors. Because you're missing a brace. Indent. Find it. Fix it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    28
    okay, so I copied by hand and I noticed this little gem

    Code:
    retPtr[str.length()] = ”;
    The genius forgot to put something on the other side of the assignment. I have no idea what this part of the code does so I just put a 'c' there. Anyway, here's the whole thing as I typed it and the errors that go along with it. Is it because of that 'c' or something else?

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <WinSock.h>
    #include <algorithm>
    using namespace std;
    
    //globals
    
    SOCKET sock;
    ofstream outfile;
    
    //connecttohost connects to a remote host
    
    //functions
    
    bool ConnectToHost(int PortNo, char* IPAddress)
    {
    	//start winsock
    	WSADATA wsadata;
    
    	int error = WSAStartup(0x0202, &wsadata);
    	//error did something happen
    	if (error)
    	{
    		return false;
    	}
    
    	SOCKADDR_IN target;
    
    	target.sin_family = AF_INET;
    	target.sin_port = htons (PortNo);
    	target.sin_addr.s_addr = inet_addr (IPAddress);
    
    	sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //create socket
    	if (sock == INVALID_SOCKET)
    	{
    		return false; //could not create socket
    	}
    
    	//try connecting
    
    	if(connect(sock, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
    	{
    		cout << "false" << endl;
    		outfile << "false" << endl;
    		return false; //couldn't connect
    
    	}
    	else
    	{
    		cout << "true" << endl;
    		outfile << "true" << endl;
    		return true; //success
    	}
    
    }
    
    void CloseConnection ()
    {
    	if (sock)
    		closesocket(sock);
    
    	WSACleanup();
    
    }
    
    char *convertStringToChar(const string &str)
    {
    	char *retPtr(new char[str.length() + 1]);
    
    	copy(str.begin(), str.end(), retPtr);
    	retPtr[str.length()] = 'c';
    
    	return retPtr;
    }
    
    
    
    int main()
    {
    	string line;
    	int myport1;
    	int myport2;
    	int i;
    	cout << "\n\n";
    	cout << "Enter the starting PORT You wish to attempt a connection on, example: \t 21 \n" << endl;
    	cin >> myport1;
    	cout << "Enter the Ending PORT You wish to attempt a connection on, example: \t 25 \n" << endl;
    	cin >> myport2;
    	outfile.open("outfile.txt");
    	ifstream myfile ("input.txt");
    	if (myfile.is_open())
    	{
    		while (!myfile.eof())
    		{
    			getline(myfile,line);
    			for (i = myport1; i <= myport2; i++)
    			{
    				ConnectToHost(i,convertStringToChar(line));
    				cout << i << "\t" << line << endl;
    				outfile << i << "\t" << line << endl;
    
    			}
    
    		}
    		myfile.close();
    		outfile.close();
    	}
    	else cout << "Unable to open file input.txt\n\n";
    	system("PAUSE");
    	return EXIT_SUCCESS;
    }
    errors:

    1>------ Build started: Project: port scan, Configuration: Debug Win32 ------
    1> port scan.cpp
    1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
    1> c:\program files\microsoft visual studio 10.0\vc\include\xutility(2212) : see declaration of 'std::_Copy_impl'
    1> c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(73) : see reference to function template instantiation '_OutIt std::copy<std::_String_const_iterator<_Elem,_Trait s,_Alloc>,char*>(_InIt,_InIt,_OutIt)' being compiled
    1> with
    1> [
    1> _OutIt=char *,
    1> _Elem=char,
    1> _Traits=std::char_traits<char>,
    1> _Alloc=std::allocator<char>,
    1> _InIt=std::_String_const_iterator<char,std::char_t raits<char>,std::allocator<char>>
    1> ]
    1>port scan.obj : error LNK2019: unresolved external symbol _connect@12 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol _inet_addr@4 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol _htons@4 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function "void __cdecl CloseConnection(void)" (?CloseConnection@@YAXXZ)
    1>port scan.obj : error LNK2019: unresolved external symbol _closesocket@4 referenced in function "void __cdecl CloseConnection(void)" (?CloseConnection@@YAXXZ)
    1>C:\Documents and Settings\Rian Saville\My Documents\Visual Studio 2010\Projects\port scan\Debug\port scan.exe : fatal error LNK1120: 7 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Thanks for telling me what the stdafx file is for though I'm not going to really worry about optimizing my code until it actually works.

  11. #11
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    For one, it can't find the definitions of your socket functions. Maybe you should try winsock2.h.

    Actually, you probably have to include the winsock.dll file in your solution so that it links properly.

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    28
    do I include a dll like any other header?

    #include <winsock.dll> ?

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    28
    Yeah, I tried adding winsock2.h and got this.


    1>------ Build started: Project: port scan, Configuration: Debug Win32 ------
    1> port scan.cpp
    1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
    1> c:\program files\microsoft visual studio 10.0\vc\include\xutility(2212) : see declaration of 'std::_Copy_impl'
    1> c:\documents and settings\rian saville\my documents\visual studio 2010\projects\port scan\port scan\port scan.cpp(74) : see reference to function template instantiation '_OutIt std::copy<std::_String_const_iterator<_Elem,_Trait s,_Alloc>,char*>(_InIt,_InIt,_OutIt)' being compiled
    1> with
    1> [
    1> _OutIt=char *,
    1> _Elem=char,
    1> _Traits=std::char_traits<char>,
    1> _Alloc=std::allocator<char>,
    1> _InIt=std::_String_const_iterator<char,std::char_t raits<char>,std::allocator<char>>
    1> ]
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "bool __cdecl ConnectToHost(int,char *)" (?ConnectToHost@@YA_NHPAD@Z)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function "void __cdecl CloseConnection(void)" (?CloseConnection@@YAXXZ)
    1>port scan.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "void __cdecl CloseConnection(void)" (?CloseConnection@@YAXXZ)
    1>C:\Documents and Settings\Rian Saville\My Documents\Visual Studio 2010\Projects\port scan\Debug\port scan.exe : fatal error LNK1120: 7 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    The first time, I included both winsock and winsock2 and it really didn't like that. So I commented out winsock and got the above. Still trying to figure out how to include a dll. I'll see if google can help.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Goto project properties -> C/C++ -> Linker -> Input -> Additional input and add Ws2_32.lib.
    Now try compiling again.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    28
    THANKS! It almost works now. It compiles and this is what the console spat out



    Enter the starting PORT You wish to attempt a connection on, example: 21

    1
    Enter the Ending PORT You wish to attempt a connection on, example: 25

    100
    Unable to open file input.txt

    false
    1
    false
    2
    false
    3
    false
    4
    false
    5
    false
    6
    false
    7
    false
    8
    false
    9
    false
    10
    false
    11
    false
    12
    false
    13
    false
    14
    false
    15
    false
    16
    false
    17
    false
    18
    false
    19
    false
    20
    false
    21
    false
    22
    false
    23
    false
    24
    false
    25
    false
    26
    false
    27
    false
    28
    false
    29
    false
    30
    false
    31
    false
    32
    false
    33
    false
    34
    false
    35
    false
    36
    false
    37
    false
    38
    false
    39
    false
    40
    false
    41
    false
    42
    false
    43
    false
    44
    false
    45
    false
    46
    false
    47
    false
    48
    false
    49
    false
    50
    false
    51
    false
    52
    false
    53
    false
    54
    false
    55
    false
    56
    false
    57
    false
    58
    false
    59
    false
    60
    false
    61
    false
    62
    false
    63
    false
    64
    false
    65
    false
    66
    false
    67
    false
    68
    false
    69
    false
    70
    false
    71
    false
    72
    false
    73
    false
    74
    false
    75
    false
    76
    false
    77
    false
    78
    false
    79
    false
    80
    false
    81
    false
    82
    false
    83
    false
    84
    false
    85
    false
    86
    false
    87
    false
    88
    false
    89
    false
    90
    false
    91
    false
    92
    false
    93
    false
    94
    false
    95
    false
    96
    false
    97
    false
    98
    false
    99
    false
    100


    for some reason it won't open that text file. But hey, we're making progress.

    btw, are the data on ports supposed to be represented by bools? I always thought it would be a byte.

Popular pages Recent additions subscribe to a feed