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
|
(* Copyright (C) 2002-2006 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
*
* MLton is released under a HPND-style license.
* See the file MLton-LICENSE for details.
*)
structure NetProtDB: NET_PROT_DB =
struct
structure Prim = PrimitiveFFI.NetProtDB
datatype entry = T of {name: string,
aliases: string list,
protocol: C_Int.t}
local
fun make s (T r) = s r
in
val name = make #name
val aliases = make #aliases
val protocol = C_Int.toInt o (make #protocol)
end
local
fun get (i: C_Int.t): entry option =
if i <> C_Int.zero
then let
val name = CUtil.C_String.toString (Prim.getEntryName ())
val numAliases = Prim.getEntryAliasesNum ()
fun fill (n, aliases) =
if C_Int.< (n, numAliases)
then let
val alias = CUtil.C_String.toString (Prim.getEntryAliasesN n)
in
fill (C_Int.+ (n, 1), alias::aliases)
end
else List.rev aliases
val aliases = fill (0, [])
val protocol = Prim.getEntryProto ()
in
SOME (T {name = name,
aliases = aliases,
protocol = protocol})
end
else NONE
in
fun getByName name =
get (Prim.getByName (NullString.nullTerm name))
fun getByNumber proto =
get (Prim.getByNumber (C_Int.fromInt proto))
end
end
|