1 /**************************************************************************/ 2 /* */ 3 /* OCaml */ 4 /* */ 5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ 6 /* */ 7 /* Copyright 1996 Institut National de Recherche en Informatique et */ 8 /* en Automatique. */ 9 /* */ 10 /* All rights reserved. This file is distributed under the terms of */ 11 /* the GNU Lesser General Public License version 2.1, with the */ 12 /* special exception on linking described in the file LICENSE. */ 13 /* */ 14 /**************************************************************************/ 15 16 #ifndef CAML_SOCKETADDR_H 17 #define CAML_SOCKETADDR_H 18 19 #include "caml/misc.h" 20 #include <sys/types.h> 21 #include <sys/socket.h> 22 #include <sys/un.h> 23 #include <netinet/in.h> 24 #include <arpa/inet.h> 25 26 union sock_addr_union { 27 struct sockaddr s_gen; 28 struct sockaddr_un s_unix; 29 struct sockaddr_in s_inet; 30 #ifdef HAS_IPV6 31 struct sockaddr_in6 s_inet6; 32 #endif 33 }; 34 35 #ifdef HAS_SOCKLEN_T 36 typedef socklen_t socklen_param_type; 37 #else 38 typedef int socklen_param_type; 39 #endif 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 extern void get_sockaddr (value mladdr, 46 union sock_addr_union * addr /*out*/, 47 socklen_param_type * addr_len /*out*/); 48 CAMLexport value alloc_sockaddr (union sock_addr_union * addr /*in*/, 49 socklen_param_type addr_len, int close_on_error); 50 CAMLexport value alloc_inet_addr (struct in_addr * inaddr); 51 #define GET_INET_ADDR(v) (*((struct in_addr *) (v))) 52 53 #ifdef HAS_IPV6 54 CAMLexport value alloc_inet6_addr (struct in6_addr * inaddr); 55 #define GET_INET6_ADDR(v) (*((struct in6_addr *) (v))) 56 #endif 57 58 #ifdef __cplusplus 59 } 60 #endif 61 62 #endif /* CAML_SOCKETADDR_H */ 63