Ipv6.icl 1.08 KB
Newer Older
Mart Lubbers's avatar
Mart Lubbers committed
1 2 3 4 5 6 7 8
implementation module System.Socket.Ipv6

import StdEnv
import Data.Error
import Data.Maybe
import System.Socket
import System._Pointer
import Text.GenPrint
Mart Lubbers's avatar
Mart Lubbers committed
9
from System._Socket import AF_INET6
Mart Lubbers's avatar
Mart Lubbers committed
10

Mart Lubbers's avatar
Mart Lubbers committed
11
instance SocketAddress Ipv6SocketAddress where
Mart Lubbers's avatar
Mart Lubbers committed
12
	sa_serialize sa p w
Camil Staps's avatar
Camil Staps committed
13
		# p = writeInt2 p 0 (sa_domain sa)
Mart Lubbers's avatar
Mart Lubbers committed
14 15 16 17
		# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.ipv6_socket_port)
		# p = writeInt4 p 4 (sa.ipv6_socket_flowinfo)
		# p = writeCharArray (p+8) (pad16 (fromMaybe "::" sa.ipv6_socket_addr))
		# p = writeInt4 p 24 (sa.ipv6_socket_scope_id)
Camil Staps's avatar
Camil Staps committed
18
		= (p, w)
Mart Lubbers's avatar
Mart Lubbers committed
19 20 21
	where
		pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]}
	sa_deserialize p = Ok
Mart Lubbers's avatar
Mart Lubbers committed
22 23 24 25
		{ ipv6_socket_port     = networkToHostByteOrderShort (readInt2Z p 2)
		, ipv6_socket_flowinfo = readInt4Z p 4
		, ipv6_socket_addr     = Just (derefCharArray (p+8) 16)
		, ipv6_socket_scope_id = readInt4Z p 24
Mart Lubbers's avatar
Mart Lubbers committed
26 27
		}
	sa_length _ = 28
Mart Lubbers's avatar
Mart Lubbers committed
28
	sa_domain _ = AF_INET6
Mart Lubbers's avatar
Mart Lubbers committed
29
	sa_null = {ipv6_socket_port=0,ipv6_socket_flowinfo=0,ipv6_socket_addr=Nothing,ipv6_socket_scope_id=0}
Mart Lubbers's avatar
Mart Lubbers committed
30

Mart Lubbers's avatar
Mart Lubbers committed
31 32
derive gPrint Ipv6SocketAddress, Maybe
instance toString Ipv6SocketAddress where toString s = printToString s