X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/8d516888863f6236649b33af3d69b8d159d1f789..e02f980793337f4bf0b16bca957a3d112a67b62a:/lib/addr.c
diff --git a/lib/addr.c b/lib/addr.c
index a763321..fecc28c 100644
--- a/lib/addr.c
+++ b/lib/addr.c
@@ -1,40 +1,33 @@
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2007 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * This program 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.
- *
+ *
+ * This program 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 General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see .
*/
/** @file lib/addr.c
* @brief Socket address support */
-#include
-#include "types.h"
+#include "common.h"
-#include
-#include
#include
#include
#include
-#include
#include
#include
#include "log.h"
#include "printf.h"
-#include "configuration.h"
#include "addr.h"
#include "mem.h"
@@ -105,7 +98,7 @@ int addrinfocmp(const struct addrinfo *a,
if(a->ai_family != b->ai_family) return a->ai_family - b->ai_family;
if(a->ai_socktype != b->ai_socktype) return a->ai_socktype - b->ai_socktype;
if(a->ai_protocol != b->ai_protocol) return a->ai_protocol - b->ai_protocol;
- switch(a->ai_protocol) {
+ switch(a->ai_family) {
case PF_INET:
ina = (const struct sockaddr_in *)a->ai_addr;
inb = (const struct sockaddr_in *)b->ai_addr;
@@ -125,10 +118,12 @@ int addrinfocmp(const struct addrinfo *a,
}
}
+/** @brief Return nonzero if @p sin4 is an IPv4 multicast address */
static inline int multicast4(const struct sockaddr_in *sin4) {
return IN_MULTICAST(ntohl(sin4->sin_addr.s_addr));
}
+/** @brief Return nonzero if @p sin6 is an IPv6 multicast address */
static inline int multicast6(const struct sockaddr_in6 *sin6) {
return IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr);
}
@@ -145,6 +140,7 @@ int multicast(const struct sockaddr *sa) {
}
}
+/** @brief Format an IPv4 address */
static inline char *format_sockaddr4(const struct sockaddr_in *sin4) {
char buffer[1024], *r;
@@ -160,6 +156,7 @@ static inline char *format_sockaddr4(const struct sockaddr_in *sin4) {
return r;
}
+/** @brief Format an IPv6 address */
static inline char *format_sockaddr6(const struct sockaddr_in6 *sin6) {
char buffer[1024], *r;
@@ -175,11 +172,15 @@ static inline char *format_sockaddr6(const struct sockaddr_in6 *sin6) {
return r;
}
+/** @brief Format a UNIX socket address */
static inline char *format_sockaddrun(const struct sockaddr_un *sun) {
return xstrdup(sun->sun_path);
}
-/** @brief Construct a text description a sockaddr */
+/** @brief Construct a text description a sockaddr
+ * @param sa Socket address
+ * @return Human-readable form of address
+ */
char *format_sockaddr(const struct sockaddr *sa) {
switch(sa->sa_family) {
case AF_INET: