]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/unix/strofaddr.c
Inital import
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / unix / strofaddr.c
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 /***********************************************************************/
13
14 /* $Id: strofaddr.c 6824 2005-03-24 17:20:54Z doligez $ */
15
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <fail.h>
19 #include "unixsupport.h"
20
21 #ifdef HAS_SOCKETS
22
23 #include "socketaddr.h"
24
25 CAMLprim value unix_string_of_inet_addr(value a)
26 {
27   char * res;
28 #ifdef HAS_IPV6
29   char buffer[64];
30   if (string_length(a) == 16)
31     res = (char *)
32       inet_ntop(AF_INET6, (const void *) &GET_INET6_ADDR(a),
33                 buffer, sizeof(buffer));
34   else
35     res = (char *)
36       inet_ntop(AF_INET, (const void *) &GET_INET_ADDR(a),
37                 buffer, sizeof(buffer));
38 #else
39   res = inet_ntoa(GET_INET_ADDR(a));
40 #endif
41   if (res == NULL) uerror("string_of_inet_addr", Nothing);
42   return copy_string(res);
43 }
44
45 #else
46
47 CAMLprim value unix_string_of_inet_addr(value a)
48 { invalid_argument("string_of_inet_addr not implemented"); }
49
50 #endif