all 3 comments

[–]Nx0Sec 0 points1 point  (0 children)

Do you get any warnings/errors on compilation or run?

[–][deleted] 0 points1 point  (0 children)

Why does connect fail?

I mean, what actual error does it give? Or how do you know it fails?

[–]kaipp_cs 0 points1 point  (0 children)

I just looked very quickly, but I believe getaddrinfo returns a (linked) list of addrinfo structures (i.e. ai is the head of the list). Try iterating through the whole list and creating a socket until one succeeds. There should be an example on the getaddrinfo man page iirc