Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/system/Basis/Implementation/Sockets/host-db.sml
ViewVC logotype

Diff of /sml/trunk/src/system/Basis/Implementation/Sockets/host-db.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1393, Fri Sep 26 17:00:32 2003 UTC revision 1394, Fri Sep 26 19:56:20 2003 UTC
# Line 6  Line 6 
6    
7  local  local
8      structure Word8 = Word8Imp      structure Word8 = Word8Imp
     structure SysWord = SysWordImp  
9  in  in
10  structure NetHostDB : NET_HOST_DB =  structure NetHostDBInternal :> sig
11    struct      (* export extra element for internal use by Basis implementation *)
12        include NET_HOST_DB
13        val INADDR : Socket.addr -> in_addr
14        val unINADDR : in_addr -> Socket.addr
15    end
16      where type addr_family = Socket.AF.addr_family
17    = struct
18    
19      structure SysW = SysWord      structure SysW = SysWordImp
20    
21      fun netdbFun x = CInterface.c_function "SMLNJ-Sockets" x      fun netdbFun x = CInterface.c_function "SMLNJ-Sockets" x
22    
23      type in_addr = Socket.in_addr      datatype in_addr = INADDR of Socket.addr
24      type addr_family = Socket.AF.addr_family      type addr_family = Socket.AF.addr_family
25    
26        fun unINADDR (INADDR a) = a
27    
28      datatype entry = HOSTENT of {      datatype entry = HOSTENT of {
29            name : string,            name : string,
30            aliases : string list,            aliases : string list,
# Line 42  Line 49 
49          | getHostEnt (SOME(name, aliases, addrType, addrs)) = SOME(HOSTENT{          | getHostEnt (SOME(name, aliases, addrType, addrs)) = SOME(HOSTENT{
50                name = name, aliases = aliases,                name = name, aliases = aliases,
51                addrType = Socket.AF.AF addrType,                addrType = Socket.AF.AF addrType,
52                addrs = List.map Socket.INADDR addrs                addrs = List.map INADDR addrs
53              })              })
54        val getHostByName' : string -> hostent option = netdbFun "getHostByName"        val getHostByName' : string -> hostent option = netdbFun "getHostByName"
55        val getHostByAddr' : Socket.addr -> hostent option = netdbFun "getHostByAddr"        val getHostByAddr' : Socket.addr -> hostent option = netdbFun "getHostByAddr"
56      in      in
57      val getByName = getHostEnt o getHostByName'      val getByName = getHostEnt o getHostByName'
58      fun getByAddr (Socket.INADDR addr) = getHostEnt(getHostByAddr' addr)      fun getByAddr (INADDR addr) = getHostEnt(getHostByAddr' addr)
59      end (* local *)      end (* local *)
60    
61      fun scan getc strm = let      fun scan getc strm = let
62            fun w2b w = Word8.fromLargeWord(SysW.toLargeWord w)            fun w2b w = Word8.fromLargeWord(SysW.toLargeWord w)
63            fun getB (w, shft) = SysW.andb(SysW.>>(w, shft), 0wxFF)            fun getB (w, shft) = SysW.andb(SysW.>>(w, shft), 0wxFF)
64            fun mkAddr (a, b, c, d) = Socket.INADDR(Word8Vector.fromList[            fun mkAddr (a, b, c, d) = INADDR(Word8Vector.fromList[
65                    w2b a, w2b b, w2b c, w2b d                    w2b a, w2b b, w2b c, w2b d
66                  ])                  ])
67            in            in
# Line 73  Line 80 
80    
81      val fromString = StringCvt.scanString scan      val fromString = StringCvt.scanString scan
82    
83      fun toString (Socket.INADDR addr) = let      fun toString (INADDR addr) = let
84            fun get i = Word8Vector.sub(addr, i)            fun get i = Word8Vector.sub(addr, i)
85            in            in
86              Socket.fromBytes(get 0, get 1, get 2, get 3)              Socket.fromBytes(get 0, get 1, get 2, get 3)
# Line 82  Line 89 
89      val getHostName : unit -> string = netdbFun "getHostName"      val getHostName : unit -> string = netdbFun "getHostName"
90    
91    end    end
 end  
92    
93    (* restrict to NET_HOST_DB *)
94    structure NetHostDB : NET_HOST_DB = NetHostDBInternal
95    
96    end

Legend:
Removed from v.1393  
changed lines
  Added in v.1394

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0