File: NetHostDB.c

package info (click to toggle)
mlton 20070826-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 33,184 kB
  • ctags: 70,419
  • sloc: ansic: 16,154; lisp: 2,727; makefile: 1,635; sh: 1,234; pascal: 256; asm: 97
file content (56 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download
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
#include "platform.h"

static struct hostent *hostent;

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

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

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

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

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

C_Int_t NetHostDB_getEntryAddrsNum(void) {
  int num = 0;
  while (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 < hostent->h_length; i++) {
    ((char*)addr)[i] = hostent->h_addr_list[n][i];
  }
  return;
}

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

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

C_Errno_t(C_Int_t) NetHostDB_getHostName(Array(Char8_t) buf, C_Size_t len) {
  MLton_initSockets ();
  return gethostname ((char*)buf, len);
}