+
+/**
+ * inet_pton() replacement
+ */
+int vlc_inet_pton (int af, const char *src, void *dst)
+{
+#ifndef HAVE_INET_PTON
+ /* Windows Vista has inet_pton(), but not XP. */
+ /* We have a pretty good example of abstraction inversion here... */
+ struct addrinfo hints = {
+ .ai_family = af,
+ .ai_socktype = SOCK_DGRAM, /* make sure we have... */
+ .ai_protocol = IPPROTO_UDP, /* ...only one response */
+ .ai_flags = AI_NUMERICHOST,
+ }, *res;
+
+ if (getaddrinfo (src, NULL, &hints, &res))
+ return 0;
+
+ const void *data;
+ size_t len;
+
+ switch (af)
+ {
+ case AF_INET:
+ data = &((const struct sockaddr_in *)res->ai_addr)->sin_addr;
+ len = sizeof (struct in_addr);
+ break;
+#ifdef AF_INET6
+ case AF_INET6:
+ data = &((const struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
+ len = sizeof (struct in6_addr);
+ break;
+#endif
+ default:
+ freeaddrinfo (res);
+ return -1;
+ }
+ memcpy (dst, data, len);
+ freeaddrinfo (res);
+ return 1;
+#else /* HAVE_INET_PTON */
+ return inet_pton( af, src, dst );
+#endif /* HAVE_INET_PTON */
+}
+
+/**
+ * inet_ntop() replacement
+ */
+const char *vlc_inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
+{
+#ifndef HAVE_INET_NTOP
+ int ret = EAI_FAMILY;
+
+ switch (af)
+ {
+#ifdef AF_INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 addr;
+ memset (&addr, 0, sizeof(addr));
+ addr.sin6_family = AF_INET6;
+ addr.sin6_addr = *(struct in6_addr *)src;
+ ret = getnameinfo ((struct sockaddr *)&addr, sizeof (addr),
+ dst, cnt, NULL, 0, NI_NUMERICHOST);
+ }
+
+#endif
+ case AF_INET:
+ {
+ struct sockaddr_in addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr = *(struct in_addr *)src;
+ ret = getnameinfo ((struct sockaddr *)&addr, sizeof (addr),
+ dst, cnt, NULL, 0, NI_NUMERICHOST);
+ }
+ }
+ return (ret == 0) ? dst : NULL;
+#else /* HAVE_INET_NTOP */
+ return inet_ntop( af, src, dst, cnt );
+#endif /* HAVE_INET_NTOP */
+}
+