summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-12-05 19:20:08 +0000
committerLennart Poettering <lennart@poettering.net>2004-12-05 19:20:08 +0000
commit9cc3df6a1958c18bee866a6af19661623d6cd71e (patch)
treef63ec3054bd13a27093c8d89dd6d232e84f4fa2b /src
parent5a12f4f892685adcbbeecbdc406a297152d0dad1 (diff)
port to autotools
git-svn-id: file:///home/lennart/svn/public/nss-mdns/trunk@54 0ee8848e-81ea-0310-a63a-f631d1a40d77
Diffstat (limited to 'src')
-rw-r--r--src/Makefile28
-rw-r--r--src/Makefile.am45
-rw-r--r--src/nss.c28
-rw-r--r--src/query.c27
-rw-r--r--src/query.h5
5 files changed, 97 insertions, 36 deletions
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index 1b70117..0000000
--- a/src/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
-CFLAGS=-Wall -fPIC -g -O0 -W -pipe '-DDEBUG_TRAP=__asm__("int $$3")'
-
-all: mdns-test nss-test libnss_mdns.so.2 libnss_mdns6.so.2 libnss_mdns4.so.2
-
-mdns-test: query.o dns.o util.o mdns-test.o
- $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-nss-test: nss-test.o
-
-libnss_mdns.so.2: query.o dns.o util.o nss.o
- $(CC) -shared -o $@ -Wl,-soname,$@ $^
-
-libnss_mdns4.so.2: query.o dns.o util.o nss4.o
- $(CC) -shared -o $@ -Wl,-soname,$@ $^
-
-libnss_mdns6.so.2: query.o dns.o util.o nss6.o
- $(CC) -shared -o $@ -Wl,-soname,$@ $^
-
-nss6.o: nss.c
- $(CC) $(CFLAGS) -DNSS_IPV6_ONLY=1 -c -o $@ $<
-
-nss4.o: nss.c
- $(CC) $(CFLAGS) -DNSS_IPV4_ONLY=1 -c -o $@ $<
-
-*.o: *.h
-
-clean:
- rm -f *.o mdns-test *.so.2 nss-test
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..dc2513c
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,45 @@
+# $Id$
+#
+# This file is part of nss-mdns.
+#
+# nss-mdns is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# nss-mdns is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with nss-mdns; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+rootlibdir=/
+
+AM_CFLAGS=-D_GNU_SOURCE
+
+# This cool debug trap works on i386/gcc only
+AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
+
+noinst_PROGRAMS = nss-test mdns-test
+
+rootlib_LTLIBRARIES = libnss_mdns.la libnss_mdns4.la libnss_mdns6.la
+
+mdns_test_SOURCES = query.c dns.c util.c mdns-test.c
+
+nss_test_SOURCES = nss-test.c
+
+libnss_mdns_la_SOURCES = query.c dns.c util.c nss.c
+libnss_mdns_la_CFLAGS=$(AM_CFLAGS)
+libnss_mdns_la_LDFLAGS=-avoid-version -module -export-dynamic -shrext .so.2
+
+libnss_mdns4_la_SOURCES=$(libnss_mdns_la_SOURCES)
+libnss_mdns4_la_CFLAGS=$(libnss_mdns_la_CFLAGS) -DNSS_IPV4_ONLY=1
+libnss_mdns4_la_LDFLAGS=$(libnss_mdns_la_LDFLAGS)
+
+libnss_mdns6_la_SOURCES=$(libnss_mdns_la_SOURCES)
+libnss_mdns6_la_CFLAGS=$(libnss_mdns_la_CFLAGS) -DNSS_IPV6_ONLY=1
+libnss_mdns6_la_LDFLAGS=$(libnss_mdns_la_LDFLAGS)
diff --git a/src/nss.c b/src/nss.c
index 0515b2d..b9e69e9 100644
--- a/src/nss.c
+++ b/src/nss.c
@@ -30,6 +30,7 @@ struct userdata {
} data;
};
+#ifndef NSS_IPV6_ONLY
static void ipv4_callback(const ipv4_address_t *ipv4, void *userdata) {
struct userdata *u = userdata;
assert(ipv4 && userdata);
@@ -40,7 +41,9 @@ static void ipv4_callback(const ipv4_address_t *ipv4, void *userdata) {
u->data.ipv4[u->count++] = *ipv4;
u->data_len += sizeof(ipv4_address_t);
}
+#endif
+#ifndef NSS_IPV4_ONLY
static void ipv6_callback(const ipv6_address_t *ipv6, void *userdata) {
struct userdata *u = userdata;
assert(ipv6 && userdata);
@@ -51,6 +54,7 @@ static void ipv6_callback(const ipv6_address_t *ipv6, void *userdata) {
u->data.ipv6[u->count++] = *ipv6;
u->data_len += sizeof(ipv6_address_t);
}
+#endif
static void name_callback(const char*name, void *userdata) {
struct userdata *u = userdata;
@@ -76,6 +80,8 @@ enum nss_status _nss_mdns_gethostbyname2_r(
enum nss_status status = NSS_STATUS_UNAVAIL;
int fd = -1, r, i;
size_t address_length, l, index, astart;
+ void (*ipv4_func)(const ipv4_address_t *ipv4, void *userdata);
+ void (*ipv6_func)(const ipv6_address_t *ipv6, void *userdata);
/* DEBUG_TRAP; */
@@ -113,8 +119,20 @@ enum nss_status _nss_mdns_gethostbyname2_r(
u.count = 0;
u.data_len = 0;
+
+#ifndef NSS_IPV6_ONLY
+ ipv4_func = af == AF_INET ? ipv4_callback : NULL;
+#else
+ ipv4_func = NULL;
+#endif
+
+#ifndef NSS_IPV4_ONLY
+ ipv6_func = af == AF_INET6 ? ipv6_callback : NULL;
+#else
+ ipv6_func = NULL;
+#endif
- if ((r = mdns_query_name(fd, name, af == AF_INET ? ipv4_callback : NULL, af == AF_INET6 ? ipv6_callback : NULL, &u)) < 0) {
+ if ((r = mdns_query_name(fd, name, ipv4_func, ipv6_func, &u)) < 0) {
*errnop = ETIMEDOUT;
*h_errnop = HOST_NOT_FOUND;
goto finish;
@@ -240,10 +258,18 @@ enum nss_status _nss_mdns_gethostbyaddr_r(
goto finish;
}
+#if ! defined(NSS_IPV6_ONLY) && ! defined(NSS_IPV4_ONLY)
if (af == AF_INET)
+#endif
+#ifndef NSS_IPV6_ONLY
r = mdns_query_ipv4(fd, (ipv4_address_t*) addr, name_callback, &u);
+#endif
+#if ! defined(NSS_IPV6_ONLY) && ! defined(NSS_IPV4_ONLY)
else
+#endif
+#ifndef NSS_IPV4_ONLY
r = mdns_query_ipv6(fd, (ipv6_address_t*) addr, name_callback, &u);
+#endif
if (r < 0) {
*errnop = ETIMEDOUT;
diff --git a/src/query.c b/src/query.c
index 5673c3e..441f1d8 100644
--- a/src/query.c
+++ b/src/query.c
@@ -192,6 +192,7 @@ static int send_name_query(int fd, const char *name, int query_ipv4, int query_i
dns_packet_set_field(p, DNS_FIELD_FLAGS, DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+#ifndef NSS_IP6_ONLY
if (query_ipv4) {
if (!(prev_name = dns_packet_append_name(p, name))) {
fprintf(stderr, "Bad host name\n");
@@ -202,7 +203,9 @@ static int send_name_query(int fd, const char *name, int query_ipv4, int query_i
dns_packet_append_uint16(p, DNS_CLASS_IN);
qdcount++;
}
-
+#endif
+
+#ifndef NSS_IP4_ONLY
if (query_ipv6) {
if (!dns_packet_append_name_compressed(p, name, prev_name)) {
fprintf(stderr, "Bad host name\n");
@@ -213,7 +216,8 @@ static int send_name_query(int fd, const char *name, int query_ipv4, int query_i
dns_packet_append_uint16(p, DNS_CLASS_IN);
qdcount++;
}
-
+#endif
+
dns_packet_set_field(p, DNS_FIELD_QDCOUNT, qdcount);
if (send_dns_packet(fd, p) < 0)
@@ -287,6 +291,7 @@ static int process_name_response(int fd, const char *name, usec_t timeout, void
/* Remove mDNS cache flush bit */
class &= ~0x8000;
+#ifndef NSS_IPV6_ONLY
if (ipv4_func &&
type == DNS_TYPE_A &&
class == DNS_CLASS_IN &&
@@ -301,7 +306,13 @@ static int process_name_response(int fd, const char *name, usec_t timeout, void
ipv4_func(&ipv4, userdata);
done = 1;
- } else if (ipv6_func &&
+ }
+#endif
+#if ! defined(NSS_IPV6_ONLY) && ! defined(NSS_IPV4_ONLY)
+ else
+#endif
+#ifndef NSS_IPV4_ONLY
+ if (ipv6_func &&
type == DNS_TYPE_AAAA &&
class == DNS_CLASS_IN &&
!domain_cmp(name, pname) &&
@@ -314,7 +325,9 @@ static int process_name_response(int fd, const char *name, usec_t timeout, void
ipv6_func(&ipv6, userdata);
done = 1;
- } else {
+ }
+#endif
+ else {
/* Step over */
@@ -486,7 +499,7 @@ static int query_reverse(int fd, const char *name, void (*name_func)(const char
return -1;
}
-
+#ifndef NSS_IPV6_ONLY
int mdns_query_ipv4(int fd, const ipv4_address_t *ipv4, void (*name_func)(const char *name, void *userdata), void *userdata) {
char name[256];
uint32_t a;
@@ -497,7 +510,9 @@ int mdns_query_ipv4(int fd, const ipv4_address_t *ipv4, void (*name_func)(const
return query_reverse(fd, name, name_func, userdata);
}
+#endif
+#ifndef NSS_IPV4_ONLY
int mdns_query_ipv6(int fd, const ipv6_address_t *ipv6, void (*name_func)(const char *name, void *userdata), void *userdata) {
char name[256];
assert(fd >= 0 && ipv6 && name_func);
@@ -538,4 +553,4 @@ int mdns_query_ipv6(int fd, const ipv6_address_t *ipv6, void (*name_func)(const
return query_reverse(fd, name, name_func, userdata);
}
-
+#endif
diff --git a/src/query.h b/src/query.h
index 0c22c49..2d77912 100644
--- a/src/query.h
+++ b/src/query.h
@@ -19,14 +19,17 @@ int mdns_query_name(int fd,
void (*ipv6_func)(const ipv6_address_t *ipv6, void *userdata),
void *userdata);
+#ifndef NSS_IPV6_ONLY
int mdns_query_ipv4(int fd,
const ipv4_address_t *ipv4,
void (*name_func)(const char *name, void *userdata),
void *userdata);
-
+#endif
+#ifndef NSS_IPV4_ONLY
int mdns_query_ipv6(int fd,
const ipv6_address_t *ipv6,
void (*name_func)(const char *name, void *userdata),
void *userdata);
+#endif
#endif