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 
21 union sock_addr_union {
22   struct sockaddr s_gen;
23   struct sockaddr_in s_inet;
24 #ifdef HAS_IPV6
25   struct sockaddr_in6 s_inet6;
26 #endif
27 };
28 
29 extern union sock_addr_union sock_addr;
30 
31 #ifdef HAS_SOCKLEN_T
32 typedef socklen_t socklen_param_type;
33 #else
34 typedef int socklen_param_type;
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 extern void get_sockaddr (value mladdr,
42                           union sock_addr_union * addr /*out*/,
43                           socklen_param_type * addr_len /*out*/);
44 CAMLprim value alloc_sockaddr (union sock_addr_union * addr /*in*/,
45                       socklen_param_type addr_len, int close_on_error);
46 CAMLprim value alloc_inet_addr (struct in_addr * inaddr);
47 #define GET_INET_ADDR(v) (*((struct in_addr *) (v)))
48 
49 #ifdef HAS_IPV6
50 CAMLexport value alloc_inet6_addr (struct in6_addr * inaddr);
51 #define GET_INET6_ADDR(v) (*((struct in6_addr *) (v)))
52 #endif
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #endif /* CAML_SOCKETADDR_H */
59