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

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 8
Reputation: Umar Ali is an unknown quantity at this point 
Solved Threads: 0
Umar Ali Umar Ali is offline Offline
Newbie Poster

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

 
0
  #1
Oct 21st, 2009
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
  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
“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” (Bill Gates)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,996
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac
 
0
  #2
Oct 21st, 2009
You're not linking to the correct library. I'm not 100% sure, but adding:
#pragma comment(lib, "wsock32.lib") should do the trick
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: Umar Ali is an unknown quantity at this point 
Solved Threads: 0
Umar Ali Umar Ali is offline Offline
Newbie Poster
 
0
  #3
Oct 21st, 2009
Originally Posted by niek_e View Post
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.
“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” (Bill Gates)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,996
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac
 
0
  #4
Oct 21st, 2009
What compiler are you using?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: Umar Ali is an unknown quantity at this point 
Solved Threads: 0
Umar Ali Umar Ali is offline Offline
Newbie Poster
 
0
  #5
Oct 21st, 2009
Originally Posted by niek_e View Post
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.
“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” (Bill Gates)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,996
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac
 
0
  #6
Oct 21st, 2009
Originally Posted by Umar Ali View Post
I don't know what's my compiler
Turbo, Visual Studio, Gcc, Mingw?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: Umar Ali is an unknown quantity at this point 
Solved Threads: 0
Umar Ali Umar Ali is offline Offline
Newbie Poster
 
0
  #7
Oct 21st, 2009
Originally Posted by niek_e View Post
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.
“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” (Bill Gates)
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 344 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC