I was looking into cleaning up the inet_ntoa's in Apache, and in the process
also cleaned up some minute APR code. This just removes some magic #'s
It's so minor it is embarassing to post.. ;-)
Commit or reject at your leisure,
-- Jon
Index: lib/apr/include/apr_network_io.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_network_io.h,v
retrieving revision 1.85
diff -u -r1.85 apr_network_io.h
--- lib/apr/include/apr_network_io.h 2000/12/01 18:47:28 1.85
+++ lib/apr/include/apr_network_io.h 2000/12/02 00:11:58
@@ -154,6 +154,10 @@
/* use apr_uint16_t just in case some system has a short that isn't 16 bits...
*/
typedef apr_uint16_t apr_port_t;
+/* Length of the string rep of a dotted decimal notation of an addy */
+#define APR_IPV4_DOTDEC_LEN (sizeof("255.255.255.255"))
+#define APR_IPV6_DOTDEC_LEN
(sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))
+
/* we're going to roll our own sockaddr type as we want to make sure
* we have protocol independence for APR...
*
Index: lib/apr/network_io/unix/inet_ntop.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/inet_ntop.c,v
retrieving revision 1.4
diff -u -r1.4 inet_ntop.c
--- lib/apr/network_io/unix/inet_ntop.c 2000/11/18 13:28:12 1.4
+++ lib/apr/network_io/unix/inet_ntop.c 2000/12/02 00:12:03
@@ -73,10 +73,10 @@
apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size)
{
switch (af) {
- case AF_INET:
+ case APR_INET:
return (inet_ntop4(src, dst, size));
#if APR_HAVE_IPV6
- case AF_INET6:
+ case APR_INET6:
return (inet_ntop6(src, dst, size));
#endif
default:
@@ -104,7 +104,7 @@
apr_size_t size;
{
static const char fmt[] = "%u.%u.%u.%u";
- char tmp[sizeof "255.255.255.255"];
+ char tmp[APR_IPV4_DOTDEC_LEN];
if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
errno = ENOSPC;
@@ -134,7 +134,7 @@
* Keep this in mind if you think this function should have been coded
* to use pointer overlays. All the world's not a VAX.
*/
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+ char tmp[APR_IPV6_DOTDEC_LEN], *tp;
struct { int base, len; } best, cur;
unsigned int words[IN6ADDRSZ / INT16SZ];
int i;
Index: lib/apr/network_io/unix/sa_common.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sa_common.c,v
retrieving revision 1.15
diff -u -r1.15 sa_common.c
--- lib/apr/network_io/unix/sa_common.c 2000/12/01 18:47:31 1.15
+++ lib/apr/network_io/unix/sa_common.c 2000/12/02 00:12:03
@@ -142,14 +142,14 @@
if (family == APR_INET) {
addr->salen = sizeof(struct sockaddr_in);
- addr->addr_str_len = 16;
+ addr->addr_str_len = APR_IPV4_DOTDEC_LEN;
addr->ipaddr_ptr = &(addr->sa.sin.sin_addr);
addr->ipaddr_len = sizeof(struct in_addr);
}
#if APR_HAVE_IPV6
else if (family == APR_INET6) {
addr->salen = sizeof(struct sockaddr_in6);
- addr->addr_str_len = 46;
+ addr->addr_str_len = APR_IPV6_DOTDEC_LEN;
addr->ipaddr_ptr = &(addr->sa.sin6.sin6_addr);
addr->ipaddr_len = sizeof(struct in6_addr);
}
Index: lib/apr/network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sockets.c,v
retrieving revision 1.65
diff -u -r1.65 sockets.c
--- lib/apr/network_io/unix/sockets.c 2000/11/21 21:33:07 1.65
+++ lib/apr/network_io/unix/sockets.c 2000/12/02 00:12:03
@@ -79,24 +79,24 @@
if (family == APR_INET) {
sock->local_addr->salen = sizeof(struct sockaddr_in);
- sock->local_addr->addr_str_len = 16;
+ sock->local_addr->addr_str_len = APR_IPV4_DOTDEC_LEN;
sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin.sin_addr);
sock->local_addr->ipaddr_len = sizeof(struct in_addr);
sock->remote_addr->salen = sizeof(struct sockaddr_in);
- sock->remote_addr->addr_str_len = 16;
+ sock->remote_addr->addr_str_len = APR_IPV4_DOTDEC_LEN;
sock->remote_addr->ipaddr_ptr = &(sock->remote_addr->sa.sin.sin_addr);
sock->remote_addr->ipaddr_len = sizeof(struct in_addr);
}
#if APR_HAVE_IPV6
else if (family == APR_INET6) {
sock->local_addr->salen = sizeof(struct sockaddr_in6);
- sock->local_addr->addr_str_len = 46;
+ sock->local_addr->addr_str_len = APR_IPV6_DOTDEC_LEN;
sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin6.sin6_addr);
sock->local_addr->ipaddr_len = sizeof(struct in6_addr);
sock->remote_addr->salen = sizeof(struct sockaddr_in6);
- sock->remote_addr->addr_str_len = 46;
+ sock->remote_addr->addr_str_len = APR_IPV6_DOTDEC_LEN;
sock->remote_addr->ipaddr_ptr =
&(sock->remote_addr->sa.sin6.sin6_addr);
sock->remote_addr->ipaddr_len = sizeof(struct in6_addr);
}