check_ip_tree(const int mode, const unsigned long ip)
{
    tcpr_tree_t *node, *finder;

    finder = new_tree();
    finder->family = AF_INET;
    finder->u.ip = ip;

    node = RB_FIND(tcpr_data_tree_s, &treeroot, finder);

    if (node == NULL && mode == DIR_UNKNOWN)
        errx(-1, "%s (%lu) is an unknown system... aborting.!\n"
             "Try a different auto mode (-n router|client|server)",
             get_addr2name4(ip, RESOLVE), ip);

    /* return node type if we found the node, else return the default (mode) */
    if (node != NULL) {
#ifdef DEBUG
        switch (node->type) {
        case DIR_SERVER:
            dbgx(1, "DIR_SERVER: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_CLIENT:
            dbgx(1, "DIR_CLIENT: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_UNKNOWN:
            dbgx(1, "DIR_UNKNOWN: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_ANY:
            dbgx(1, "DIR_ANY: %s", get_addr2name4(ip, RESOLVE));
            break;
        }
#endif

        switch (node->type) {
        case DIR_SERVER:
            safe_free(finder);
            return TCPR_DIR_S2C;
            break;
        case DIR_CLIENT:
            safe_free(finder);
            return TCPR_DIR_C2S;
            break;
        case DIR_UNKNOWN:
        case DIR_ANY:
            /* use our current mode to determine return code */
            goto return_unknown; 
        default:
            errx(-1, "Node for %s has invalid type: %d", get_addr2name4(ip, RESOLVE), node->type);
        }
    }
    
return_unknown:
    safe_free(finder);
    switch (mode) {
    case DIR_SERVER:
        return TCPR_DIR_S2C;
        break;
    case DIR_CLIENT:
        return TCPR_DIR_C2S;
        break;
    default:
        return -1;
    }
}
check_ip_tree(const int mode, const unsigned long ip)
{
    tcpr_tree_t *node, *finder;

    finder = new_tree();
    finder->family = AF_INET;
    finder->u.ip = ip;

    node = RB_FIND(tcpr_data_tree_s, &treeroot, finder);

    if (node == NULL && mode == DIR_UNKNOWN)
        errx(-1, "%s (%lu) is an unknown system... aborting.!\n"
             "Try a different auto mode (-n router|client|server)",
             get_addr2name4(ip, RESOLVE), ip);

     
    if (node != NULL) {
#ifdef DEBUG
        switch (node->type) {
        case DIR_SERVER:
            dbgx(1, "DIR_SERVER: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_CLIENT:
            dbgx(1, "DIR_CLIENT: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_UNKNOWN:
            dbgx(1, "DIR_UNKNOWN: %s", get_addr2name4(ip, RESOLVE));
            break;
        case DIR_ANY:
            dbgx(1, "DIR_ANY: %s", get_addr2name4(ip, RESOLVE));
            break;
        }
#endif

        switch (node->type) {
        case DIR_SERVER:
            safe_free(finder);
            return TCPR_DIR_S2C;
            break;
        case DIR_CLIENT:
            safe_free(finder);
            return TCPR_DIR_C2S;
            break;
        case DIR_UNKNOWN:
        case DIR_ANY:
             
            goto return_unknown; 
        default:
            errx(-1, "Node for %s has invalid type: %d", get_addr2name4(ip, RESOLVE), node->type);
        }
    }
    
return_unknown:
    safe_free(finder);
    switch (mode) {
    case DIR_SERVER:
        return TCPR_DIR_S2C;
        break;
    case DIR_CLIENT:
        return TCPR_DIR_C2S;
        break;
    default:
        return -1;
    }
}