Ipv4.icl 797 Bytes
Newer Older
Mart Lubbers's avatar
Mart Lubbers committed
1 2 3 4 5 6 7 8 9
implementation module System.Socket.Ipv4

import StdEnv
import Network.IP
import Data.Error
import System.Socket
import System._Pointer
import Text.GenPrint

Mart Lubbers's avatar
Mart Lubbers committed
10
instance SocketAddress Ipv4SocketAddress where
Mart Lubbers's avatar
Mart Lubbers committed
11
	sa_serialize sa p w
Camil Staps's avatar
Camil Staps committed
12
		# p = writeInt2 p 0 (sa_domain sa)
Mart Lubbers's avatar
Mart Lubbers committed
13 14
		# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.ipv4_socket_port)
		# p = writeInt4 p 4 (maybe 0 toInt sa.ipv4_socket_addr)
Camil Staps's avatar
Camil Staps committed
15
		= (p, w)
Mart Lubbers's avatar
Mart Lubbers committed
16
	sa_deserialize p
Mart Lubbers's avatar
Mart Lubbers committed
17
		= Ok {ipv4_socket_port=networkToHostByteOrderShort (readInt2Z p 2),ipv4_socket_addr=Just (fromInt (readInt4Z p 4))}
Mart Lubbers's avatar
Mart Lubbers committed
18 19
	sa_length _ = 16
	sa_domain _ = 2
Mart Lubbers's avatar
Mart Lubbers committed
20
	sa_null = {ipv4_socket_port=0, ipv4_socket_addr=Nothing}
Mart Lubbers's avatar
Mart Lubbers committed
21 22

gPrint{|IPAddress|} a s = gPrint{|*|} (toString a) s
Mart Lubbers's avatar
Mart Lubbers committed
23 24
derive gPrint Ipv4SocketAddress, Maybe
instance toString Ipv4SocketAddress where toString s = printToString s