1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
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. */
12 /***********************************************************************/
20 #include "unixsupport.h"
24 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
34 static value
alloc_service_entry(struct servent
*entry
)
37 value name
= Val_unit
, aliases
= Val_unit
, proto
= Val_unit
;
39 Begin_roots3 (name
, aliases
, proto
);
40 name
= copy_string(entry
->s_name
);
41 aliases
= copy_string_array((const char**)entry
->s_aliases
);
42 proto
= copy_string(entry
->s_proto
);
43 res
= alloc_small(4, 0);
45 Field(res
,1) = aliases
;
46 Field(res
,2) = Val_int(ntohs(entry
->s_port
));
52 CAMLprim value
unix_getservbyname(value name
, value proto
)
54 struct servent
* entry
;
55 entry
= getservbyname(String_val(name
), String_val(proto
));
56 if (entry
== (struct servent
*) NULL
) raise_not_found();
57 return alloc_service_entry(entry
);
60 CAMLprim value
unix_getservbyport(value port
, value proto
)
62 struct servent
* entry
;
63 entry
= getservbyport(htons(Int_val(port
)), String_val(proto
));
64 if (entry
== (struct servent
*) NULL
) raise_not_found();
65 return alloc_service_entry(entry
);
70 CAMLprim value
unix_getservbyport(value port
, value proto
)
71 { invalid_argument("getservbyport not implemented"); }
73 CAMLprim value
unix_getservbyname(value name
, value proto
)
74 { invalid_argument("getservbyname not implemented"); }