network programming - c++ gethostbyaddr with user input -


i writing c++ code telnet client. having problems getting host address user input.

struct in_addr peers;  cin>>peers;  peerserver = gethostbyaddr((const char*)peers,4,af_inet);  if (peerserver == null)     exit(0); 

i new c++, can suggest better way of getting host addr user input. in advance.

what you're looking gethostbyname, not gethostbyaddr. gethostbyaddr assumes you've got ip address.

char peers[256]; cin >> peers; struct hostent *ent = gethostbyname(peers); printf("%04x\n", *(int *)(ent->h_addr));

Comments

Popular posts from this blog

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -