headers = netdb.h

---

#include <stdlib.h>
#include <string.h>
#include <netdb.h>

static int socket_create_connect(char *host, ushort port) {
    struct hostent *he;
    struct sockaddr_in their_addr; /* connector's address information */
    if ((he = gethostbyname(host)) == NULL) {  /* get the host info */
        return -1;
    }
    int sockfd;
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
        return -2;
    }

    their_addr.sin_family = AF_INET;      /* host byte order */
    their_addr.sin_port = htons(port);    /* short, network byte order */
    their_addr.sin_addr = *((struct in_addr *) he->h_addr);
    bzero(&(their_addr.sin_zero), 8);     /* zero the rest of the struct */

    if (connect(sockfd, (struct sockaddr *) &their_addr, sizeof(struct sockaddr)) == -1) {
        return -3;
    }

    return sockfd;
}