t_new (void)
{
    int i = 0, j = 0;
    struct tcpclient *x = NULL;

    for (j = 0; j < MAXTCP; ++j)
        if (!t[j].active)
          break;

    if (j >= MAXTCP)
    {
        j = 0;
        for (i = 1; i < MAXTCP; ++i)
            if (taia_less (&t[i].start, &t[j].start))
                j = i;
        errno = error_timeout;
        if (t[j].state == 0)
          t_drop (j);
        else
          t_close (j);
    }

    x = t + j;
    taia_now (&x->start);

    x->tcp = socket_accept4 (tcp53, x->ip, &x->port);
    if (x->tcp == -1)
        return;
    if (x->port < 1024 && x->port != 53)
    {
        close (x->tcp);
        return;
    }
    if (!okclient (x->ip))
    {
        close (x->tcp);
        return;
    }
    if (ndelay_on (x->tcp) == -1)
    {
        close(x->tcp);
        return;
    } /* Linux bug */

    x->active = 1;
    ++tactive;
    x->state = 1;
    t_timeout (j);

    if (debug_level > 2)
        log_tcpopen (x->ip, x->port);
}
t_new (void)
{
    int i = 0, j = 0;
    struct tcpclient *x = NULL;

    for (j = 0; j < MAXTCP; ++j)
        if (!t[j].active)
          break;

    if (j >= MAXTCP)
    {
        j = 0;
        for (i = 1; i < MAXTCP; ++i)
            if (taia_less (&t[i].start, &t[j].start))
                j = i;
        errno = error_timeout;
        if (t[j].state == 0)
          t_drop (j);
        else
          t_close (j);
    }

    x = t + j;
    taia_now (&x->start);

    x->tcp = socket_accept4 (tcp53, x->ip, &x->port);
    if (x->tcp == -1)
        return;
    if (x->port < 1024 && x->port != 53)
    {
        close (x->tcp);
        return;
    }
    if (!okclient (x->ip))
    {
        close (x->tcp);
        return;
    }
    if (ndelay_on (x->tcp) == -1)
    {
        close(x->tcp);
        return;
    }  

    x->active = 1;
    ++tactive;
    x->state = 1;
    t_timeout (j);

    if (debug_level > 2)
        log_tcpopen (x->ip, x->port);
}