Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / runtime / basis / Net / NetHostDB.c
CommitLineData
7f918cf1
CE
1#include "platform.h"
2
3static struct hostent *NetHostDB_hostent;
4
5C_String_t NetHostDB_getEntryName(void) {
6 return (C_String_t)(NetHostDB_hostent->h_name);
7}
8
9C_Int_t NetHostDB_getEntryAliasesNum(void) {
10 int num = 0;
11 while (NetHostDB_hostent->h_aliases[num] != NULL) num++;
12 return num;
13}
14
15C_String_t NetHostDB_getEntryAliasesN(C_Int_t n) {
16 return (C_String_t)(NetHostDB_hostent->h_aliases[n]);
17}
18
19C_Int_t NetHostDB_getEntryAddrType(void) {
20 return NetHostDB_hostent->h_addrtype;
21}
22
23C_Int_t NetHostDB_getEntryLength(void) {
24 return NetHostDB_hostent->h_length;
25}
26
27C_Int_t NetHostDB_getEntryAddrsNum(void) {
28 int num = 0;
29 while (NetHostDB_hostent->h_addr_list[num] != NULL) num++;
30 return num;
31}
32
33void NetHostDB_getEntryAddrsN(C_Int_t n, Array(Word8_t) addr) {
34 int i;
35 for (i = 0; i < NetHostDB_hostent->h_length; i++) {
36 ((char*)addr)[i] = NetHostDB_hostent->h_addr_list[n][i];
37 }
38 return;
39}
40
41C_Int_t NetHostDB_getByAddress(Vector(Word8_t) addr, C_Socklen_t len) {
42 MLton_initSockets ();
43 NetHostDB_hostent = gethostbyaddr((const char*)addr, len, AF_INET);
44 return (C_Int_t)(NetHostDB_hostent != NULL and NetHostDB_hostent->h_name != NULL);
45}
46
47C_Int_t NetHostDB_getByName(NullString8_t name) {
48 MLton_initSockets ();
49 NetHostDB_hostent = gethostbyname((const char*)name);
50 return (C_Int_t)(NetHostDB_hostent != NULL and NetHostDB_hostent->h_name != NULL);
51}
52
53C_Errno_t(C_Int_t) NetHostDB_getHostName(Array(Char8_t) buf, C_Size_t len) {
54 int out;
55
56 MLton_initSockets ();
57 out = gethostname ((char*)buf, len);
58 if (out == -1) MLton_fixSocketErrno ();
59
60 return out;
61}