Commits

Anonymous committed ba3f698

Submit cf-0.1 release.

  • Participants
  • Parent commits a4f84b1

Comments (0)

Files changed (1)

cf/cf_ip4_addr_p.c

 /*---------------------------------------------------------------------------*
   C MODULE  cf_ip4_addr_p.c
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
     const u_int8_t* addr2Ptr;
     int i, result;
     
-    addr1Ptr = (u_int8_t*)(Cf_ip4_addr_val(v1)->s_addr) + 3;
-    addr2Ptr = (u_int8_t*)(Cf_ip4_addr_val(v2)->s_addr) + 3;
+    addr1Ptr = (u_int8_t*)(&Cf_ip4_addr_val(v1)->s_addr) + 3;
+    addr2Ptr = (u_int8_t*)(&Cf_ip4_addr_val(v2)->s_addr) + 3;
     
     for (i = 4; i >= 0; --i, --addr1Ptr, --addr2Ptr) {
         result = *addr1Ptr - *addr2Ptr;
     CAMLparam1(v);
     long result;
     
-    result = (long) Cf_ip4_addr_val(v)->s_addr;
+    result = (long) ntohl(Cf_ip4_addr_val(v)->s_addr);
     
     CAMLreturn(result);
 }
     CAMLreturn(addr);
 }
 
+#ifndef IN_LINKLOCAL
+#define IN_LINKLOCALNETNUM    (u_int32_t)0xA9FE0000 /* 169.254.0.0 */
+#define IN_LINKLOCAL(i) \
+    (((u_int32_t)(i) & IN_CLASSB_NET) == IN_LINKLOCALNETNUM)
+#endif
+
 /*---
     external unicast_realm:
         [> unicast ] t -> unicast_realm = "cf_ip4_addr_unicast_realm"
     hostMask = cf_ip4_addr_compute_hostmask(prefixLen);
     
     if (minPtr) minPtr->s_addr = addrPtr->s_addr & ~hostMask;
-    if (maxPtr) maxPtr->s_addr = addrPtr->s_addr | hostMask;
+    if (maxPtr) maxPtr->s_addr = addrPtr->s_addr | ~hostMask;
 }
 
 /*---
 
     register_custom_operations(&cf_ip4_addr_op);
         
-    addr.s_addr = INADDR_ANY;
+    addr.s_addr = htonl(INADDR_ANY);
     register_global_root(&cf_ip4_addr_any_val);
     cf_ip4_addr_any_val = cf_ip4_addr_alloc(&addr);
 
-    addr.s_addr = INADDR_LOOPBACK;
+    addr.s_addr = htonl(INADDR_LOOPBACK);
     register_global_root(&cf_ip4_addr_loopback_val);
     cf_ip4_addr_loopback_val = cf_ip4_addr_alloc(&addr);
 
-    addr.s_addr = INADDR_BROADCAST;
+    addr.s_addr = htonl(INADDR_BROADCAST);
     register_global_root(&cf_ip4_addr_broadcast_val);
     cf_ip4_addr_broadcast_val = cf_ip4_addr_alloc(&addr);
 
-    addr.s_addr = INADDR_UNSPEC_GROUP;
+    addr.s_addr = htonl(INADDR_UNSPEC_GROUP);
     register_global_root(&cf_ip4_addr_empty_group_val);
     cf_ip4_addr_empty_group_val = cf_ip4_addr_alloc(&addr);
 
-    addr.s_addr = INADDR_ALLHOSTS_GROUP;
+    addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
     register_global_root(&cf_ip4_addr_all_hosts_group_val);
     cf_ip4_addr_all_hosts_group_val = cf_ip4_addr_alloc(&addr);
 
-    addr.s_addr = INADDR_ALLRTRS_GROUP;
+    addr.s_addr = htonl(INADDR_ALLRTRS_GROUP);
     register_global_root(&cf_ip4_addr_all_routers_group_val);
     cf_ip4_addr_all_routers_group_val = cf_ip4_addr_alloc(&addr);