Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / otherlibs / unix / addrofstr.c
blob5dfcf368d9e3c229e7e1bd7d6b81ce5c44765129
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
6 /* */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
11 /* */
12 /***********************************************************************/
14 /* $Id$ */
16 #include <mlvalues.h>
17 #include <fail.h>
18 #include "unixsupport.h"
20 #ifdef HAS_SOCKETS
22 #include "socketaddr.h"
24 CAMLprim value unix_inet_addr_of_string(value s)
26 #if defined(HAS_IPV6)
27 struct in_addr address;
28 struct in6_addr address6;
29 if (inet_pton(AF_INET, String_val(s), &address) > 0)
30 return alloc_inet_addr(&address);
31 else if (inet_pton(AF_INET6, String_val(s), &address6) > 0)
32 return alloc_inet6_addr(&address6);
33 else
34 failwith("inet_addr_of_string");
35 #elif defined(HAS_INET_ATON)
36 struct in_addr address;
37 if (inet_aton(String_val(s), &address) == 0)
38 failwith("inet_addr_of_string");
39 return alloc_inet_addr(&address);
40 #else
41 struct in_addr address;
42 address.s_addr = inet_addr(String_val(s));
43 if (address.s_addr == (uint32) -1) failwith("inet_addr_of_string");
44 return alloc_inet_addr(&address);
45 #endif
48 #else
50 CAMLprim value unix_inet_addr_of_string(value s)
51 { invalid_argument("inet_addr_of_string not implemented"); }
53 #endif