1. Add command line parameters to the Project
2. Code
# Include "stdafx. H"
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
// Socket programming
# Include "winsock2.h"
# Pragma comment (Lib, "ws2_32.lib ")
# Include "ws2tcpip. H" // note location
Int main (INT argc, char ** argv)
{
// Wsastartup (it initiates use of ws2_32.dll by a process) must be called before any socket function is called)
Wsadata;
If (wsastartup (makeword (2, 2), & wsadata )! = 0 ){
Fprintf (stderr, "wsastartup failed: % d \ n", getlasterror ());
Exitprocess (-1 );
}
If (argc! = 2 ){
Fprintf (stderr, "Usage: % s hostname \ n ",
Argv [1]);
Exit (1 );
}
Struct addrinfo * answer, hint, * curr;
Memset (& hint, 0, sizeof (hint ));
Hint. ai_family = af_inet;
Hint. ai_socktype = sock_stream;
Int ret = getaddrinfo (argv [1], null, & hint, & answer );
If (Ret! = 0 ){
Fprintf (stderr, "getaddrinfo: % s \ n ",
Gai_strerror (RET ));
Exit (1 );
}
Char * dest_ip;
For (curr = answer; curr! = NULL; curr = curr-> ai_next ){
Dest_ip = inet_ntoa (struct sockaddr_in *) (curr-> ai_addr)-> sin_addr ));
Fprintf (stdout, "IP: % s \ n", dest_ip );
}
Freeaddrinfo (answer );
Wsacleanup ();
System ("pause ");
Exit (0 );
}
Result:
Add multiple IP addresses: