How can I know if a string
is the canonical name
or the IP address
?
Because if argv[1]
is the IP address
I do:
sscanf(argv[2],"%" SCNu16,&server_port);
inet_aton(argv[1],&server_address);
remote_address.sin_family = AF_INET;
remote_address.sin_port = htons(server_port);
remote_address.sin_addr = server_address;
And if argv[1] is the canonical name
I do:
h = gethostbyname(server);
indirizzo_remoto.sin_family = AF_INET;
indirizzo_remoto.sin_port = htons(porta_server);
indirizzo_remoto.sin_addr = XYZ;
Also, what do I have to have in place of XYZ
?
POSSIBLE SOLUTION:
struct in_addr indirizzo_server;
struct hostent *h;
h = gethostbyname(server);
inet_aton(h->h_addr_list[0],&indirizzo_server);
indirizzo_remoto.sin_family = AF_INET;
indirizzo_remoto.sin_port = htons(porta_server);
indirizzo_remoto.sin_addr = indirizzo_server;