If getaddrinfo
is expecting a string you must convert port
(an int
) to one first. Here is one way:
char portStr[MAX_PORT_STR_LEN];
snprintf(portStr, MAX_PORT_STR_LEN, "%d", port);
Now you can send it to getaddrinfo
:
error = getaddrinfo(host, portStr, &hints, &res);