File: NetHostDB.c

package info (click to toggle)
mlton 20061107-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,828 kB
  • ctags: 61,118
  • sloc: ansic: 11,446; makefile: 1,339; sh: 1,160; lisp: 900; pascal: 256; asm: 97
file content (53 lines) | stat: -rw-r--r-- 1,248 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
#include "platform.h"

static struct hostent *hostent;

Cstring NetHostDB_Entry_name() {
        return (Cstring)hostent->h_name;
}

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

Cstring NetHostDB_Entry_aliasesN(Int n) {
        return (Cstring)hostent->h_aliases[n];
}

Int NetHostDB_Entry_addrType() {
        return hostent->h_addrtype;
}

Int NetHostDB_Entry_length() {
        return hostent->h_length;
}

Int NetHostDB_Entry_numAddrs() {
        int num = 0;
        while (hostent->h_addr_list[num] != NULL) num++;
        return num;
}

void NetHostDB_Entry_addrsN(Int n, Pointer addr) {
        int i;
        for (i = 0; i < hostent->h_length; i++) {
                addr[i] = hostent->h_addr_list[n][i];
        }
        return;
}

Bool NetHostDB_getByAddress(Pointer addr, Int len) {
        hostent = gethostbyaddr(addr, len, AF_INET);
        return (hostent != NULL and hostent->h_name != NULL);
}

Bool NetHostDB_getByName(Cstring name) {
        hostent = gethostbyname((char*)name);
        return (hostent != NULL and hostent->h_name != NULL);
}

Int NetHostDB_getHostName(Pointer buf, Int len) {
        return (gethostname (buf, len));
}