Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: getaddrinfo tests



hello list,

On Fri, 4 Feb 2011 11:51:36 +0100
Martin Husemann <martin%duskware.de@localhost> wrote:

> ./usr.sbin/ndp
> ./usr.sbin/rwhod

I made patches for ndp and rwhod.
XXX: rwhod should use getifaddrs(3) to get v4 broadcast addresses.

Curiously rwhod works without this patch...

Thanks.


Index: src/usr.sbin/ndp/ndp.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/ndp/ndp.c,v
retrieving revision 1.38
diff -u -r1.38 ndp.c
--- src/usr.sbin/ndp/ndp.c      6 Nov 2009 20:51:19 -0000       1.38
+++ src/usr.sbin/ndp/ndp.c      13 Feb 2011 06:10:42 -0000
@@ -106,11 +106,6 @@
 #include <unistd.h>
 #include "gmt2local.h"
 
-/* packing rule for routing socket */
-#define ROUNDUP(a) \
-       ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
-#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
-
 static pid_t pid;
 static int nflag;
 static int tflag;
@@ -387,7 +382,7 @@
                /* NOTREACHED */
        }
        mysin = (struct sockaddr_in6 *)(void *)(rtm + 1);
-       sdl = (struct sockaddr_dl *)(void *)(ROUNDUP(mysin->sin6_len) + (char 
*)(void *)mysin);
+       sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(mysin->sin6_len) + 
(char *)(void *)mysin);
        if (IN6_ARE_ADDR_EQUAL(&mysin->sin6_addr, &sin_m.sin6_addr)) {
                if (sdl->sdl_family == AF_LINK &&
                    (rtm->rtm_flags & RTF_LLINFO) &&
@@ -482,7 +477,7 @@
        if (rtmsg(RTM_GET) < 0)
                errx(1, "RTM_GET(%s) failed", host);
        mysin = (struct sockaddr_in6 *)(void *)(rtm + 1);
-       sdl = (struct sockaddr_dl *)(void *)(ROUNDUP(mysin->sin6_len) +
+       sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(mysin->sin6_len) +
            (char *)(void *)mysin);
        if (IN6_ARE_ADDR_EQUAL(&mysin->sin6_addr, &sin_m.sin6_addr)) {
                if (sdl->sdl_family == AF_LINK &&
@@ -574,7 +569,7 @@
 
                rtm = (struct rt_msghdr *)(void *)next;
                mysin = (struct sockaddr_in6 *)(void *)(rtm + 1);
-               sdl = (struct sockaddr_dl *)(void *)((char *)(void *)mysin + 
ROUNDUP(mysin->sin6_len));
+               sdl = (struct sockaddr_dl *)(void *)((char *)(void *)mysin + 
RT_ROUNDUP(mysin->sin6_len));
 
                /*
                 * Some OSes can produce a route that has the LINK flag but
@@ -850,7 +845,7 @@
 #define NEXTADDR(w, s) \
        if (rtm->rtm_addrs & (w)) { \
                (void)memcpy(cp, &s, sizeof(s)); \
-               ADVANCE(cp, (struct sockaddr *)(void *)&s); \
+               RT_ADVANCE(cp, (struct sockaddr *)(void *)&s); \
        }
 
        NEXTADDR(RTA_DST, sin_m);
Index: src/usr.sbin/rwhod/rwhod.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/rwhod/rwhod.c,v
retrieving revision 1.38
diff -u -r1.38 rwhod.c
--- src/usr.sbin/rwhod/rwhod.c  18 Apr 2009 13:05:54 -0000      1.38
+++ src/usr.sbin/rwhod/rwhod.c  13 Feb 2011 06:10:43 -0000
@@ -444,10 +444,6 @@
        exit(EXIT_FAILURE);
 }
 
-#define ROUNDUP(a) \
-       ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
-#define ADVANCE(x, n) ((char *)(x) + ROUNDUP((n)->sa_len))
-
 static void
 rt_xaddrs(void *cp, void *cplim, struct rt_addrinfo *rtinfo)
 {
@@ -459,7 +455,7 @@
                if ((rtinfo->rti_addrs & (1 << i)) == 0)
                        continue;
                rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
-               cp = ADVANCE(cp, sa);
+               cp = (char *)cp + RT_ROUNDUP(sa->sa_len);
        }
 }
 

--
Takahiro HAYASHI



Home | Main Index | Thread Index | Old Index