Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / basis / Net / NetServDB.c
CommitLineData
7f918cf1
CE
1#include "platform.h"
2
3static struct servent *NetHostDB_servent;
4
5C_String_t NetServDB_getEntryName(void) {
6 return (C_String_t)(NetHostDB_servent->s_name);
7}
8
9C_Int_t NetServDB_getEntryAliasesNum(void) {
10 int num = 0;
11 while (NetHostDB_servent->s_aliases[num] != NULL) num++;
12 return num;
13}
14
15C_String_t NetServDB_getEntryAliasesN(C_Int_t n) {
16 return (C_String_t)(NetHostDB_servent->s_aliases[n]);
17}
18
19C_Int_t NetServDB_getEntryPort(void) {
20 return NetHostDB_servent->s_port;
21}
22
23C_String_t NetServDB_getEntryProto(void) {
24 return (C_String_t)(NetHostDB_servent->s_proto);
25}
26
27C_Int_t NetServDB_getByName(NullString8_t name, NullString8_t proto) {
28 NetHostDB_servent = getservbyname((const char*)name, (const char*)proto);
29 return (C_Int_t)(NetHostDB_servent != NULL and NetHostDB_servent->s_name != NULL);
30}
31
32C_Int_t NetServDB_getByNameNull(NullString8_t name) {
33 return NetServDB_getByName(name, (NullString8_t)NULL);
34}
35
36C_Int_t NetServDB_getByPort(C_Int_t port, NullString8_t proto) {
37 NetHostDB_servent = getservbyport(port, (const char*)proto);
38 return (C_Int_t)(NetHostDB_servent != NULL and NetHostDB_servent->s_name != NULL);
39}
40
41C_Int_t NetServDB_getByPortNull(C_Int_t port) {
42 return NetServDB_getByPort(port, (NullString8_t)NULL);
43}