Server 0.0.1
HTTP/REST server implementation

src/socket/connect.c

Go to the documentation of this file.
00001 
00023 #include <stdlib.h>     // for atoi() and exit()
00024 #include <errno.h>      // for errno
00025 
00026 #include "socket.h"
00027 #include "class.h"
00028 #include "logger.h"
00029 
00030 
00031 void
00032 socketConnect(Sock this, const char * addr, char (*remoteAddr)[16])
00033 {
00034         inet_pton(AF_INET, addr, &((this->addr).sin_addr));
00035     (this->addr).sin_family = AF_INET;           // Internet address family
00036     (this->addr).sin_port   = htons(this->port); // Local port
00037 
00038         if (-1 == connect(
00039                                 this->handle,
00040                                 (struct sockaddr*) &(this->addr),
00041                                 sizeof(this->addr)))
00042         {
00043         loggerLog(this->log, LOGGER_CRIT,
00044                 "error connection socket: %s - service terminated",
00045                 strerror(errno));
00046         exit(EXIT_FAILURE);
00047     } else {
00048                 strcpy(*remoteAddr, inet_ntoa((this->addr).sin_addr));
00049 
00050         loggerLog(this->log, LOGGER_INFO,
00051                                 "handling connection %s\n", inet_ntoa((this->addr).sin_addr));
00052     }
00053 }
00054 
00055 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines