943,946 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 737
  • C++ RSS
Oct 21st, 2009
0

Unknown errors in code (doesn't connect to dns local server)

Expand Post »
Hello
I have a problem with this code. I'm trying to connect to local dns server in order to get the ip of the hostname( that user would enter). For now, i'm just trying to connect to the local dns server, and this code gives me following 8 errors..

client.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
client.obj : error LNK2001: unresolved external symbol __imp__connect@12
client.obj : error LNK2001: unresolved external symbol __imp__htons@4
client.obj : error LNK2001: unresolved external symbol __imp__inet_addr@4
client.obj : error LNK2001: unresolved external symbol __imp__socket@12
client.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
client.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/client.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.


The code goes here
C++ Syntax (Toggle Plain Text)
  1. #define WIN32_LEAN_AND_MEAN
  2. #pragma comment(lib, "wininet.lib")
  3. #include <winsock2.h>
  4. #include <windows.h>
  5. #include <iostream.h>
  6. #include <conio.h>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. void main()
  12. {
  13. WSADATA wsadat;
  14. WORD rVersion;
  15. rVersion = MAKEWORD(2,0);
  16.  
  17. if(WSAStartup(rVersion, &wsadat) != NO_ERROR)
  18. {
  19. cout<<"WSA initialization failed.\n";
  20. WSACleanup();
  21. return;
  22. }
  23.  
  24. SOCKET client;
  25. client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  26. if(client == INVALID_SOCKET)
  27. {
  28. cout<<"Error creating socket.\n";
  29. WSACleanup();
  30. return;
  31. }
  32.  
  33. char *ip= "208.67.222.222";
  34. cout<<ip;
  35. SOCKADDR_IN server;
  36. server.sin_family= AF_INET;
  37. server.sin_addr.s_addr= inet_addr(ip);
  38. server.sin_port= htons(53);
  39.  
  40. if(connect(client, (SOCKADDR*) &server, sizeof(server)) == SOCKET_ERROR)
  41. {
  42. cout<<"Connection cannot be established. \n";
  43. WSACleanup();
  44. return;
  45. }
  46.  
  47.  
  48. closesocket(client);
  49. WSACleanup();
  50.  
  51. return;
  52. }
I don't know what to do... Kindly help me out, I need to submit my assignment by Friday......
Regards
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Umar Ali is offline Offline
19 posts
since Nov 2008
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
You're not linking to the correct library. I'm not 100% sure, but adding:
#pragma comment(lib, "wsock32.lib") should do the trick
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
Click to Expand / Collapse  Quote originally posted by niek_e ...
You're not linking to the correct library. I'm not 100% sure, but adding:
#pragma comment(lib, "wsock32.lib") should do the trick
Thanks for your reply. Well I added your mentioned library and it gives me this poppycock...

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shimeng.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\hnetcfg.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
The thread 0x850 has exited with code 0 (0x0).
The program 'C:\Documents and Settings\Yasir\Desktop\Debug\client.exe' has exited with code 0 (0x0)


Now what??
Last edited by Umar Ali; Oct 21st, 2009 at 6:26 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Umar Ali is offline Offline
19 posts
since Nov 2008
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
What compiler are you using?
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
Click to Expand / Collapse  Quote originally posted by niek_e ...
What compiler are you using?
I don't know what's my compiler
Last edited by Umar Ali; Oct 21st, 2009 at 7:21 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Umar Ali is offline Offline
19 posts
since Nov 2008
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
Click to Expand / Collapse  Quote originally posted by Umar Ali ...
I don't know what's my compiler
Turbo, Visual Studio, Gcc, Mingw?
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 21st, 2009
0
Re: Unknown errors in code (doesn't connect to dns local server)
Click to Expand / Collapse  Quote originally posted by niek_e ...
Turbo, Visual Studio, Gcc, Mingw?
I'm using visual c++ 6, i guess i uses vc compiler :-|
Last edited by Umar Ali; Oct 21st, 2009 at 8:04 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Umar Ali is offline Offline
19 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Ms-Access as back end for files in cpp
Next Thread in C++ Forum Timeline: multiple definition???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC