Github user kavinderd commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/951#discussion_r81863084 --- Diff: src/backend/access/external/pxfutils.c --- @@ -133,3 +137,60 @@ static void process_request(ClientContext* client_context, char *uri) } + +/* + * Finds ip address of any available loopback interface(ipv4/ipv6). + * Returns ip for ipv4 addresses and [ip] for ipv6 addresses. + * + */ +char* get_loopback_ip_addr() { + struct ifaddrs *ifaddr, *ifa; + int family, s, n; + char host[NI_MAXHOST]; + char *loopback_addr; + + if (getifaddrs(&ifaddr) == -1) { + elog(ERROR, "Unable to obtain list of network interfaces."); + } + + for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { + if (ifa->ifa_addr == NULL) + continue; + + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET || family == AF_INET6) { + s = getnameinfo(ifa->ifa_addr, + (family == AF_INET) ? + sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6), host, NI_MAXHOST, + NULL, 0, NI_NUMERICHOST); + if (s != 0) { + elog(WARNING, "Unable to get name information for interface, getnameinfo() failed: %s\n", gai_strerror(s)); + } + + //get loopback interface + if (ifa->ifa_flags & IFF_LOOPBACK) { + if (family == AF_INET) + { + loopback_addr = palloc(strlen(host) + 1); + sprintf(loopback_addr, "%s", host); --- End diff -- Ok, makes sense. I overlooked the previous line
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---