1(*
2    Title:      Standard Basis Library: NetProtDB Structures and Signatures
3    Author:     David Matthews
4    Copyright   David Matthews 2000, 2016
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License version 2.1 as published by the Free Software Foundation.
9    
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14    
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18*)
19
20signature NET_PROT_DB =
21sig
22    type entry
23    val name : entry -> string
24    val aliases : entry -> string list
25    val protocol : entry -> int
26    val getByName : string -> entry option
27    val getByNumber : int -> entry option
28end;
29
30structure NetProtDB :> NET_PROT_DB =
31struct
32    type entry = string * string list * int
33    
34    (* The RTS calls return either zero or the address of the entry. *)
35    datatype result = AResult of entry | NoResult
36
37    val name: entry -> string = #1
38    val aliases : entry -> string list = #2
39    val protocol : entry -> int = #3
40
41    local
42        val doCall: string -> result = RunCall.rtsCallFull1 "PolyNetworkGetProtByName"
43    in
44        fun getByName s =
45            case doCall s of AResult r => SOME r | NoResult => NONE
46    end
47
48    local
49        val doCall: int -> result = RunCall.rtsCallFull1 "PolyNetworkGetProtByNo"
50    in
51        fun getByNumber n =
52            case doCall n of AResult r => SOME r | NoResult => NONE
53    end
54
55end;
56