File: NetHostDB.c

package info (click to toggle)
mlton 20130715-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 60,900 kB
  • ctags: 69,386
  • sloc: xml: 34,418; ansic: 17,399; lisp: 2,879; makefile: 1,605; sh: 1,254; pascal: 256; python: 143; asm: 97
file content (61 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "platform.h"

static struct hostent *NetHostDB_hostent;

C_String_t NetHostDB_getEntryName(void) {
  return (C_String_t)(NetHostDB_hostent->h_name);
}

C_Int_t NetHostDB_getEntryAliasesNum(void) {
  int num = 0;
  while (NetHostDB_hostent->h_aliases[num] != NULL) num++;
  return num;
}

C_String_t NetHostDB_getEntryAliasesN(C_Int_t n) {
  return (C_String_t)(NetHostDB_hostent->h_aliases[n]);
}

C_Int_t NetHostDB_getEntryAddrType(void) {
  return NetHostDB_hostent->h_addrtype;
}

C_Int_t NetHostDB_getEntryLength(void) {
  return NetHostDB_hostent->h_length;
}

C_Int_t NetHostDB_getEntryAddrsNum(void) {
  int num = 0;
  while (NetHostDB_hostent->h_addr_list[num] != NULL) num++;
  return num;
}

void NetHostDB_getEntryAddrsN(C_Int_t n, Array(Word8_t) addr) {
  int i;
  for (i = 0; i < NetHostDB_hostent->h_length; i++) {
    ((char*)addr)[i] = NetHostDB_hostent->h_addr_list[n][i];
  }
  return;
}

C_Int_t NetHostDB_getByAddress(Vector(Word8_t) addr, C_Socklen_t len) {
  MLton_initSockets ();
  NetHostDB_hostent = gethostbyaddr((const char*)addr, len, AF_INET);
  return (C_Int_t)(NetHostDB_hostent != NULL and NetHostDB_hostent->h_name != NULL);
}

C_Int_t NetHostDB_getByName(NullString8_t name) {
  MLton_initSockets ();
  NetHostDB_hostent = gethostbyname((const char*)name);
  return (C_Int_t)(NetHostDB_hostent != NULL and NetHostDB_hostent->h_name != NULL);
}

C_Errno_t(C_Int_t) NetHostDB_getHostName(Array(Char8_t) buf, C_Size_t len) {
  int out;
  
  MLton_initSockets ();
  out = gethostname ((char*)buf, len);
  if (out == -1) MLton_fixSocketErrno ();
  
  return out;
}