/*
* This file is part of DisOrder.
- * Copyright (C) 2004 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
-/** @file lib/addr.c Socket address support */
+/** @file lib/addr.c
+ * @brief Socket address support */
#include <config.h>
#include "types.h"
}
}
-static inline int multicast4(const struct sockaddr_in *sin) {
- return IN_MULTICAST(ntohl(sin->sin_addr.s_addr));
+/** @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);
}
}
}
-static inline char *format_sockaddr4(const struct sockaddr_in *sin) {
+/** @brief Format an IPv4 address */
+static inline char *format_sockaddr4(const struct sockaddr_in *sin4) {
char buffer[1024], *r;
- if(sin->sin_port)
+ if(sin4->sin_port)
byte_xasprintf(&r, "%s port %u",
- inet_ntop(sin->sin_family, &sin->sin_addr,
+ inet_ntop(sin4->sin_family, &sin4->sin_addr,
buffer, sizeof buffer),
- ntohs(sin->sin_port));
+ ntohs(sin4->sin_port));
else
byte_xasprintf(&r, "%s",
- inet_ntop(sin->sin_family, &sin->sin_addr,
+ inet_ntop(sin4->sin_family, &sin4->sin_addr,
buffer, sizeof buffer));
return r;
}
+/** @brief Format an IPv6 address */
static inline char *format_sockaddr6(const struct sockaddr_in6 *sin6) {
char buffer[1024], *r;
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: