static int connect_to_sdog(const char *addr, const char *port)

{

    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];

    int fd, ret;

    struct addrinfo hints, *res, *res0;



    if (!addr) {

        addr = SD_DEFAULT_ADDR;

        port = SD_DEFAULT_PORT;

    }



    memset(&hints, 0, sizeof(hints));

    hints.ai_socktype = SOCK_STREAM;



    ret = getaddrinfo(addr, port, &hints, &res0);

    if (ret) {

        error_report("unable to get address info %s, %s",

                     addr, strerror(errno));

        return -errno;

    }



    for (res = res0; res; res = res->ai_next) {

        ret = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),

                          sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);

        if (ret) {

            continue;

        }



        fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

        if (fd < 0) {

            continue;

        }



    reconnect:

        ret = connect(fd, res->ai_addr, res->ai_addrlen);

        if (ret < 0) {

            if (errno == EINTR) {

                goto reconnect;

            }


            break;

        }



        dprintf("connected to %s:%s\n", addr, port);

        goto success;

    }

    fd = -errno;

    error_report("failed connect to %s:%s", addr, port);

success:

    freeaddrinfo(res0);

    return fd;

}
static int connect_to_sdog(const char *addr, const char *port)

{

    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];

    int fd, ret;

    struct addrinfo hints, *res, *res0;



    if (!addr) {

        addr = SD_DEFAULT_ADDR;

        port = SD_DEFAULT_PORT;

    }



    memset(&hints, 0, sizeof(hints));

    hints.ai_socktype = SOCK_STREAM;



    ret = getaddrinfo(addr, port, &hints, &res0);

    if (ret) {

        error_report("unable to get address info %s, %s",

                     addr, strerror(errno));

        return -errno;

    }



    for (res = res0; res; res = res->ai_next) {

        ret = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),

                          sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);

        if (ret) {

            continue;

        }



        fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

        if (fd < 0) {

            continue;

        }



    reconnect:

        ret = connect(fd, res->ai_addr, res->ai_addrlen);

        if (ret < 0) {

            if (errno == EINTR) {

                goto reconnect;

            }


            break;

        }



        dprintf("connected to %s:%s\n", addr, port);

        goto success;

    }

    fd = -errno;

    error_report("failed connect to %s:%s", addr, port);

success:

    freeaddrinfo(res0);

    return fd;

}
static int FUNC_0(const char *VAR_0, const char *VAR_1)

{

    char VAR_2[NI_MAXHOST], sbuf[NI_MAXSERV];

    int VAR_3, VAR_4;

    struct addrinfo VAR_5, *VAR_6, *VAR_7;



    if (!VAR_0) {

        VAR_0 = SD_DEFAULT_ADDR;

        VAR_1 = SD_DEFAULT_PORT;

    }



    memset(&VAR_5, 0, sizeof(VAR_5));

    VAR_5.ai_socktype = SOCK_STREAM;



    VAR_4 = getaddrinfo(VAR_0, VAR_1, &VAR_5, &VAR_7);

    if (VAR_4) {

        error_report("unable to get address info %s, %s",

                     VAR_0, strerror(errno));

        return -errno;

    }



    for (VAR_6 = VAR_7; VAR_6; VAR_6 = VAR_6->ai_next) {

        VAR_4 = getnameinfo(VAR_6->ai_addr, VAR_6->ai_addrlen, VAR_2, sizeof(VAR_2),

                          sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);

        if (VAR_4) {

            continue;

        }



        VAR_3 = socket(VAR_6->ai_family, VAR_6->ai_socktype, VAR_6->ai_protocol);

        if (VAR_3 < 0) {

            continue;

        }



    reconnect:

        VAR_4 = connect(VAR_3, VAR_6->ai_addr, VAR_6->ai_addrlen);

        if (VAR_4 < 0) {

            if (errno == EINTR) {

                goto reconnect;

            }


            break;

        }



        dprintf("connected to %s:%s\n", VAR_0, VAR_1);

        goto success;

    }

    VAR_3 = -errno;

    error_report("failed connect to %s:%s", VAR_0, VAR_1);

success:

    freeaddrinfo(VAR_7);

    return VAR_3;

}
static int FUNC_0(const char *VAR_0, const char *VAR_1)
{ char VAR_2[NI_MAXHOST], sbuf[NI_MAXSERV]; int VAR_3, VAR_4; struct addrinfo VAR_5, *VAR_6, *VAR_7; if (!VAR_0) { VAR_0 = SD_DEFAULT_ADDR; VAR_1 = SD_DEFAULT_PORT; } memset(&VAR_5, 0, sizeof(VAR_5)); VAR_5.ai_socktype = SOCK_STREAM; VAR_4 = getaddrinfo(VAR_0, VAR_1, &VAR_5, &VAR_7); if (VAR_4) { error_report("unable to get address info %s, %s",
VAR_0, strerror(errno)); return -errno; } for (VAR_6 = VAR_7; VAR_6; VAR_6 = VAR_6->ai_next) { VAR_4 = getnameinfo(VAR_6->ai_addr, VAR_6->ai_addrlen, VAR_2, sizeof(VAR_2),
sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV); if (VAR_4) { continue; } VAR_3 = socket(VAR_6->ai_family, VAR_6->ai_socktype, VAR_6->ai_protocol); if (VAR_3 < 0) { continue; } reconnect:
VAR_4 = connect(VAR_3, VAR_6->ai_addr, VAR_6->ai_addrlen); if (VAR_4 < 0) { if (errno == EINTR) { goto reconnect; } break; } dprintf("connected to %s:%s\n", VAR_0, VAR_1); goto success; } VAR_3 = -errno; error_report("failed connect to %s:%s", VAR_0, VAR_1); success:
freeaddrinfo(VAR_7); return VAR_3; }