Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamlnet: EAFNOSUPPORT on Max OSX
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: Solved! (was Re: Mac OSX getsocketpair/getsockname and IPv6)
The culprit is in alloc_sockaddr [1].

adr->s_gen.sa_family is 0 which stands for AF_UNSPEC in my /usr/ 
include/sys/socket.h.

alloc_sockaddr does not handle this family type and throws EAFNOSUPPORT.

I'm inclined to think that ocamlnet should be fixed and not the OCaml  
library, although it would be helpful if an error different from  
EAFNOSUPPORT was used.

I would have been most helpful to have a stack trace on exception as  
this would have allowed me to narrow down the source of the problem  
in no time rather than going spelunking through ocamlnet and OCaml  
networking libraries.

	Thanks, Joel

[1] otherlibs/unix/socketaddr.c

value alloc_sockaddr(union sock_addr_union * adr /*in*/,
                      socklen_param_type adr_len, int close_on_error)
{
   value res;
   switch(adr->s_gen.sa_family) {
#ifndef _WIN32
   case AF_UNIX:
     { value n = copy_string(adr->s_unix.sun_path);
       Begin_root (n);
         res = alloc_small(1, 0);
         Field(res,0) = n;
       End_roots();
       break;
     }
#endif
   case AF_INET:
     { value a = alloc_inet_addr(&adr->s_inet.sin_addr);
       Begin_root (a);
         res = alloc_small(2, 1);
         Field(res,0) = a;
         Field(res,1) = Val_int(ntohs(adr->s_inet.sin_port));
       End_roots();
       break;
     }
#ifdef HAS_IPV6
   case AF_INET6:
     { value a = alloc_inet6_addr(&adr->s_inet6.sin6_addr);
       Begin_root (a);
         res = alloc_small(2, 1);
         Field(res,0) = a;
         Field(res,1) = Val_int(ntohs(adr->s_inet6.sin6_port));
       End_roots();
       break;
     }
#endif
   default:
     if (close_on_error != -1) close (close_on_error);
     unix_error(EAFNOSUPPORT, "", Nothing);
   }
   return res;
}

--
http://wagerlabs.com/