Commits

jhwoodyatt  committed 6cfcc4f

Add a third element to the socket address type: an int32 for the scope id.

  • Participants
  • Parent commits 9095881

Comments (0)

Files changed (3)

File cf/cf_ip6_proto.ml

 
 module AF = struct
     type tag_t = [ `AF_INET6 ]
-    type address_t = Cf_ip6_addr.opaque Cf_ip6_addr.t * int
+    type address_t = Cf_ip6_addr.opaque Cf_ip6_addr.t * int * int32
     
     let domain = domain_ ()
 
         let any =
             (Cf_ip6_addr.unspecified :> Cf_ip6_addr.opaque Cf_ip6_addr.t)
         in
-        to_sockaddr (any, 0)
+        to_sockaddr (any, 0, 0l)
 end
 
 type mreq_t = {

File cf/cf_ip6_proto.mli

 (** The address family module for IPv6 transports. *)
 module AF: Cf_socket.AF with
     type tag_t = [ `AF_INET6 ] and
-    type address_t = Cf_ip6_addr.opaque Cf_ip6_addr.t * int
+    type address_t = Cf_ip6_addr.opaque Cf_ip6_addr.t * int * int32
 
 (** The multicast request type *)
 type mreq_t = {

File cf/cf_ip6_proto_p.c

     sinAddr1Ptr = &Cf_socket_sockaddrx_val(in6, v1)->sx_sockaddr_in6;
     sinAddr2Ptr = &Cf_socket_sockaddrx_val(in6, v2)->sx_sockaddr_in6;
     
-    addr1Ptr = (u_int8_t*)(sinAddr1Ptr->sin6_addr.s6_addr) + 15;
-    addr2Ptr = (u_int8_t*)(sinAddr2Ptr->sin6_addr.s6_addr) + 15;
+    result = sinAddr1Ptr->sin6_scope_id - sinAddr2Ptr->sin6_scope_id;
+    if (result) goto done;
     
-    for (i = 16; i >= 0; --i, --addr1Ptr, --addr2Ptr) {
+    addr1Ptr = (u_int8_t*)(sinAddr1Ptr->sin6_addr.s6_addr);
+    addr2Ptr = (u_int8_t*)(sinAddr2Ptr->sin6_addr.s6_addr);
+    
+    for (i = 0; i < 16; ++i, ++addr1Ptr, ++addr2Ptr) {
         result = *addr1Ptr - *addr2Ptr;
         if (result) goto done;
     }
+        
+    addr1Ptr = (u_int8_t*) &(sinAddr1Ptr->sin6_port);
+    addr2Ptr = (u_int8_t*) &(sinAddr2Ptr->sin6_port);
     
-    addr1Ptr = (u_int8_t*) &(sinAddr1Ptr->sin6_port) + 1;
-    addr2Ptr = (u_int8_t*) &(sinAddr2Ptr->sin6_port) + 1;
-    
-    for (i = 2; i >= 0; --i, --addr1Ptr, --addr2Ptr) {
+    for (i = 0; i < 2; ++i, ++addr1Ptr, ++addr2Ptr) {
         result = *addr1Ptr - *addr2Ptr;
         if (result) goto done;
     }
     result = ntohs(sin6Ptr->sin6_port);
     p = (long*) &sin6Ptr->sin6_addr;
     for (i = 0; i < 4; ++i) result ^= ntohl(p[i]);
+    result ^= sin6Ptr->sin6_scope_id;
     
     CAMLreturn(result);
 }
     sin6Ptr = &Cf_socket_sockaddrx_val(in6, sxVal)->sx_sockaddr_in6;
     serialize_block_1(sin6Ptr->sin6_addr.s6_addr, 16);
     serialize_int_2(ntohs(sin6Ptr->sin6_port));
+    serialize_int_4(ntohl(sin6Ptr->sin6_scope_id));
     
     *size32Ptr = sizeof *sin6Ptr;
     *size64Ptr = sizeof *sin6Ptr;
     deserialize_block_1(sin6Ptr->sin6_addr.s6_addr, 16);
     sin6Ptr->sin6_port = deserialize_uint_2();
     sin6Ptr->sin6_port = htons(sin6Ptr->sin6_port);
+    sin6Ptr->sin6_scope_id = deserialize_uint_4();
+    sin6Ptr->sin6_scope_id = htonl(sin6Ptr->sin6_scope_id);
     
     return sizeof *sin6Ptr;
 }
 
 /*---
     external to_sockaddr:
-        Cf_ip6_addr.opaque Cf_ip6_addr.t * int ->
+        Cf_ip6_addr.opaque Cf_ip6_addr.t * int * int32 ->
         [`AF_INET6] Cf_socket.sockaddr_t = "cf_ip6_proto_to_sockaddr"
   ---*/
 CAMLprim value cf_ip6_proto_to_sockaddr(value addrVal)
     sin6.sin6_family = AF_INET6;
     sin6.sin6_port = htons(port);
     sin6.sin6_addr = *Cf_ip6_addr_val(Field(addrVal, 0));
+    sin6.sin6_scope_id = Int32_val(Field(addrVal, 2));
     
     resultVal =
         cf_ip6_proto_sockaddr_cons((struct sockaddr*) &sin6, sizeof sin6);
 /*---
     external of_sockaddr:
         [`AF_INET6] Cf_socket.sockaddr_t ->
-        Cf_ip6_addr.opaque Cf_ip6_addr.t * int = "cf_ip6_proto_of_sockaddr"
+        Cf_ip6_addr.opaque Cf_ip6_addr.t * int * int32
+          = "cf_ip6_proto_of_sockaddr"
   ---*/
 CAMLprim value cf_ip6_proto_of_sockaddr(value sxVal)
 {
     sin6Ptr = &sxPtr->sx_sockaddr_in6;
     addrVal = cf_ip6_addr_alloc(&sin6Ptr->sin6_addr);
     
-    resultVal = alloc_small(2, 0);
+    resultVal = alloc_small(3, 0);
     Store_field(resultVal, 0, addrVal);
     Store_field(resultVal, 1, Val_int(ntohs(sin6Ptr->sin6_port)));
+    Store_field(resultVal, 2, copy_int32(sin6Ptr->sin6_scope_id));
     
     CAMLreturn(resultVal);
 }