]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We should not use ntohl in IN_LOCAL define, instead where we use it.
authorRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 16:08:49 +0000 (16:08 +0000)
committerRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 16:08:49 +0000 (16:08 +0000)
client.c
configure.c
dhcp.c
dhcpcd.c
interface.h

index 44c0c0df7b64c4a450b0c27be338fc24d443eb95..5323be320e0a8de62326714e5ebaf2dfd8520d4e 100644 (file)
--- a/client.c
+++ b/client.c
@@ -180,7 +180,7 @@ static bool get_old_lease (const options_t *options, interface_t *iface,
 #ifdef ENABLE_ARP
        /* Check that no-one is using the address */
        if ((options->dolastlease || 
-                (IN_LINKLOCAL (dhcp->address.s_addr) &&
+                (IN_LINKLOCAL (ntohl (dhcp->address.s_addr)) &&
                  (! options->doipv4ll ||
                   arp_claim (iface, dhcp->address)))))
        {
@@ -271,7 +271,9 @@ int dhcp_run (const options_t *options, int *pidfd)
                        return (-1);
                }
 
-               if (! options->daemonised && IN_LINKLOCAL (dhcp->address.s_addr)) {
+               if (! options->daemonised &&
+                       IN_LINKLOCAL (ntohl (dhcp->address.s_addr)))
+               {
                        logger (LOG_ERR, "cannot request a link local address");
                        return (-1);
                }
@@ -459,7 +461,7 @@ int dhcp_run (const options_t *options, int *pidfd)
                                                || state == STATE_REBINDING)
                                        {
                                                logger (LOG_INFO, "received SIGHUP, releasing lease");
-                                               if (! IN_LINKLOCAL (dhcp->address.s_addr)) {
+                                               if (! IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) {
                                                        SOCKET_MODE (SOCKET_OPEN);
                                                        xid = random ();
                                                        if ((open_socket (iface, false)) >= 0)
@@ -489,13 +491,13 @@ int dhcp_run (const options_t *options, int *pidfd)
                                case STATE_INIT:
                                        if (xid != 0) {
                                                if (iface->previous_address.s_addr != 0 &&
-                                                       ! IN_LINKLOCAL (iface->previous_address.s_addr) &&
+                                                       ! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr)) &&
                                                        ! options->doinform)
                                                {
                                                        logger (LOG_ERR, "lost lease");
                                                        if (! options->persistent)
                                                                DROP_CONFIG;
-                                               } else
+                                               } else if (! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr)))
                                                        logger (LOG_ERR, "timed out");
                                                
                                                SOCKET_MODE (SOCKET_CLOSED);
@@ -525,7 +527,7 @@ int dhcp_run (const options_t *options, int *pidfd)
 #ifdef ENABLE_IPV4LL
                                                if (! options->test && options->doipv4ll &&
                                                        (! dhcp->address.s_addr ||
-                                                        (! IN_LINKLOCAL (dhcp->address.s_addr) &&
+                                                        (! IN_LINKLOCAL (ntohl (dhcp->address.s_addr)) &&
                                                          ! options->dolastlease)))
                                                {
                                                        logger (LOG_INFO, "probing for an IPV4LL address");
@@ -534,9 +536,6 @@ int dhcp_run (const options_t *options, int *pidfd)
                                                        if (ipv4ll_get_address (iface, dhcp) == -1) {
                                                                break;
                                                        }
-                                                       if (! daemonised)
-                                                               logger (LOG_WARNING, "using IPV4LL address %s",
-                                                                               inet_ntoa (dhcp->address));
                                                        timeout = dhcp->renewaltime;
                                                }
 #endif
@@ -544,6 +543,10 @@ int dhcp_run (const options_t *options, int *pidfd)
 #if defined (ENABLE_INFO) || defined (ENABLE_IPV4LL)
                                                if (dhcp->address.s_addr)
                                                {
+                                                       if (! daemonised &&
+                                                               IN_LINKLOCAL (ntohl (dhcp->address.s_addr)))
+                                                               logger (LOG_WARNING, "using IPV4LL address %s",
+                                                                               inet_ntoa (dhcp->address));
                                                        if (configure (options, iface, dhcp, true) == -1 &&
                                                                ! daemonised)
                                                        {
@@ -601,7 +604,7 @@ int dhcp_run (const options_t *options, int *pidfd)
                                        break;
                                case STATE_BOUND:
                                case STATE_RENEW_REQUESTED:
-                                       if (IN_LINKLOCAL (dhcp->address.s_addr)) {
+                                       if (IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) {
                                                memset (&dhcp->address, 0, sizeof (struct in_addr));
                                                state = STATE_INIT;
                                                xid = 0;
index ae5fa5550aa92a47bd98f31a87c4a90497e06c79..ca832aa99039c04bcc0a2110e1569e675557ec50 100644 (file)
@@ -546,7 +546,7 @@ int configure (const options_t *options, interface_t *iface,
         * address and isn't link local itself */
        if (options-> doipv4ll &&
                ! haslinklocal &&
-               IN_PRIVATE (dhcp->address.s_addr))
+               IN_PRIVATE (ntohl (dhcp->address.s_addr)))
        {
                struct in_addr dest;
                struct in_addr mask;
diff --git a/dhcp.c b/dhcp.c
index 4f8c3ffdc92ce72dedd389aa4ca8e1c66548142d..532d9536f418322cc971c94e9b422857b6fa2b5e 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -78,7 +78,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
        if ((type == DHCP_INFORM ||
                type == DHCP_RELEASE ||
                type == DHCP_REQUEST) &&
-               ! IN_LINKLOCAL (iface->previous_address.s_addr))
+               ! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr)))
        {
                message->ciaddr = iface->previous_address.s_addr;
                from.s_addr = iface->previous_address.s_addr;
@@ -143,7 +143,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
                        memcpy (p, &_val.s_addr, 4); \
                        p += 4; \
                }
-               if (IN_LINKLOCAL (dhcp->address.s_addr))
+               if (IN_LINKLOCAL (ntohl (dhcp->address.s_addr)))
                        logger (LOG_ERR, "cannot request a link local address");
                else {
                        if (dhcp->address.s_addr != iface->previous_address.s_addr &&
index d52bfd76d5b8a1c4f996204e0f365e1a3179baa8..5db98e8b18eac5e90fe1cd365bef3800c97f1513 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
                        options->keep_address = true;
        }
 
-       if (IN_LINKLOCAL (options->request_address.s_addr)) {
+       if (IN_LINKLOCAL (ntohl (options->request_address.s_addr))) {
                logger (LOG_ERR, "you are not allowed to request a link local address");
                exit (EXIT_FAILURE);
        }
index f49afd89cfe9cedcc9b7474897f3396958e8f6d8..3115452e6a51dd6f79c91092b9e3582624ae9f36 100644 (file)
@@ -45,9 +45,9 @@
  * 192.168/16
  */
 #ifndef IN_PRIVATE
-# define IN_PRIVATE(addr) (((ntohl (addr) & IN_CLASSA_NET) == 0x0a000000) || \
-                                                  ((ntohl (addr) & 0xfff00000)    == 0xac100000) || \
-                                                  ((ntohl (addr) & IN_CLASSB_NET) == 0xc0a80000))
+# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
+                                                  ((addr & 0xfff00000)    == 0xac100000) || \
+                                                  ((addr & IN_CLASSB_NET) == 0xc0a80000))
 #endif
 
 #define LINKLOCAL_ADDR       0xa9fe0000
@@ -55,7 +55,7 @@
 #define LINKLOCAL_BRDC          0xa9feffff
 
 #ifndef IN_LINKLOCAL
-# define IN_LINKLOCAL(addr) ((ntohl (addr) & IN_CLASSB_NET) == LINKLOCAL_ADDR)
+# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
 #endif
 
 typedef struct route_t