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

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -