connect.c 718 Bytes
#include <stdlib.h>     /* for atoi() and exit() */
#include <errno.h>      /* for errno */

#include "socket.h"
#include "interface/class.h"
#include "interface/logger.h"


void
socketConnect(Sock this, const char * addr)
{
	inet_pton(AF_INET, addr, &((this->addr).sin_addr));
    (this->addr).sin_family = AF_INET;           /* Internet address family */
    (this->addr).sin_port   = htons(this->port); /* Local port */

	if (-1 == connect(this->handle, (struct sockaddr*) &(this->addr), sizeof(this->addr))) {
        loggerLog(this->log, LOGGER_CRIT,
                "error connection socket: %s - service terminated",
                strerror(errno));
        exit(EXIT_FAILURE);
    }
}

// vim: set ts=4 sw=4: