I am very confused.
I use getaddrinfo to get the address information for this web site.
In this case, I used www.cmu.edu .
My code worked for a while, but then it stopped.
The odd part is the fact that I clearly come up with an error, but when the error code is printed, it says "success."
Here are the relevant bits of code:
struct addrinfo *res = NULL; struct addrinfo hint; memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_DGRAM; hint.ai_flags = 0; hint.ai_protocol = 17; if (getaddrinfo(host, portNo, &hint, &res)) { perror("getaddrinfo"); return 0; }
Host and portNo are strings containing the host (in this case, " www.cmu.edu ") and the port (in this case, "80").
They definitely contain the right thing, no extra spaces or anything like that.
Edit: Thanks everyone! I at least have a corresponding error message, although I still don't know why everything stopped working. Error message:
Servname not supported for ai_socktype
I examined the possible causes of this error, and I did not find anything. As I said, this code worked earlier and stopped without changing anything. I realized that this is the port number that I used, but I changed it several times and did not change anything.
Any insight? I am not tied to a port number or anything other than a host. I'm just trying to make it work.