| 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 |
#ifdef _WIN32 |
| 22 |
|
| 23 |
/* Code duplication with runtime/debugger.c is inevitable, because |
| 24 |
* pulling winsock2.h creates many naming conflicts. */ |
| 25 |
#include <winsock2.h> |
| 26 |
#ifdef HAS_AFUNIX_H |
| 27 |
#include <afunix.h> |
| 28 |
#else |
| 29 |
#define UNIX_PATH_MAX 108 |
| 30 |
|
| 31 |
struct sockaddr_un { |
| 32 |
ADDRESS_FAMILY sun_family; |
| 33 |
char sun_path[UNIX_PATH_MAX]; |
| 34 |
}; |
| 35 |
|
| 36 |
#define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256) |
| 37 |
|
| 38 |
#endif |
| 39 |
|
| 40 |
#else |
| 41 |
#include <sys/types.h> |
| 42 |
#include <sys/socket.h> |
| 43 |
#include <sys/un.h> |
| 44 |
#include <netinet/in.h> |
| 45 |
#include <arpa/inet.h> |
| 46 |
#endif |
| 47 |
|
| 48 |
union sock_addr_union { |
| 49 |
struct sockaddr s_gen; |
| 50 |
struct sockaddr_un s_unix; |
| 51 |
struct sockaddr_in s_inet; |
| 52 |
#ifdef HAS_IPV6 |
| 53 |
struct sockaddr_in6 s_inet6; |
| 54 |
#endif |
| 55 |
}; |
| 56 |
|
| 57 |
#ifdef HAS_SOCKLEN_T |
| 58 |
typedef socklen_t socklen_param_type; |
| 59 |
#else |
| 60 |
typedef int socklen_param_type; |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifdef __cplusplus |
| 64 |
extern "C" { |
| 65 |
#endif |
| 66 |
|
| 67 |
/* Compatibility definitions for the pre-5.0 names of these functions */ |
| 68 |
#ifndef CAML_BUILDING_UNIX |
| 69 |
#define get_sockaddr caml_unix_get_sockaddr |
| 70 |
#define alloc_sockaddr caml_unix_alloc_sockaddr |
| 71 |
#define alloc_inet_addr caml_unix_alloc_inet_addr |
| 72 |
#endif /* CAML_BUILDING_UNIX */ |
| 73 |
|
| 74 |
extern void caml_unix_get_sockaddr (value mladdr, |
| 75 |
union sock_addr_union * addr /*out*/, |
| 76 |
socklen_param_type * addr_len /*out*/); |
| 77 |
extern value caml_unix_alloc_sockaddr (union sock_addr_union * addr /*in*/, |
| 78 |
socklen_param_type addr_len, |
| 79 |
int close_on_error); |
| 80 |
extern value caml_unix_alloc_inet_addr (struct in_addr * inaddr); |
| 81 |
#define GET_INET_ADDR(v) (*((struct in_addr *) (v))) |
| 82 |
|
| 83 |
#ifdef HAS_IPV6 |
| 84 |
extern value caml_unix_alloc_inet6_addr (struct in6_addr * inaddr); |
| 85 |
#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v))) |
| 86 |
|
| 87 |
/* Compatibility definition for the pre-5.0 name of this function */ |
| 88 |
#ifndef CAML_BUILDING_UNIX |
| 89 |
#define alloc_inet6_addr caml_unix_alloc_inet6_addr |
| 90 |
#endif /* CAML_BUILDING_UNIX */ |
| 91 |
#endif /* HAS_IPV6 */ |
| 92 |
|
| 93 |
#ifdef __cplusplus |
| 94 |
} |
| 95 |
#endif |
| 96 |
|
| 97 |
#endif /* CAML_SOCKETADDR_H */ |