struct sockaddr_in addr;

// Allow sockets across machines.
addr.sin_family = AF_INET;
// The port the server will be listening on.
addr.sin_port = htons(port);
// Clear this field; sin_zero is used for padding for the struct.
memset(&(addr.sin_zero), 0, 8);

// Lookup host IP address.
struct hostent *hp = gethostbyname(hostname);
if (hp == NULL) {
    fprintf(stderr, "unknown host %s\n", hostname);
    exit(1);
}

addr.sin_addr = *((struct in_addr *)hp->h_addr);