Posted to tcl by rmax at Wed Sep 26 16:49:41 GMT 2012view pretty

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
    struct addrinfo hints, *result;
    int err;

    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;

    err = getaddrinfo("localhost", "0", &hints, &result);
    printf("getaddrinfo returned: %d, %s\n", err,
           err ? gai_strerror(err) : "Success");

    return 0;
}