Click here to Skip to main content
15,906,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modeless (again) Pin
Gary R. Wheeler4-May-02 3:54
Gary R. Wheeler4-May-02 3:54 
GeneralHelp with UI Pin
Steve L.3-May-02 10:39
Steve L.3-May-02 10:39 
GeneralRe: Help with UI Pin
PJ Arends3-May-02 10:45
professionalPJ Arends3-May-02 10:45 
GeneralRe: Help with UI Pin
Steve L.3-May-02 11:10
Steve L.3-May-02 11:10 
GeneralCView: Control colors Pin
Anton A. Loukine3-May-02 10:37
Anton A. Loukine3-May-02 10:37 
GeneralRe: CView: Control colors Pin
Nish Nishant3-May-02 14:00
sitebuilderNish Nishant3-May-02 14:00 
GeneralRe: CView: Control colors Pin
Stan the man3-May-02 17:00
Stan the man3-May-02 17:00 
GeneralResolving Hostname Using getaddrinfo(...) :: Winsock Pin
valikac3-May-02 10:27
valikac3-May-02 10:27 
Hi.

I am new to winsock program and has began study from Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohlund.

I am trying to get a code to basically resolve a hostname to its ip address. For example:

-----
user input: www.microsoft.com
app output: 207.46.230.220
-----

I am able to get the calculation above working using older winsock 1.1+ tool including the use of structure hostent, gethostbyname(), and inet_ntoa().

However, in their book, Jones and Ohlund recommend using the newer winsock tools including getaddrinfo() and getnameinfo(). I cannot figure out how to extract the corresponding IP address from a hostname. Here is the code:

-----
int rc = 0;
addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

if (getaddrinfo(rHName, "21", &hints, &result) != 0)
return false;
else
{

// This is where I need help getting the IP address

m_sIP = (reinterpret_cast<sockaddr *="">(result->ai_addr)->sa_data());// ->sa_data(); // inet_ntoa(*(reinterpret_cast<in_addr *="">(host->h_addr)));

return = true;
}
-----

In the code above, m_sIP is a character array. What do I have to cast result->ai_addr in order to access the IP address?

Thanks,
Kuphryn
GeneralRe: Solution Pin
valikac3-May-02 16:40
valikac3-May-02 16:40 
Questiondoes this ASSERT make sense to you? Pin
3-May-02 9:13
suss3-May-02 9:13 
AnswerRe: does this ASSERT make sense to you? Pin
Jack Handy3-May-02 9:33
Jack Handy3-May-02 9:33 
AnswerRe: does this ASSERT make sense to you? Pin
Ravi Bhavnani3-May-02 9:47
professionalRavi Bhavnani3-May-02 9:47 
GeneralRe: does this ASSERT make sense to you? Pin
3-May-02 11:05
suss3-May-02 11:05 
GeneralCPropertySheet change Cancel Button Pin
moobob3-May-02 9:01
moobob3-May-02 9:01 
GeneralRe: CPropertySheet change Cancel Button Pin
Tim Smith3-May-02 9:05
Tim Smith3-May-02 9:05 
GeneralRe: CPropertySheet change Cancel Button Pin
moobob3-May-02 9:39
moobob3-May-02 9:39 
GeneralRe: CPropertySheet change Cancel Button Pin
Tim Smith3-May-02 9:55
Tim Smith3-May-02 9:55 
QuestionHow does net start service_name.exe call the service? Pin
Craig Miller3-May-02 8:50
Craig Miller3-May-02 8:50 
AnswerRe: How does net start service_name.exe call the service? Pin
Tim Smith3-May-02 9:03
Tim Smith3-May-02 9:03 
GeneralRe: How does net start service_name.exe call the service? Pin
Craig Miller3-May-02 9:42
Craig Miller3-May-02 9:42 
GeneralRe: How does net start service_name.exe call the service? Pin
Tim Smith3-May-02 9:59
Tim Smith3-May-02 9:59 
GeneralRe: How does net start service_name.exe call the service? Pin
Craig Miller3-May-02 10:13
Craig Miller3-May-02 10:13 
GeneralRe: How does net start service_name.exe call the service? Pin
Tim Smith3-May-02 10:36
Tim Smith3-May-02 10:36 
GeneralRe: How does net start service_name.exe call the service? Pin
Craig Miller3-May-02 11:44
Craig Miller3-May-02 11:44 
GeneralTest my new hash algorithm Pin
Dominik Reichl3-May-02 8:42
Dominik Reichl3-May-02 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.