SF.net SVN: gar:[24964] csw/mgar/pkg
dmichelsen at users.sourceforge.net
dmichelsen at users.sourceforge.net
Wed May 13 13:49:26 CEST 2015
Revision: 24964
http://sourceforge.net/p/gar/code/24964
Author: dmichelsen
Date: 2015-05-13 11:49:26 +0000 (Wed, 13 May 2015)
Log Message:
-----------
libasr: Initial commit from http://lists.opencsw.org/pipermail/users/2015-May/010057.html
Added Paths:
-----------
csw/mgar/pkg/libasr/
csw/mgar/pkg/libasr/Makefile
csw/mgar/pkg/libasr/branches/
csw/mgar/pkg/libasr/tags/
csw/mgar/pkg/libasr/trunk/
csw/mgar/pkg/libasr/trunk/Makefile
csw/mgar/pkg/libasr/trunk/checksums
csw/mgar/pkg/libasr/trunk/files/
csw/mgar/pkg/libasr/trunk/files/0001-add-openbsd-compat-getifaddrs.c.patch
csw/mgar/pkg/libasr/trunk/files/0002-fix-possible-MAX-redefinition.patch
csw/mgar/pkg/libasr/trunk/files/openbsd-compat/
csw/mgar/pkg/libasr/trunk/files/openbsd-compat/getifaddrs.c
csw/mgar/pkg/libasr/trunk/files/openbsd-compat/ifaddrs.h
Added: csw/mgar/pkg/libasr/Makefile
===================================================================
--- csw/mgar/pkg/libasr/Makefile (rev 0)
+++ csw/mgar/pkg/libasr/Makefile 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,2 @@
+%:
+ $(MAKE) -C trunk $*
Index: csw/mgar/pkg/libasr/trunk
===================================================================
--- csw/mgar/pkg/libasr/trunk 2015-05-11 17:27:21 UTC (rev 24963)
+++ csw/mgar/pkg/libasr/trunk 2015-05-13 11:49:26 UTC (rev 24964)
Property changes on: csw/mgar/pkg/libasr/trunk
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
+work
Added: csw/mgar/pkg/libasr/trunk/Makefile
===================================================================
--- csw/mgar/pkg/libasr/trunk/Makefile (rev 0)
+++ csw/mgar/pkg/libasr/trunk/Makefile 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,59 @@
+# $Id$
+# TODO (release-critical prefixed with !, non release-critical with *)
+#
+NAME = libasr
+VERSION = 201505061057
+GARTYPE = v2
+
+DESCRIPTION = libasr is a free, simple and portable asynchronous resolver library.
+define BLURB
+ libasr is a free, simple and portable asynchronous resolver library.
+
+ It allows to run dns queries and perform hostname resolutions in a fully asynchronous fashion. The implementation is thread-less, fork-less, and does not make use of signals or other "tricks" that might get in the developer's way. The API was initially developped for the OpenBSD operating system, where it is natively supported.
+
+ This library is intended to bring this interface to other systems. It is originally provided as a support library for the portable version of the OpenSMTPD daemon, but it can be used in any other contexts. It is known to work on the following systems:
+
+ * Linux
+ * FreeBSD
+ * NetBSD
+ * DragonFly
+ * MacOSX
+
+ The primary source of information about libasr is the github repository.
+endef
+
+MASTER_SITES = http://www.opensmtpd.org/archives/
+DISTFILES = $(DISTNAME).tar.gz
+
+ifneq ($(GAROSREL),11)
+PATCHFILES += 0001-add-openbsd-compat-getifaddrs.c.patch
+endif
+PATCHFILES += 0002-fix-possible-MAX-redefinition.patch
+
+GARCOMPILER = GNU
+
+PACKAGES += CSWlibasr
+CATALOGNAME_CSWlibasr = libasr
+PKGFILES_CSWlibasr += $(call baseisadirs,$(libdir),libasr\.so(\.\d+)*)
+SPKG_DESC_CSWlibasr += $(DESCRIPTION), libasr.so
+
+PACKAGES += CSWlibasr-dev
+CATALOGNAME_CSWlibasr-dev = libasr_dev
+SPKG_DESC_CSWlibasr-dev += $(DESCRIPTION), development files
+RUNTIME_DEP_PKGS_CSWlibasr-dev += CSWlibasr
+
+CONFIGURE_ARGS = $(DIRPATHS)
+CONFIGURE_ARGS += --with-mantype=man
+
+include gar/category.mk
+
+ifneq ($(GAROSREL),11)
+# ifaddrs.h taken from https://java.net/projects/solaris/sources/on-src/content/usr/src/head/ifaddrs.h?raw=true
+# getifaddrs.c taken from https://java.net/projects/solaris/sources/on-src/content/usr/src/lib/libsocket/inet/getifaddrs.c?raw=true
+# libsocket_priv.h is a gruik hack
+pre-build-modulated:
+ cp $(FILEDIR)/openbsd-compat/ifaddrs.h $(WORKSRC)/openbsd-compat/
+ cp $(FILEDIR)/openbsd-compat/getifaddrs.c $(WORKSRC)/openbsd-compat/
+ cp $(FILEDIR)/openbsd-compat/libsocket_priv.h $(WORKSRC)/openbsd-compat/
+ @$(MAKECOOKIE)
+endif
Property changes on: csw/mgar/pkg/libasr/trunk/Makefile
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: csw/mgar/pkg/libasr/trunk/checksums
===================================================================
--- csw/mgar/pkg/libasr/trunk/checksums (rev 0)
+++ csw/mgar/pkg/libasr/trunk/checksums 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1 @@
+2a4b768b54892465570ef7488e56b737 libasr-201505061057.tar.gz
Added: csw/mgar/pkg/libasr/trunk/files/0001-add-openbsd-compat-getifaddrs.c.patch
===================================================================
--- csw/mgar/pkg/libasr/trunk/files/0001-add-openbsd-compat-getifaddrs.c.patch (rev 0)
+++ csw/mgar/pkg/libasr/trunk/files/0001-add-openbsd-compat-getifaddrs.c.patch 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,24 @@
+From cf1d038c260ca6fd161174d6c5c42aaee90b1532 Mon Sep 17 00:00:00 2001
+From: Freddy DISSAUX <dsx at bsdsx.fr>
+Date: Thu, 7 May 2015 09:53:12 +0200
+Subject: [PATCH] add openbsd-compat/getifaddrs.c
+
+---
+ src/Makefile.am | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 286d382..7121b0b 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -11,6 +11,7 @@ libasr_la_SOURCES += $(top_srcdir)/openbsd-compat/strlcat.c
+ libasr_la_SOURCES += $(top_srcdir)/openbsd-compat/strlcpy.c
+ libasr_la_SOURCES += $(top_srcdir)/openbsd-compat/strsep.c
+ libasr_la_SOURCES += $(top_srcdir)/openbsd-compat/strtonum.c
++libasr_la_SOURCES += $(top_srcdir)/openbsd-compat/getifaddrs.c
+
+ include_HEADERS = asr.h
+
+--
+2.3.1
+
Added: csw/mgar/pkg/libasr/trunk/files/0002-fix-possible-MAX-redefinition.patch
===================================================================
--- csw/mgar/pkg/libasr/trunk/files/0002-fix-possible-MAX-redefinition.patch (rev 0)
+++ csw/mgar/pkg/libasr/trunk/files/0002-fix-possible-MAX-redefinition.patch 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,44 @@
+From 104a97a81ae81b29ae5796f9d1e48463b6305635 Mon Sep 17 00:00:00 2001
+From: Freddy DISSAUX <dsx at bsdsx.fr>
+Date: Fri, 8 May 2015 11:01:26 +0200
+Subject: [PATCH] fix possible MAX redefinition
+
+---
+ src/gethostnamadr_async.c | 4 ++++
+ src/getnetnamadr_async.c | 2 ++
+ 2 files changed, 6 insertions(+)
+
+diff --git a/src/gethostnamadr_async.c b/src/gethostnamadr_async.c
+index 2d6ecb7..5d34956 100644
+--- a/src/gethostnamadr_async.c
++++ b/src/gethostnamadr_async.c
+@@ -40,8 +40,12 @@
+
+ #include "asr_private.h"
+
++#ifndef MAXALIASES
+ #define MAXALIASES 35
++#endif
++#ifndef MAXADDRS
+ #define MAXADDRS 35
++#endif
+
+ struct hostent_ext {
+ struct hostent h;
+diff --git a/src/getnetnamadr_async.c b/src/getnetnamadr_async.c
+index ec14262..cc37ef0 100644
+--- a/src/getnetnamadr_async.c
++++ b/src/getnetnamadr_async.c
+@@ -33,7 +33,9 @@
+
+ #include "asr_private.h"
+
++#ifndef MAXALIASES
+ #define MAXALIASES 16
++#endif
+
+ struct netent_ext {
+ struct netent n;
+--
+2.3.1
+
Added: csw/mgar/pkg/libasr/trunk/files/openbsd-compat/getifaddrs.c
===================================================================
--- csw/mgar/pkg/libasr/trunk/files/openbsd-compat/getifaddrs.c (rev 0)
+++ csw/mgar/pkg/libasr/trunk/files/openbsd-compat/getifaddrs.c 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,272 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include <netdb.h>
+#include <nss_dbdefs.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/sockio.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <libsocket_priv.h>
+
+/*
+ * Create a linked list of `struct ifaddrs' structures, one for each
+ * address that is UP. If successful, store the list in *ifap and
+ * return 0. On errors, return -1 and set `errno'.
+ *
+ * The storage returned in *ifap is allocated dynamically and can
+ * only be properly freed by passing it to `freeifaddrs'.
+ */
+int
+getifaddrs(struct ifaddrs **ifap)
+{
+ int err;
+ char *cp;
+ struct ifaddrs *curr;
+
+ if (ifap == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ *ifap = NULL;
+ err = getallifaddrs(AF_UNSPEC, ifap, LIFC_ENABLED);
+ if (err == 0) {
+ for (curr = *ifap; curr != NULL; curr = curr->ifa_next) {
+ if ((cp = strchr(curr->ifa_name, ':')) != NULL)
+ *cp = '\0';
+ }
+ }
+ return (err);
+}
+
+void
+freeifaddrs(struct ifaddrs *ifa)
+{
+ struct ifaddrs *curr;
+
+ while (ifa != NULL) {
+ curr = ifa;
+ ifa = ifa->ifa_next;
+ free(curr->ifa_name);
+ free(curr->ifa_addr);
+ free(curr->ifa_netmask);
+ free(curr->ifa_dstaddr);
+ free(curr);
+ }
+}
+
+/*
+ * Returns all addresses configured on the system. If flags contain
+ * LIFC_ENABLED, only the addresses that are UP are returned.
+ * Address list that is returned by this function must be freed
+ * using freeifaddrs().
+ */
+int
+getallifaddrs(sa_family_t af, struct ifaddrs **ifap, int64_t flags)
+{
+ struct lifreq *buf = NULL;
+ struct lifreq *lifrp;
+ struct lifreq lifrl;
+ int ret;
+ int s, n, numifs;
+ struct ifaddrs *curr, *prev;
+ sa_family_t lifr_af;
+ int sock4;
+ int sock6;
+ int err;
+
+ if ((sock4 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ return (-1);
+ if ((sock6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ err = errno;
+ close(sock4);
+ errno = err;
+ return (-1);
+ }
+
+retry:
+ /* Get all interfaces from SIOCGLIFCONF */
+ ret = getallifs(sock4, af, &buf, &numifs, (flags & ~LIFC_ENABLED));
+ if (ret != 0)
+ goto fail;
+
+ /*
+ * Loop through the interfaces obtained from SIOCGLIFCOMF
+ * and retrieve the addresses, netmask and flags.
+ */
+ prev = NULL;
+ lifrp = buf;
+ *ifap = NULL;
+ for (n = 0; n < numifs; n++, lifrp++) {
+
+ /* Prepare for the ioctl call */
+ (void) strncpy(lifrl.lifr_name, lifrp->lifr_name,
+ sizeof (lifrl.lifr_name));
+ lifr_af = lifrp->lifr_addr.ss_family;
+ if (af != AF_UNSPEC && lifr_af != af)
+ continue;
+
+ s = (lifr_af == AF_INET ? sock4 : sock6);
+
+ if (ioctl(s, SIOCGLIFFLAGS, (caddr_t)&lifrl) < 0)
+ goto fail;
+ if ((flags & LIFC_ENABLED) && !(lifrl.lifr_flags & IFF_UP))
+ continue;
+
+ /*
+ * Allocate the current list node. Each node contains data
+ * for one ifaddrs structure.
+ */
+ curr = calloc(1, sizeof (struct ifaddrs));
+ if (curr == NULL)
+ goto fail;
+
+ if (prev != NULL) {
+ prev->ifa_next = curr;
+ } else {
+ /* First node in the linked list */
+ *ifap = curr;
+ }
+ prev = curr;
+
+ curr->ifa_flags = lifrl.lifr_flags;
+ if ((curr->ifa_name = strdup(lifrp->lifr_name)) == NULL)
+ goto fail;
+
+ curr->ifa_addr = malloc(sizeof (struct sockaddr_storage));
+ if (curr->ifa_addr == NULL)
+ goto fail;
+ (void) memcpy(curr->ifa_addr, &lifrp->lifr_addr,
+ sizeof (struct sockaddr_storage));
+
+ /* Get the netmask */
+ if (ioctl(s, SIOCGLIFNETMASK, (caddr_t)&lifrl) < 0)
+ goto fail;
+ curr->ifa_netmask = malloc(sizeof (struct sockaddr_storage));
+ if (curr->ifa_netmask == NULL)
+ goto fail;
+ (void) memcpy(curr->ifa_netmask, &lifrl.lifr_addr,
+ sizeof (struct sockaddr_storage));
+
+ /* Get the destination for a pt-pt interface */
+ if (curr->ifa_flags & IFF_POINTOPOINT) {
+ if (ioctl(s, SIOCGLIFDSTADDR, (caddr_t)&lifrl) < 0)
+ goto fail;
+ curr->ifa_dstaddr = malloc(
+ sizeof (struct sockaddr_storage));
+ if (curr->ifa_dstaddr == NULL)
+ goto fail;
+ (void) memcpy(curr->ifa_dstaddr, &lifrl.lifr_addr,
+ sizeof (struct sockaddr_storage));
+ } else if (curr->ifa_flags & IFF_BROADCAST) {
+ if (ioctl(s, SIOCGLIFBRDADDR, (caddr_t)&lifrl) < 0)
+ goto fail;
+ curr->ifa_broadaddr = malloc(
+ sizeof (struct sockaddr_storage));
+ if (curr->ifa_broadaddr == NULL)
+ goto fail;
+ (void) memcpy(curr->ifa_broadaddr, &lifrl.lifr_addr,
+ sizeof (struct sockaddr_storage));
+ }
+
+ }
+ free(buf);
+ close(sock4);
+ close(sock6);
+ return (0);
+fail:
+ err = errno;
+ free(buf);
+ freeifaddrs(*ifap);
+ *ifap = NULL;
+ if (err == ENXIO)
+ goto retry;
+ close(sock4);
+ close(sock6);
+ errno = err;
+ return (-1);
+}
+
+/*
+ * Do a SIOCGLIFCONF and store all the interfaces in `buf'.
+ */
+int
+getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs,
+ int64_t lifc_flags)
+{
+ struct lifnum lifn;
+ struct lifconf lifc;
+ size_t bufsize;
+ char *tmp;
+ caddr_t *buf = (caddr_t *)lifr;
+
+ lifn.lifn_family = af;
+ lifn.lifn_flags = lifc_flags;
+
+ *buf = NULL;
+retry:
+ if (ioctl(s, SIOCGLIFNUM, &lifn) < 0)
+ goto fail;
+
+ /*
+ * When calculating the buffer size needed, add a small number
+ * of interfaces to those we counted. We do this to capture
+ * the interface status of potential interfaces which may have
+ * been plumbed between the SIOCGLIFNUM and the SIOCGLIFCONF.
+ */
+ bufsize = (lifn.lifn_count + 4) * sizeof (struct lifreq);
+
+ if ((tmp = realloc(*buf, bufsize)) == NULL)
+ goto fail;
+
+ *buf = tmp;
+ lifc.lifc_family = af;
+ lifc.lifc_flags = lifc_flags;
+ lifc.lifc_len = bufsize;
+ lifc.lifc_buf = *buf;
+ if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
+ goto fail;
+
+ *numifs = lifc.lifc_len / sizeof (struct lifreq);
+ if (*numifs >= (lifn.lifn_count + 4)) {
+ /*
+ * If every entry was filled, there are probably
+ * more interfaces than (lifn.lifn_count + 4).
+ * Redo the ioctls SIOCGLIFNUM and SIOCGLIFCONF to
+ * get all the interfaces.
+ */
+ goto retry;
+ }
+ return (0);
+fail:
+ free(*buf);
+ *buf = NULL;
+ return (-1);
+}
Added: csw/mgar/pkg/libasr/trunk/files/openbsd-compat/ifaddrs.h
===================================================================
--- csw/mgar/pkg/libasr/trunk/files/openbsd-compat/ifaddrs.h (rev 0)
+++ csw/mgar/pkg/libasr/trunk/files/openbsd-compat/ifaddrs.h 2015-05-13 11:49:26 UTC (rev 24964)
@@ -0,0 +1,86 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+#ifndef _IFADDRS_H
+#define _IFADDRS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+
+/*
+ * The `getifaddrs' function generates a linked list of these structures.
+ * Each element of the list describes one network interface.
+ */
+#if defined(_INT64_TYPE)
+struct ifaddrs {
+ struct ifaddrs *ifa_next; /* Pointer to the next structure. */
+ char *ifa_name; /* Name of this network interface. */
+ uint64_t ifa_flags; /* Flags as from SIOCGLIFFLAGS ioctl. */
+ struct sockaddr *ifa_addr; /* Network address of this interface. */
+ struct sockaddr *ifa_netmask; /* Netmask of this interface. */
+ union {
+ /*
+ * At most one of the following two is valid. If the
+ * IFF_BROADCAST bit is set in `ifa_flags', then
+ * `ifa_broadaddr' is valid. If the IFF_POINTOPOINT bit is
+ * set, then `ifa_dstaddr' is valid. It is never the case that
+ * both these bits are set at once.
+ */
+ struct sockaddr *ifu_broadaddr;
+ struct sockaddr *ifu_dstaddr;
+ } ifa_ifu;
+ void *ifa_data; /* Address-specific data (may be unused). */
+/*
+ * This may have been defined in <net/if.h>.
+ */
+#ifndef ifa_broadaddr
+#define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */
+#endif
+#ifndef ifa_dstaddr
+#define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */
+#endif
+};
+#endif
+
+/*
+ * Create a linked list of `struct ifaddrs' structures, one for each
+ * network interface on the host machine. If successful, store the
+ * list in *ifap and return 0. On errors, return -1 and set `errno'.
+ *
+ * The storage returned in *ifap is allocated dynamically and can
+ * only be properly freed by passing it to `freeifaddrs'.
+ */
+extern int getifaddrs(struct ifaddrs **);
+
+/* Reclaim the storage allocated by a previous `getifaddrs' call. */
+extern void freeifaddrs(struct ifaddrs *);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _IFADDRS_H */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list