int connection_init (connection_t *con, sock_t sock, const char *addr) { if (con) { memset (con, 0, sizeof (connection_t)); con->sock = sock; if (sock == SOCK_ERROR) return -1; if (addr) { char *ip; if (strncmp (addr, "::ffff:", 7) == 0) ip = strdup (addr+7); else ip = strdup (addr); if (accept_ip_address (ip)) { con->ip = ip; con->id = _next_connection_id(); return 0; } free (ip); } con->sock = SOCK_ERROR; } return -1; }
connection_t *connection_create (sock_t sock, sock_t serversock, char *ip) { connection_t *con; con = (connection_t *)calloc(1, sizeof(connection_t)); if (con) { con->sock = sock; con->serversock = serversock; con->con_time = time(NULL); con->id = _next_connection_id(); con->ip = ip; } return con; }
connection_t *create_connection(sock_t sock, sock_t serversock, char *ip) { connection_t *con; con = (connection_t *)malloc(sizeof(connection_t)); memset(con, 0, sizeof(connection_t)); con->sock = sock; con->serversock = serversock; con->con_time = time(NULL); con->id = _next_connection_id(); con->ip = ip; con->event_number = EVENT_NO_EVENT; con->event = NULL; return con; }