summaryrefslogtreecommitdiff
path: root/otherlibs/unix/socketaddr.h
blob: 768669d0cc10a7adf7b76762fa27e27a2ac46eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**************************************************************************/
/*                                                                        */
/*                                 OCaml                                  */
/*                                                                        */
/*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           */
/*                                                                        */
/*   Copyright 1996 Institut National de Recherche en Informatique et     */
/*     en Automatique.                                                    */
/*                                                                        */
/*   All rights reserved.  This file is distributed under the terms of    */
/*   the GNU Lesser General Public License version 2.1, with the          */
/*   special exception on linking described in the file LICENSE.          */
/*                                                                        */
/**************************************************************************/

#ifndef CAML_SOCKETADDR_H
#define CAML_SOCKETADDR_H

#include "caml/misc.h"

#ifdef _WIN32

/* Code duplication with runtime/debugger.c is inevitable, because
 * pulling winsock2.h creates many naming conflicts. */
#include <winsock2.h>
#ifdef HAS_AFUNIX_H
#include <afunix.h>
#else
#define UNIX_PATH_MAX 108

struct sockaddr_un {
  ADDRESS_FAMILY sun_family;
  char sun_path[UNIX_PATH_MAX];
};

#define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256)

#endif

#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif

union sock_addr_union {
  struct sockaddr s_gen;
  struct sockaddr_un s_unix;
  struct sockaddr_in s_inet;
#ifdef HAS_IPV6
  struct sockaddr_in6 s_inet6;
#endif
};

#ifdef HAS_SOCKLEN_T
typedef socklen_t socklen_param_type;
#else
typedef int socklen_param_type;
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* Compatibility definitions for the pre-5.0 names of these functions */
#ifndef CAML_BUILDING_UNIX
#define get_sockaddr caml_unix_get_sockaddr
#define alloc_sockaddr caml_unix_alloc_sockaddr
#define alloc_inet_addr caml_unix_alloc_inet_addr
#endif /* CAML_BUILDING_UNIX */

extern void caml_unix_get_sockaddr (value mladdr,
                               union sock_addr_union * addr /*out*/,
                               socklen_param_type * addr_len /*out*/);
extern value caml_unix_alloc_sockaddr (union sock_addr_union * addr /*in*/,
                                  socklen_param_type addr_len,
                                  int close_on_error);
extern value caml_unix_alloc_inet_addr (struct in_addr * inaddr);
#define GET_INET_ADDR(v) (*((struct in_addr *) (v)))

#ifdef HAS_IPV6
extern value caml_unix_alloc_inet6_addr (struct in6_addr * inaddr);
#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v)))

/* Compatibility definition for the pre-5.0 name of this function */
#ifndef CAML_BUILDING_UNIX
#define alloc_inet6_addr caml_unix_alloc_inet6_addr
#endif /* CAML_BUILDING_UNIX */
#endif /* HAS_IPV6 */

#ifdef __cplusplus
}
#endif

#endif /* CAML_SOCKETADDR_H */