[C++] domain to ip

rook

Erfahrenes Mitglied
hey... :)

weiss einer wie ich eine domain zur ip auflöse?
ich brauche das, um auf einen server zu connecten, besser gesagt, auf meinen server.. über die externe ip, da es eine static ip ist, wächselt sie ständig... bin aber bei dyndns.org :)

nur hab ich kein plan :(
 
moin


du hast geschrieben:
"über die externe ip, da es eine static ip ist, wächselt sie ständig".

hä? wenn sie statisch ist wechselt sie?

hast du dich verschrieben oder hab ich was falsch verstanden?



mfg
umbrasaxum
 
Original geschrieben von reima
Hm, nur aus reinem Interesse, theoretisch würde es in *n?x mit gethostbyname() auch funktionieren, oder? WinSock kommt ja von der Unix-Ecke, wenn ich mich nicht ganz täusche...

es gibt eine Funktion in der netdb.h
sruct hostend *gethostbyname(cont char *name);

dann gibt es in der sys/socekt.h
sruct hostent *gethostbyadrr(const char *addr, int len, int type);

gib einfach auf Linux system
man gethostbyname
ein.

Ja der Ganze TCP/IP Bereich von Windows kommt von FreeBSD bzw *BSD
 
also, mein code sieht so aus...

Code:
hostent *ip;
ip = gethostbyname("x");

dummerweise erhalte ich ein NULL pointer... und GetLastError() bzw. WSAGetLastError() sagen mir beide 10093... kann da aber nichts finden... whats wrong?
 
If no error occurs, this function returns a pointer to the hostent structure. If an error occurs, it returns a NULL pointer, and a specific error number can be retrieved by calling WSAGetLastError.
Da stehts doch. Wenn du einen int Return wert hast dann vergleich ihn doch mit jenen Konstanten:
The following table shows the possible error codes.
Error code Description
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND An authoritative answer host was not found.
WSATRY_AGAIN A nonauthoritative host was not found, or the server failure.
WSANO_RECOVERY A nonrecoverable error occurred.
WSANO_DATA A valid name exists, but no data record of the requested type exists.
WSAEINPROGRESS A blocking Winsock call is in progress, or the service provider is still processing a callback function.
WSAEFAULT The name parameter is not a valid part of the user address space.
WSAEINTR The socket was closed.
Code:
switch(errocode) {
  case WSANOTINITIALISED:
    // tu jenes
  break;
  case WSAENETDOWN:
    // tu dieses
  break:
 ...
}
 
danke, wenn ich trottel aufgepasst hätte, hätte ich bemerkt das ich den code an der falschen stelle meines programmes untergebracht habe, nähmlich da, wo ich das netzwerk noch nicht gestartet hab....

nun klappt das, aber wie bekomm ich aus der structur hostent, jez eine dotted ip?
sorry, irgendwie steh ich total aufm schlauch... :(
 
@ rook:

Ich programmier kein C++
und ich programmiere nichtmal WinAPI
aber ich kann Referenzen lesen :)

Das heisst das solltest du dir anlernen denn hier:
http://search.microsoft.com/gomsuri...m/library/en-us/winsock/winsock/hostent_2.asp

steht es ziemlich klar eigentlich.
h_addr_list
Null-terminated list of addresses for the host. Addresses are returned in network byte order. The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.

<--
 
Zurück