Every DNS resolver, DHCP client, and syslog daemon on Linux ultimately calls socket(AF_INET, SOCK_DGRAM, 0) and manually fills sockaddr_in exactly as you do here, since getaddrinfo() is just a convenience wrapper around this same syscall sequence. Forgetting htons() on the port field is a real, extremely common bug — the value silently becomes garbage on little-endian machines instead of erroring.