--- sa.c 2001/08/12 13:44:10 1.2
+++ sa.c 2001/08/20 11:28:29 1.3
@@ -42,8 +42,34 @@
#include <sys/socket.h>
#include <arpa/inet.h>
+#include "config.h"
#include "sa.h"
+#if !defined(AF_LOCAL) && defined(AF_UNIX)
+#define AF_LOCAL AF_UNIX
+#endif
+
+#ifndef HAVE_INET_PTON
+#ifdef HAVE_INET_ATON
+static int inet_pton(int family, const char *strptr, void *addrptr)
+{
+ struct in_addr in_val;
+
+ if (family == AF_INET) {
+ if (inet_aton(strptr, &in_val)) {
+ memcpy(addrptr, &in_val, sizeof(struct in_addr));
+ return 1;
+ }
+ return 0;
+ }
+ errno = EAFNOSUPPORT;
+ return -1;
+}
+#else
+#error "neither inet_pton nor inet_aton available"
+#endif
+#endif
+
sa_t *sa_create(int sa_type, ...)
{
va_list ap;
@@ -52,7 +78,9 @@
socklen_t sl;
struct sockaddr *sa;
struct sockaddr_in sa4;
+#ifdef AF_INET6
struct sockaddr_in6 sa6;
+#endif
struct sockaddr_un sau;
struct hostent *he;
struct servent *se;
@@ -70,6 +98,7 @@
sa = NULL;
sl = 0;
if (sa_type == SA_UNIX) {
+#if defined(AF_LOCAL)
if ((cpPath = va_arg(ap, char *)) == NULL)
return NULL;
if ((nPath = strlen(cpPath)) >= (sizeof(sau.sun_path)-1))
@@ -79,6 +108,9 @@
memcpy(sau.sun_path, cpPath, nPath + 1);
sa = (struct sockaddr *)&sau;
sl = sizeof(sau);
+#else
+ return NULL;
+#endif
}
else if (sa_type == SA_IP) {
if ((cpProto = va_arg(ap, char *)) == NULL)
@@ -116,12 +148,14 @@
sa = (struct sockaddr *)&sa4;
sl = sizeof(sa4);
}
+#ifdef AF_INET6
else if (inet_pton(AF_INET6, cpHost, &sa6.sin6_addr.s6_addr) == 1) {
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(nPort);
sa = (struct sockaddr *)&sa6;
sl = sizeof(sa6);
}
+#endif
else if ((he = gethostbyname(cpHost)) != NULL) {
if (he->h_addrtype == AF_INET) {
sa4.sin_family = AF_INET;
@@ -130,6 +164,7 @@
sa = (struct sockaddr *)&sa4;
sl = sizeof(sa4);
}
+#ifdef AF_INET6
else if (he->h_addrtype == AF_INET6) {
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(nPort);
@@ -137,6 +172,7 @@
sa = (struct sockaddr *)&sa6;
sl = sizeof(sa6);
}
+#endif
}
}
else
|