pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/mDNSResponder-nss Build the mdns hostname resoluti...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/941b5f9f516e
branches:  trunk
changeset: 515898:941b5f9f516e
user:      drochner <drochner%pkgsrc.org@localhost>
date:      Mon Jul 10 17:35:30 2006 +0000

description:
Build the mdns hostname resolution nsswitch plugin which comes with
mDNSResponder.
(NetBSD-3.x only for now.)

diffstat:

 net/mDNSResponder-nss/DESCR            |    2 +
 net/mDNSResponder-nss/Makefile         |   33 ++
 net/mDNSResponder-nss/PLIST            |    5 +
 net/mDNSResponder-nss/distinfo         |    6 +
 net/mDNSResponder-nss/files/netbsd.c   |  143 +++++++++++
 net/mDNSResponder-nss/files/netbsd.h   |   11 +
 net/mDNSResponder-nss/patches/patch-aa |  411 +++++++++++++++++++++++++++++++++
 7 files changed, 611 insertions(+), 0 deletions(-)

diffs (truncated from 639 to 300 lines):

diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/DESCR       Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,2 @@
+This is a nsswitch plugin from Apple's mDNSResponder code, adapted for
+NetBSD's nsswitch.
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/Makefile    Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,33 @@
+# $NetBSD: Makefile,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $
+
+DISTNAME=      mDNSResponder-108
+PKGNAME=       mDNSResponder-nss-108
+CATEGORIES=    net
+MASTER_SITES=  http://darwinsource.opendarwin.org/tarballs/apsl/
+
+MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=      http://developer.apple.com/darwin/projects/bonjour/
+COMMENT=       Apple's mDNS responder - NetBSD nsswitch module
+
+# needs nsswitch
+ONLY_FOR_PLATFORM=     NetBSD-3.*-*
+
+post-extract:
+       ${CP} ${FILESDIR}/netbsd.c ${FILESDIR}/netbsd.h ${WRKSRC}/mDNSPosix
+
+do-build:
+       (cd ${WRKSRC}/mDNSPosix && ${CC} -c -fPIC -I. -I${LOCALBASE}/include \
+               nss_mdns.c netbsd.c)
+       (cd ${WRKSRC}/mDNSPosix && ${LD} -shared *.o -o nss_mdns.so.0 \
+               -L${LOCALBASE}/lib -Wl,-R${LOCALBASE}/lib -ldns_sd)
+
+do-install:
+       ${INSTALL_DATA} ${WRKSRC}/mDNSPosix/nss_mdns.so.0 ${PREFIX}/lib
+       ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/nss_mdns
+       ${INSTALL_DATA} ${WRKSRC}/mDNSPosix/nss_mdns.conf \
+               ${PREFIX}/share/examples/nss_mdns
+       ${INSTALL_MAN} ${WRKSRC}/mDNSPosix/nss_mdns.conf.5 ${PREFIX}/man/man5
+
+.include "../../net/mDNSResponder/buildlink3.mk"
+.include "../../mk/pthread.buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/PLIST       Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,5 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $
+lib/nss_mdns.so.0
+man/man5/nss_mdns.conf.5
+share/examples/nss_mdns/nss_mdns.conf
+@dirrm share/examples/nss_mdns
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/distinfo
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/distinfo    Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,6 @@
+$NetBSD: distinfo,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $
+
+SHA1 (mDNSResponder-108.tar.gz) = d51509077be75ec8ba49c805fef701c3370428fc
+RMD160 (mDNSResponder-108.tar.gz) = 3a1961f3267bcf009b52c8d8ce234ee6045aeed2
+Size (mDNSResponder-108.tar.gz) = 1362840 bytes
+SHA1 (patch-aa) = 17dc96e6671c974df086d1cb9143163b22309fd7
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/files/netbsd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/files/netbsd.c      Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,143 @@
+/* $NetBSD: netbsd.c,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $ */
+
+#include <sys/param.h>
+#include <nsswitch.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+
+#include "netbsd.h"
+typedef enum nss_status NSS_STATUS;
+
+extern NSS_STATUS _nss_mdns_gethostbyname2_r(const char *,
+       int, struct hostent *, char *, size_t, int *, int *);
+static int netbsd_gethostbyname(void *, void *, va_list);
+static int netbsd_getaddrinfo(void *, void *, va_list);
+extern NSS_STATUS _nss_mdns_gethostbyaddr_r(const void *, socklen_t,
+       int, struct hostent *, char *, size_t, int *, int *);
+static int netbsd_gethostbyaddr(void *, void *, va_list);
+
+static int nss2netbsderr[] = {
+       NS_SUCCESS, NS_NOTFOUND, NS_UNAVAIL, NS_TRYAGAIN, NS_RETURN
+};
+
+static struct hostent host;
+static char hostbuf[8*1024];
+
+static ns_mtab methods[] = {
+       { NSDB_HOSTS, "gethostbyname", netbsd_gethostbyname, 0 },
+       { NSDB_HOSTS, "getaddrinfo", netbsd_getaddrinfo, 0 },
+       { NSDB_HOSTS, "gethostbyaddr", netbsd_gethostbyaddr, 0 },
+};
+
+static int
+netbsd_gethostbyname(void *rv, void *cb_data, va_list ap)
+{
+       NSS_STATUS s;
+       int err, herr;
+       const char *name = va_arg(ap, char *);
+       size_t namlen = va_arg(ap, size_t);
+       int af = va_arg(ap, int);
+
+       s = _nss_mdns_gethostbyname2_r(name, af, &host,
+               hostbuf, sizeof(hostbuf), &err, &herr);
+
+       if (s == NSS_STATUS_SUCCESS)
+               *(struct hostent **)rv = &host;
+       else {
+               h_errno = HOST_NOT_FOUND;
+               *(struct hostent **)rv = 0;
+       }
+       return nss2netbsderr[s];
+}
+
+static void
+aiforaf(const char *name, int af, struct addrinfo *pai, struct addrinfo **aip)
+{
+       NSS_STATUS s;
+       int err, herr;
+       char **addrp;
+       char addrstr[INET6_ADDRSTRLEN];
+       struct addrinfo hints, *res0, *res;
+
+       s = _nss_mdns_gethostbyname2_r(name, af, &host,
+               hostbuf, sizeof(hostbuf), &err, &herr);
+       if (s != NSS_STATUS_SUCCESS)
+               return;
+
+       for (addrp = host.h_addr_list; *addrp; addrp++) {
+               /* XXX this sucks, but get_ai is not public */
+               if (!inet_ntop(host.h_addrtype, *addrp,
+                              addrstr, sizeof(addrstr)))
+                       continue;
+               hints = *pai;
+               hints.ai_flags = AI_NUMERICHOST;
+               hints.ai_family = af;
+               if (getaddrinfo(addrstr, NULL, &hints, &res0))
+                       continue;
+               for (res = res0; res; res = res->ai_next)
+                       res->ai_flags = pai->ai_flags;
+
+               (*aip)->ai_next = res0;
+               while ((*aip)->ai_next)
+                       *aip = (*aip)->ai_next;
+       }
+}
+
+static int
+netbsd_getaddrinfo(void *rv, void *cb_data, va_list ap)
+{
+       struct addrinfo sentinel, *cur;
+       const char *name = va_arg(ap, char *);
+       struct addrinfo *ai = va_arg(ap, struct addrinfo *);
+
+       memset(&sentinel, 0, sizeof(sentinel));
+       cur = &sentinel;
+
+       if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET6))
+               aiforaf(name, AF_INET6, ai, &cur);
+       if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET))
+               aiforaf(name, AF_INET, ai, &cur);
+
+       if (!sentinel.ai_next) {
+               h_errno = HOST_NOT_FOUND;
+               return NS_NOTFOUND;
+       }
+       *((struct addrinfo **)rv) = sentinel.ai_next;
+       return NS_SUCCESS;
+}
+
+static int
+netbsd_gethostbyaddr(void *rv, void *cb_data, va_list ap)
+{
+       int err, herr;
+       NSS_STATUS s;
+       const unsigned char *addr = va_arg(ap, unsigned char *);
+       socklen_t addrlen = va_arg(ap, socklen_t);
+       int af = va_arg(ap, int);
+
+       s = _nss_mdns_gethostbyaddr_r(addr, addrlen, af, &host,
+               hostbuf, sizeof(hostbuf), &err, &herr);
+
+       if (s == NSS_STATUS_SUCCESS)
+               *(struct hostent **)rv = &host;
+       else {
+               h_errno = HOST_NOT_FOUND;
+               *(struct hostent **)rv = 0;
+       }
+       return nss2netbsderr[s];
+}
+
+ns_mtab *
+nss_module_register(const char *source, unsigned int *mtabsize,
+                   nss_module_unregister_fn *unreg)
+{
+
+       *mtabsize = sizeof(methods)/sizeof(methods[0]);
+       *unreg = NULL;
+       return (methods);
+}
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/files/netbsd.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/files/netbsd.h      Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,11 @@
+/* $NetBSD: netbsd.h,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $ */
+
+#include <nsswitch.h>
+
+enum nss_status {
+        NSS_STATUS_SUCCESS,
+       NSS_STATUS_NOTFOUND,
+       NSS_STATUS_UNAVAIL,
+       NSS_STATUS_TRYAGAIN,
+       NSS_STATUS_RETURN
+};
diff -r fc8ee652db5c -r 941b5f9f516e net/mDNSResponder-nss/patches/patch-aa
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/mDNSResponder-nss/patches/patch-aa    Mon Jul 10 17:35:30 2006 +0000
@@ -0,0 +1,411 @@
+$NetBSD: patch-aa,v 1.1.1.1 2006/07/10 17:35:30 drochner Exp $
+
+--- mDNSPosix/nss_mdns.c.orig  2006-07-10 13:43:18.000000000 +0200
++++ mDNSPosix/nss_mdns.c
+@@ -96,7 +96,7 @@ b. in the case of services:
+ /*
+       Count the number of dots in a name string.
+  */
+-int
++static int
+ count_dots (const char * name);
+ 
+ 
+@@ -107,7 +107,7 @@ count_dots (const char * name);
+               1 if name ends with ".local" or ".local."
+               0 otherwise
+  */
+-int
++static int
+ islocal (const char * name);
+ 
+ 
+@@ -126,7 +126,7 @@ islocal (const char * name);
+               Pointer to (first character of) output buffer,
+               or NULL on error.
+  */
+-char *
++static char *
+ format_reverse_addr (int af, const void * addr, int prefixlen, char * buf);
+ 
+ 
+@@ -145,7 +145,7 @@ format_reverse_addr (int af, const void 
+               Pointer to (first character of) output buffer,
+               or NULL on error.
+  */
+-char *
++static char *
+ format_reverse_addr_in (
+       const struct in_addr * addr,
+       int prefixlen,
+@@ -168,7 +168,7 @@ format_reverse_addr_in (
+               Pointer to (first character of) output buffer,
+               or NULL on error.
+  */
+-char *
++static char *
+ format_reverse_addr_in6 (
+       const struct in6_addr * addr,
+       int prefixlen,
+@@ -189,7 +189,7 @@ format_reverse_addr_in6 (
+               0 on failure (no match)
+               < 0 on error
+  */
+-int
++static int
+ cmp_dns_suffix (const char * name, const char * domain);
+ enum
+ {
+@@ -213,7 +213,7 @@ typedef int ns_class_t;
+               Appropriate AF code (from socket.h), or AF_UNSPEC if an appropriate
+               mapping couldn't be determined
+  */
+-int
++static int
+ rr_to_af (ns_type_t rrtype);
+ 
+ 
+@@ -227,7 +227,7 @@ rr_to_af (ns_type_t rrtype);
+               Appropriate RR code (from nameser.h), or ns_t_invalid if an appropriate
+               mapping couldn't be determined
+  */
+-ns_type_t



Home | Main Index | Thread Index | Old Index