gethostbyaddr

This is a discussion on gethostbyaddr within the Windows Programming forums, part of the Platform Specific Boards category; If anyone here has ever used the function gethostbyaddr or gethostbyname can you pleas tell me how to use them...

  1. #1
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    Question gethostbyaddr

    If anyone here has ever used the function gethostbyaddr or gethostbyname can you pleas tell me how to use them

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Here is a MFC snippet. I just made it in a hurry, to show you the usage of gethostbyname.
    The whole thing is in the OnOK event, as you see.
    The dialog contains a ListBox(multiline, control variable m_ListC, to display the data ) and an EditBox (control var m_EditV) to enter host name.

    void CGethostDlg::OnOK()
    {
    // TODO: Add extra validation here
    hostent* aHostenPtr;
    CString aHostName;

    UpdateData( TRUE );
    if ( m_EditV.IsEmpty() ) // if no data entered, warn
    {
    MessageBox( "Enter host name, please!","No host name entered", MB_OK );
    return;
    }

    aHostName = m_EditV;
    const char* aHostNameChr = (LPCSTR)aHostName;

    aHostenPtr = gethostbyname( aHostNameChr );
    if ( !aHostenPtr )
    {
    MessageBox( "gethostbyname failed!", "Warning", MB_OK );
    return;
    }

    m_ListC.AddString( (LPCTSTR) aHostenPtr->h_aliases );
    m_ListC.AddString( (LPCTSTR) aHostenPtr->h_name );
    m_ListC.AddString( (LPCTSTR) aHostenPtr->h_addr_list[0] );

    UpdateData( FALSE );
    }

    Whether with or without MFC, the function needs a hostent* as return type, and char* as param.

    That's all, hope this helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gethostbyaddr() reverse lookups failing (???)
    By Uncle Rico in forum C Programming
    Replies: 9
    Last Post: 08-19-2005, 09:22 AM
  2. gethostbyaddr is slow
    By eth0 in forum Networking/Device Communication
    Replies: 7
    Last Post: 05-18-2005, 04:16 AM
  3. gethostbyaddr() returning NULL
    By Snip in forum Networking/Device Communication
    Replies: 6
    Last Post: 02-12-2005, 04:03 PM
  4. gethostbyaddr( )
    By xlordt in forum Networking/Device Communication
    Replies: 4
    Last Post: 10-06-2003, 08:25 PM
  5. gethostbyaddr Help Plz
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 08-30-2001, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21