Ejemplo n.º 1
0
Archivo: tcp.c Proyecto: dolfly/nmdb
/* Same as nmdb_add_tipc_server() but for TCP connections. */
int nmdb_add_tcp_server(nmdb_t *db, const char *addr, int port)
{
    int rv;
    struct hostent *he;
    struct in_addr ia;

    /* We try to resolve and then pass it to add_tcp_server_addr(). */
    rv = inet_pton(AF_INET, addr, &ia);
    if (rv <= 0) {
        he = gethostbyname(addr);
        if (he == NULL)
            return 0;

        ia.s_addr = *( (in_addr_t *) (he->h_addr_list[0]) );
    }

    return add_tcp_server_addr(db, &(ia.s_addr), port);
}
Ejemplo n.º 2
0
Archivo: tcp.c Proyecto: bigclean/moc
int moc_add_tcp_server(moc_t *evt, const char *addr, int port,
                       int nblock, void *tv)
{
    int rv;
    struct hostent *he;
    struct in_addr ia;

    /*
     * We try to resolve and then pass it to add_tcp_server_addr().
     */
    rv = inet_pton(AF_INET, addr, &ia);
    if (rv <= 0) {
        he = gethostbyname(addr);
        if (he == NULL)
            return 0;

        ia.s_addr = *( (in_addr_t *) (he->h_addr_list[0]) );
    }

    return add_tcp_server_addr(evt, &(ia.s_addr), port, nblock, (struct timeval*)tv);
}