Work around implementation-dependent shift results
[freeradius.git] / src / main / client.c
index 247ce1d..bd825db 100644 (file)
@@ -233,15 +233,34 @@ static int client_sane(RADCLIENT *client)
                               sizeof(client->ipaddr.ipaddr.ip6addr));
 
                } else if (client->prefix < 128) {
-                       int i;
                        uint32_t mask, *addr;
 
                        addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
 
-                       for (i = client->prefix; i < 128; i += 32) {
-                               mask = ~0;
-                               mask <<= ((128 - i) & 0x1f);
-                               addr[i / 32] &= mask;
+                       if ((client->prefix & 0x1f) == 0) {
+                               mask = 0;
+                       } else {
+                               mask = ~ ((uint32_t) 0);
+                               mask <<= (32 - (client->prefix & 0x1f));
+                               mask = htonl(mask);
+                       }
+
+                       switch (client->prefix >> 5) {
+                       case 0:
+                               addr[0] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 1:
+                               addr[1] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 2:
+                               addr[2] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 3:
+                               addr[3] &= mask;
+                         break;
                        }
                }
                break;
@@ -491,11 +510,7 @@ RADCLIENT *client_find(const RADCLIENT_LIST *clients,
  */
 RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
 {
-       return client_find(root_clients, ipaddr
-#ifdef WITH_TCP
-                          , IPPROTO_UDP
-#endif
-                          );
+       return client_find(root_clients, ipaddr, IPPROTO_UDP);
 }
 
 static struct in_addr cl_ip4addr;