| 1 |
(* Copyright (C) 2002-2006 Henry Cejtin, Matthew Fluet, Suresh |
| 2 |
* Jagannathan, and Stephen Weeks. |
| 3 |
* |
| 4 |
* MLton is released under a HPND-style license. |
| 5 |
* See the file MLton-LICENSE for details. |
| 6 |
*) |
| 7 |
|
| 8 |
structure NetProtDB: NET_PROT_DB = |
| 9 |
struct |
| 10 |
structure Prim = PrimitiveFFI.NetProtDB |
| 11 |
|
| 12 |
datatype entry = T of {name: string, |
| 13 |
aliases: string list, |
| 14 |
protocol: C_Int.t} |
| 15 |
|
| 16 |
local |
| 17 |
fun make s (T r) = s r |
| 18 |
in |
| 19 |
val name = make #name |
| 20 |
val aliases = make #aliases |
| 21 |
val protocol = C_Int.toInt o (make #protocol) |
| 22 |
end |
| 23 |
|
| 24 |
local |
| 25 |
fun get (i: C_Int.t): entry option = |
| 26 |
if i <> C_Int.zero |
| 27 |
then let |
| 28 |
val name = CUtil.C_String.toString (Prim.getEntryName ()) |
| 29 |
val numAliases = Prim.getEntryAliasesNum () |
| 30 |
fun fill (n, aliases) = |
| 31 |
if C_Int.< (n, numAliases) |
| 32 |
then let |
| 33 |
val alias = CUtil.C_String.toString (Prim.getEntryAliasesN n) |
| 34 |
in |
| 35 |
fill (C_Int.+ (n, 1), alias::aliases) |
| 36 |
end |
| 37 |
else List.rev aliases |
| 38 |
val aliases = fill (0, []) |
| 39 |
val protocol = Prim.getEntryProto () |
| 40 |
in |
| 41 |
SOME (T {name = name, |
| 42 |
aliases = aliases, |
| 43 |
protocol = protocol}) |
| 44 |
end |
| 45 |
else NONE |
| 46 |
in |
| 47 |
fun getByName name = |
| 48 |
get (Prim.getByName (NullString.nullTerm name)) |
| 49 |
fun getByNumber proto = |
| 50 |
get (Prim.getByNumber (C_Int.fromInt proto)) |
| 51 |
end |
| 52 |
end |