UNSAFE MODULE; IMPORT Ctypes, IP, IPError, TCP, TCPPosix, Uin, Usocket; PROCEDURE TCPExtras LocalEndpoint (conn: TCP.T): IP.Endpoint RAISES {IP.Error} = VAR addr : Uin.struct_sockaddr_in; len : Ctypes.int := BYTESIZE (addr); ep : IP.Endpoint; BEGIN LOCK conn DO IF conn.closed THEN IPError.Raise (TCP.Closed); END; IF Usocket.getsockname (conn.fd, ADR (addr), ADR(len)) < 0 THEN IPError.RaiseUnexpected (); END; END; ep.addr := LOOPHOLE (addr.sin_addr, IP.Address); ep.port := Uin.ntohs (addr.sin_port); RETURN ep; END LocalEndpoint; PROCEDUREhtons (s: Ctypes.unsigned_short_int): Ctypes.unsigned_short_int = BEGIN RETURN Uin.htons (s); END htons; PROCEDUREntohs (s: Ctypes.unsigned_short_int): Ctypes.unsigned_short_int = BEGIN RETURN Uin.ntohs (s); END ntohs; BEGIN END TCPExtras.