summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-11-20 00:45:03 +0000
committerLennart Poettering <lennart@poettering.net>2005-11-20 00:45:03 +0000
commitef97e32ba2ed98b791af4504103b5f0378bb6b9b (patch)
tree35d898a850784e7f5d8c029bbb9b6d461f69b130
parent67ff22450f3fc7a9b933cc0e465d7f5083e2b47f (diff)
* bump version number
* make nss-mdns shut up * deal with OOM * other cleanups git-svn-id: file:///home/lennart/svn/public/nss-mdns/trunk@87 0ee8848e-81ea-0310-a63a-f631d1a40d77
-rw-r--r--configure.ac2
-rw-r--r--doc/README.html.in39
-rw-r--r--src/Makefile.am2
-rw-r--r--src/avahi.c7
-rw-r--r--src/dns.c16
-rw-r--r--src/nss.c2
-rw-r--r--src/query.c81
-rw-r--r--src/util.c9
8 files changed, 61 insertions, 97 deletions
diff --git a/configure.ac b/configure.ac
index c50c10c..8ded07b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@
# USA.
AC_PREREQ(2.57)
-AC_INIT([nss-mdns],[0.6],[mzaffzqaf (at) 0pointer (dot) de])
+AC_INIT([nss-mdns],[0.7],[mzaffzqaf (at) 0pointer (dot) de])
AC_CONFIG_SRCDIR([src/query.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign 1.9 -Wall])
diff --git a/doc/README.html.in b/doc/README.html.in
index 72e66e2..28e5402 100644
--- a/doc/README.html.in
+++ b/doc/README.html.in
@@ -42,6 +42,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p>
<h2><a name="news">News</a></h2>
+<div class="news-date">Sat Nov 19 2005: </div> <p class="news-text"><a
+href="@PACKAGE_URL@nss-mdns-0.7.tar.gz">Version 0.7</a>
+released. Changes include: Portability patch for ARM from Philipp
+Zabel; make sure not to print any messages to STDERR; deal with OOM
+situations properly; other cleanups</p>
+
<div class="news-date">Sun Aug 21 2005: </div> <p class="news-text"><a
href="@PACKAGE_URL@nss-mdns-0.6.tar.gz">Version 0.6</a>
released. Changes include: honour search list in
@@ -81,20 +87,20 @@ href="@PACKAGE_URL@nss-mdns-0.1.tar.gz">Version 0.1</a> released</p>
Switch (NSS) functionality of the GNU C Library (<tt>glibc</tt>)
providing host name resolution via <a
href="http://www.multicastdns.org/">Multicast DNS</a> (aka
-<i>Zeroconf</i>, aka <i>Apple Rendezvous</i>), effectively allowing
+<i>Zeroconf</i>, aka <i>Apple Rendezvous</i>, aka <i>Apple Bonjour</i>), effectively allowing
name resolution by common Unix/Linux programs in the ad-hoc mDNS domain <tt>.local</tt>.</p>
<p><tt>nss-mdns</tt> provides client functionality only, which
means that you have to run a mDNS responder daemon seperately
from <tt>nss-mdns</tt> if you want to register the local host name via
-mDNS (e.g. <a href="http://www.freedesktop.org/Software/Avahi">Avahi</a>).</p>
+mDNS. I recommend <a href="http://www.freedesktop.org/Software/Avahi">Avahi</a>.</p>
<p><tt>nss-mdns</tt> is very lightweight (23 KByte stripped binary
-<tt>.so</tt> compiled with <tt>-DNDEBUG=1</tt> on i386, <tt>gcc</tt>
-3.3), has no dependencies besides the <tt>glibc</tt> and requires only
+<tt>.so</tt> compiled with <tt>-DNDEBUG=1 -Os</tt> on i386, <tt>gcc</tt>
+4.0), has no dependencies besides the <tt>glibc</tt> and requires only
minimal configuration.</p>
-<p>Optionally, <tt>nss-mdns</tt> can try to contact a running <a
+<p>Optionally <tt>nss-mdns</tt> can try to contact a running <a
href="http://www.freedesktop.org/Software/Avahi">avahi-daemon</a> to
make use of its superior record cacheing.</p>
@@ -103,7 +109,8 @@ make use of its superior record cacheing.</p>
<p>It works!</p>
<p>While <tt>nss-mdns</tt> supports resolving IPv6 addresses it does
-so via IPv4 multicasts only.</p>
+so via IPv4 multicasts only. (Unless, of course, it finds a running
+Avahi daemon which supports IPv6 properly.)</p>
<h2><a name="documentation">Documentation</a></h2>
@@ -153,12 +160,6 @@ use <tt>glibc</tt>'s <tt>getent</tt> tool:
<p>Replace <i>foo</i> whith a host name that has been registered with
an mDNS responder.</p>
-<p>To reduce the traffic <tt>nss-mdns</tt> is responsible for consider
-installing <tt>glibc</tt>'s name service cache daemon
-<tt>nscd</tt>. However, when doing troubleshooting for
-<tt>nss-mdns</tt>, don't forget to disable <tt>nscd</tt> for getting
-sensible results.</p>
-
<p>If you run a firewall, don't forget to allow UDP traffic to the the
mDNS multicast address <tt>224.0.0.251</tt> on port 5353.</p>
@@ -187,14 +188,6 @@ mDNS.</p>
<p>If the configuration file is existent but empty, mDNS name lookups
are disabled completely.</p>
-<p><tt>nss-mdns</tt> does not honour the domain search list of
-<tt>/etc/resolv.conf</tt>, because I don't consider that this would be
-a good idea, since every name lookup for non-existing domains would
-result in a series of long timeouts of <tt>nss-mdns</tt>. If somebody
-still considers this a good idea, he is free to send me a sensible
-patch, which I might apply, but only if the domain search list may be
-disabled.</p>
-
<h2><a name="requirements">Requirements</a></h2>
<p>Currently, <tt>nss-mdns</tt> is tested on Linux only. A fairly
@@ -222,6 +215,8 @@ compilation and <tt>make install</tt> (as root) for installation of
<p>Sean Meiners for search list support.</p>
+<p>Philipp Zabel for ARM support.</p>
+
<h2><a name="download">Download</a></h2>
<p>The newest release is always available from <a href="@PACKAGE_URL@">@PACKAGE_URL@</a></p>
@@ -232,12 +227,12 @@ compilation and <tt>make install</tt> (as root) for installation of
<pre>svn checkout svn://svn.0pointer.de/nss-mdns/trunk nss-mdns</pre>
-<p>You may find an up to date Debian package of <tt>nss-mdns</tt> on the <a href="http://packages.debian.org/libnss-mdns">Debian package repository</a>.</p>
+<p>You may find an up to date Debian package of <tt>nss-mdns</tt> on the <a href="http://packages.debian.org/libnss-mdns">Debian package repository</a>. Many other distributions ship it, too.</p>
<p>If you want to be notified whenever I release a new version of this software use the subscription feature of <a href="http://freshmeat.net/projects/nss-mdns/">Freshmeat</a>.</p>
<hr/>
-<address class="grey">Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, Aug 2005</address>
+<address class="grey">Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, Nov 2005</address>
<div class="grey"><i>$Id$</i></div>
</body>
diff --git a/src/Makefile.am b/src/Makefile.am
index 6e537cf..231b0b6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,7 +22,7 @@ AM_CFLAGS = \
-DRESOLV_CONF_FILE=\"$(sysconfdir)/resolv.conf\" \
-DAVAHI_SOCKET=\"$(localstatedir)/run/avahi-daemon/socket\"
-#-DNDEBUG=1
+#AM_CFLAGS += -DNDEBUG=1 -Os
# This cool debug trap works on i386/gcc only
AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
diff --git a/src/avahi.c b/src/avahi.c
index 96ce615..8e45e85 100644
--- a/src/avahi.c
+++ b/src/avahi.c
@@ -65,7 +65,6 @@ fail:
close(fd);
return NULL;
-
}
int avahi_resolve_name(int af, const char* name, void* data) {
@@ -74,7 +73,8 @@ int avahi_resolve_name(int af, const char* name, void* data) {
int ret = -1;
char ln[256];
- assert(af == AF_INET || af == AF_INET6);
+ if (af != AF_INET && af != AF_INET6)
+ goto finish;
if (!(f = open_socket()))
goto finish;
@@ -127,7 +127,8 @@ int avahi_resolve_address(int af, const void *data, char* name, size_t name_len)
int ret = -1;
char a[256], ln[256];
- assert(af == AF_INET || af == AF_INET6);
+ if (af != AF_INET && af == AF_INET6)
+ goto finish;
if (!(f = open_socket()))
goto finish;
diff --git a/src/dns.c b/src/dns.c
index 61c66d8..e7e9765 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -34,8 +34,10 @@
struct dns_packet* dns_packet_new(void) {
struct dns_packet *p;
- p = malloc(sizeof(struct dns_packet));
- assert(p);
+
+ if (!(p = malloc(sizeof(struct dns_packet))))
+ return NULL;
+
p->size = p->rindex = 2*6;
memset(p->data, 0, p->size);
return p;
@@ -47,13 +49,15 @@ void dns_packet_free(struct dns_packet *p) {
}
void dns_packet_set_field(struct dns_packet *p, unsigned idx, uint16_t v) {
- assert(p && idx < 2*6);
+ assert(p);
+ assert(idx < 2*6);
((uint16_t*) p->data)[idx] = htons(v);
}
uint16_t dns_packet_get_field(struct dns_packet *p, unsigned idx) {
- assert(p && idx < 2*6);
+ assert(p);
+ assert(idx < 2*6);
return ntohs(((uint16_t*) p->data)[idx]);
}
@@ -70,6 +74,7 @@ uint8_t* dns_packet_append_name(struct dns_packet *p, const char *name) {
d = dns_packet_extend(p, n+1);
if (!f)
f = d;
+
d[0] = n;
memcpy(d+1, name, n);
@@ -95,8 +100,10 @@ uint8_t* dns_packet_append_name(struct dns_packet *p, const char *name) {
uint8_t* dns_packet_append_uint16(struct dns_packet *p, uint16_t v) {
uint8_t *d;
assert(p);
+
d = dns_packet_extend(p, sizeof(uint16_t));
*((uint16_t*) d) = htons(v);
+
return d;
}
@@ -158,7 +165,6 @@ int dns_packet_check_valid_response(struct dns_packet *p) {
return -1;
return 0;
-
}
static ssize_t consume_labels(struct dns_packet *p, size_t idx, char *ret_name, size_t l) {
diff --git a/src/nss.c b/src/nss.c
index e45342d..5b5579a 100644
--- a/src/nss.c
+++ b/src/nss.c
@@ -8,7 +8,7 @@
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
+ nss-mdns is distributed in the hope that it will be useful, but1
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.
diff --git a/src/query.c b/src/query.c
index 8079a3d..7a3e0bd 100644
--- a/src/query.c
+++ b/src/query.c
@@ -73,46 +73,32 @@ int mdns_open_socket(void) {
struct sockaddr_in sa;
int fd = -1, ttl, yes;
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- fprintf(stderr, "socket() failed: %s\n", strerror(errno));
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
goto fail;
- }
ttl = 255;
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
- fprintf(stderr, "IP_MULTICAST_TTL failed: %s\n", strerror(errno));
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
goto fail;
- }
sa.sin_family = AF_INET;
sa.sin_port = 0;
sa.sin_addr.s_addr = INADDR_ANY;
- if (bind(fd, (struct sockaddr*) &sa, sizeof(sa)) < 0) {
- fprintf(stderr, "bind() failed: %s\n", strerror(errno));
+ if (bind(fd, (struct sockaddr*) &sa, sizeof(sa)) < 0)
goto fail;
- }
yes = 1;
- if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
- fprintf(stderr, "IP_RECVTTL failed: %s\n", strerror(errno));
+ if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0)
goto fail;
- }
- if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
- fprintf(stderr, "IP_PKTINFO failed: %s\n", strerror(errno));
+ if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0)
goto fail;
- }
- if (set_cloexec(fd) < 0) {
- fprintf(stderr, "FD_CLOEXEC failed: %s\n", strerror(errno));
+ if (set_cloexec(fd) < 0)
goto fail;
- }
- if (set_nonblock(fd) < 0) {
- fprintf(stderr, "O_ONONBLOCK failed: %s\n", strerror(errno));
+ if (set_nonblock(fd) < 0)
goto fail;
- }
return fd;
@@ -129,7 +115,7 @@ static int send_dns_packet(int fd, struct dns_packet *p) {
struct iovec io;
struct cmsghdr *cmsg;
struct in_pktinfo *pkti;
- uint8_t cmsg_data[sizeof(struct cmsghdr) + sizeof(struct in_pktinfo)];
+ uint8_t cmsg_data[CMSG_LEN(sizeof(struct in_pktinfo))];
int i, n;
struct ifreq ifreq[32];
struct ifconf ifconf;
@@ -150,7 +136,7 @@ static int send_dns_packet(int fd, struct dns_packet *p) {
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
- pkti = (struct in_pktinfo*) (cmsg_data + sizeof(struct cmsghdr));
+ pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi_ifindex = 0;
memset(&msg, 0, sizeof(msg));
@@ -165,10 +151,8 @@ static int send_dns_packet(int fd, struct dns_packet *p) {
ifconf.ifc_req = ifreq;
ifconf.ifc_len = sizeof(ifreq);
- if (ioctl(fd, SIOCGIFCONF, &ifconf) < 0) {
- fprintf(stderr, "SIOCGIFCONF failed: %s\n", strerror(errno));
+ if (ioctl(fd, SIOCGIFCONF, &ifconf) < 0)
return -1;
- }
for (i = 0, n = ifconf.ifc_len/sizeof(struct ifreq); i < n; i++) {
struct sockaddr_in *ifsa;
@@ -205,10 +189,8 @@ static int send_dns_packet(int fd, struct dns_packet *p) {
if (sendmsg(fd, &msg, MSG_DONTROUTE) >= 0)
break;
- if (errno != EAGAIN) {
- fprintf(stderr, "sendmsg() failed: %s\n", strerror(errno));
+ if (errno != EAGAIN)
return -1;
- }
if (wait_for_write(fd, NULL) < 0)
return -1;
@@ -228,7 +210,8 @@ static int recv_dns_packet(int fd, struct dns_packet **ret_packet, uint8_t *ret_
uint8_t aux[64];
assert(fd >= 0);
- p = dns_packet_new();
+ if (!(p = dns_packet_new()))
+ return -1; /* OOM */
io.iov_base = p->data;
io.iov_len = sizeof(p->data);
@@ -257,10 +240,8 @@ static int recv_dns_packet(int fd, struct dns_packet **ret_packet, uint8_t *ret_
}
}
- if (cmsg == NULL) {
- fprintf(stderr, "Didn't recieve TTL\n");
+ if (!cmsg)
goto fail;
- }
p->size = (size_t) l;
@@ -268,10 +249,8 @@ static int recv_dns_packet(int fd, struct dns_packet **ret_packet, uint8_t *ret_
return 0;
}
- if (errno != EAGAIN) {
- fprintf(stderr, "recvfrom() failed: %s\n", strerror(errno));
+ if (errno != EAGAIN)
goto fail;
- }
if ((r = wait_for_read(fd, end)) < 0)
goto fail;
@@ -296,21 +275,17 @@ static int send_name_query(int fd, const char *name, uint16_t id, int query_ipv4
assert(fd >= 0 && name && (query_ipv4 || query_ipv6));
- if (!(p = dns_packet_new())) {
- fprintf(stderr, "Failed to allocate DNS packet.\n");
- goto finish;
- }
+ if (!(p = dns_packet_new()))
+ goto finish; /* OOM */
dns_packet_set_field(p, DNS_FIELD_ID, id);
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");
- goto finish;
-
- }
+ if (!(prev_name = dns_packet_append_name(p, name)))
+ goto finish; /* Bad name */
+
dns_packet_append_uint16(p, DNS_TYPE_A);
dns_packet_append_uint16(p, DNS_CLASS_IN);
qdcount++;
@@ -319,10 +294,8 @@ static int send_name_query(int fd, const char *name, uint16_t id, int query_ipv4
#ifndef NSS_IP4_ONLY
if (query_ipv6) {
- if (!dns_packet_append_name_compressed(p, name, prev_name)) {
- fprintf(stderr, "Bad host name\n");
- goto finish;
- }
+ if (!dns_packet_append_name_compressed(p, name, prev_name))
+ goto finish; /* Bad name */
dns_packet_append_uint16(p, DNS_TYPE_AAAA);
dns_packet_append_uint16(p, DNS_CLASS_IN);
@@ -510,18 +483,14 @@ static int send_reverse_query(int fd, const char *name, uint16_t id) {
assert(fd >= 0 && name);
- if (!(p = dns_packet_new())) {
- fprintf(stderr, "Failed to allocate DNS packet.\n");
+ if (!(p = dns_packet_new()))
goto finish;
- }
dns_packet_set_field(p, DNS_FIELD_ID, id);
dns_packet_set_field(p, DNS_FIELD_FLAGS, DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
- if (!dns_packet_append_name(p, name)) {
- fprintf(stderr, "Bad host name\n");
+ if (!dns_packet_append_name(p, name))
goto finish;
- }
dns_packet_append_uint16(p, DNS_TYPE_PTR);
dns_packet_append_uint16(p, DNS_CLASS_IN);
@@ -678,6 +647,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/util.c b/src/util.c
index b6b2d57..bf37711 100644
--- a/src/util.c
+++ b/src/util.c
@@ -26,7 +26,6 @@
#include <sys/select.h>
#include <errno.h>
#include <string.h>
-#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
@@ -152,10 +151,8 @@ int wait_for_write(int fd, struct timeval *end) {
}
if ((r = select(fd+1, NULL, &fds, NULL, end ? &tv : NULL)) < 0) {
- if (errno != EINTR) {
- fprintf(stderr, "select() failed: %s\n", strerror(errno));
+ if (errno != EINTR)
return -1;
- }
} else if (r == 0)
return 1;
else {
@@ -191,10 +188,8 @@ int wait_for_read(int fd, struct timeval *end) {
}
if ((r = select(fd+1, &fds, NULL, NULL, end ? &tv : NULL)) < 0) {
- if (errno != EINTR) {
- fprintf(stderr, "select() failed: %s\n", strerror(errno));
+ if (errno != EINTR)
return -1;
- }
} else if (r == 0)
return 1;
else {