CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Sep 2004
    Posts
    156

    ping a server in vc.net

    I wrote code in vc++ 6.0 to ping a server which works well but the same doesnt work in vc.net .

    i tried with the following lib files
    #pragma comment(linker,ws2_32)
    ws2_32.lib
    #pragma comment( linker, "/defaultlib:ws2_32.lib")

    and i aslo included the winsock2.h

    Could any one suggest me a solution

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: ping a server in vc.net

    Well...what does not work?

  3. #3
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    the application is giving linking errors

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: ping a server in vc.net

    Well...what linker errors?

  5. #5
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _WinMain@16
    error LNK2019: unresolved external symbol __imp__gethostbyaddr@12 referenced in function _WinMain@16
    error LNK2019: unresolved external symbol __imp__gethostbyname@4 referenced in function _WinMain@16
    error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _WinMain@16

    these are linking errors i am getting when i execute the same code in vc.net,

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: ping a server in vc.net

    Code:
    #pragma comment (lib, "ws2_32")

  7. #7
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    i tried #pragma comment (lib, "ws2_32") but still i am getting the same errors

  8. #8
    Join Date
    Aug 2003
    Posts
    70

    Re: same problem with winsock32.dll

    hi,

    i had the same linking problem with winsock32.dll. the code compiled fine, but i couldn't link to the mentioned dll -- unresolved externals on dll functions. couldn't find a solution
    notyetguru,
    (MSVC++ 6.0)

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: ping a server in vc.net

    Well...that is interesting...can you post a compilable sample program which recreates the error?

  10. #10
    Join Date
    Aug 2003
    Posts
    70

    Re: ping a server in vc.net

    Oiriginally posted by Andreas Masur
    Well...that is interesting...can you post a compilable sample program which recreates the error?
    Well, I don't have the source code of the program here (at my job). I tried to develop the client/server winsock based program some years ago when i was learning visual c++, it was for learning purposes only, and after getting the unresolved external errors i gave up after a while. i don't know if i still have the
    source code on my home computer. however, the questions remain, since then
    i wasn't confronted with internet socket programming again.
    notyetguru,
    (MSVC++ 6.0)

  11. #11
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    the core part of the code is



    #include "stdafx.h"
    #include "Pingnet.h"
    #include "PingnetDlg.h"
    #include"winsock2.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif


    void abc(char *p)
    {
    FILE *fp=fopen("TraceNet.TXT","a+");
    fprintf(fp,"%s\n",p);
    fclose(fp);
    }
    struct o
    {
    unsigned char Ttl;
    unsigned char a[7];
    };
    struct
    {
    DWORD Address;
    unsigned long Status,RoundTripTime;
    unsigned char a[8];
    struct o Options;
    } E;


    HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent *phostent;
    DWORD d;char aa[100];struct o I;char bb[100];int z;

    HANDLE ( WINAPI *pIcmpCreateFile )( VOID );
    BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE );
    DWORD (WINAPI *pIcmpSendEcho) (HANDLE,DWORD,LPVOID,WORD, LPVOID,LPVOID,DWORD,DWORD);


    void CPingnetDlg::OnBnClickedOk()
    {
    hIcmp = LoadLibrary( "ICMP.DLL" );
    WSAStartup( 0x0101, &wsa );
    pIcmpCreateFile = (HANDLE (WINAPI *)(void))
    GetProcAddress((HMODULE)hIcmp,"IcmpCreateFile");
    pIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
    GetProcAddress((HMODULE)hIcmp,"IcmpCloseHandle");
    pIcmpSendEcho = (DWORD (WINAPI *)
    (HANDLE,DWORD,LPVOID,WORD, LPVOID,LPVOID,DWORD,DWORD))
    GetProcAddress((HMODULE)hIcmp,"IcmpSendEcho");

    hIP = pIcmpCreateFile();

    for ( z = 1; z<= 20 ; z++)
    {
    I.Ttl=(unsigned char)z;
    // phostent = gethostbyname( "66.28.63.63");
    phostent = gethostbyname( "64.246.52.100");
    // phostent = gethostbyname( "66.98.128.62");
    dwIPAddr = (DWORD *)( *phostent->h_addr_list );
    pIcmpSendEcho(hIP,*dwIPAddr,0,0,&I,&E,sizeof(E),8000 );
    d=E.Address;
    phostent = gethostbyaddr((char *)&d,4,PF_INET);
    if ( phostent != 0)
    strcpy(aa,phostent->h_name) ;
    else
    strcpy(aa,"no host name");
    wsprintf(bb," RTT: %dms, TTL: %d", E.RoundTripTime, E.Options.Ttl );
    strcat(aa,bb);
    abc(aa);
    if ( E.Options.Ttl )
    {
    AfxMessageBox("Pinging");
    break;
    }
    }
    pIcmpCloseHandle( hIP );
    FreeLibrary((HMODULE)hIcmp);
    WSACleanup();

    // TODO: Add your control notification handler code here
    //OnOK();
    }


    this code worked fine in vc++ 6.0 but not vc.net

  12. #12
    Join Date
    Aug 2003
    Posts
    70

    Re: ping a server in vc.net

    give it a try with
    Code:
    #pragma comment(lib, "winsock32.dll")
    just curious
    notyetguru,
    (MSVC++ 6.0)

  13. #13
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    still it is not working with #pragma comment(lib, "winsock32.dll")

  14. #14
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    is there anyway to solve my problem

  15. #15
    Join Date
    Sep 2004
    Posts
    156

    Re: ping a server in vc.net

    can anyone bring me out of this labyrinth

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured