Little-endian version.
UNSAFE MODULEUin EXPORTSUin ;
Only unsafe because it needs Usocket.AF_INET and Usocket is unsafe.
FROM Utypes IMPORT u_long, u_short, u_char; IMPORT Usocket, Word; PROCEDUREIN_CLASSA (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_800000, 8)) = 0; END IN_CLASSA; PROCEDUREIN_CLASSB (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_c00000, 8)) = Word.Shift(16_800000, 8); END IN_CLASSB; PROCEDUREIN_CLASSC (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_e00000, 8)) = Word.Shift(16_c00000, 8); END IN_CLASSC; PROCEDUREIN_CLASSD (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_f00000, 8)) = Word.Shift(16_e00000, 8); END IN_CLASSD; PROCEDUREIN_MULTICAST (i: INTEGER): BOOLEAN = BEGIN RETURN IN_CLASSD(i); END IN_MULTICAST; PROCEDUREIN_EXPERIMENTAL (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_e00000, 8)) = Word.Shift(16_e00000, 8); END IN_EXPERIMENTAL; PROCEDUREIN_BADCLASS (i: INTEGER): BOOLEAN = BEGIN RETURN Word.And(i, Word.Shift(16_f00000, 8)) = Word.Shift(16_f00000, 8); END IN_BADCLASS; PROCEDUREIN_SET_LOOPBACK_ADDR (a: struct_sockaddr_in_star) = BEGIN a.sin_addr.s_addr := htonl(INADDR_LOOPBACK); a.sin_family := Usocket.AF_INET; END IN_SET_LOOPBACK_ADDR; TYPE A = RECORD a, b, c, d: u_char; END; B = RECORD d, c, b, a: u_char; END; C = RECORD a, b: u_char; END; D = RECORD b, a: u_char; END; PROCEDUREntohl (x: u_long): u_long = BEGIN RETURN LOOPHOLE (B { a := LOOPHOLE (x, A).a, b := LOOPHOLE (x, A).b, c := LOOPHOLE (x, A).c, d := LOOPHOLE (x, A).d}, u_long); END ntohl; PROCEDUREntohs (x: u_short): u_short = BEGIN RETURN LOOPHOLE (D { a := LOOPHOLE (x, C).a, b := LOOPHOLE (x, C).b}, u_short); END ntohs; PROCEDUREhtonl (x: u_long): u_long = BEGIN RETURN LOOPHOLE (A { a := LOOPHOLE (x, B).a, b := LOOPHOLE (x, B).b, c := LOOPHOLE (x, B).c, d := LOOPHOLE (x, B).d}, u_long); END htonl; PROCEDUREhtons (x: u_short): u_short = BEGIN RETURN LOOPHOLE (C { a := LOOPHOLE (x, D).a, b := LOOPHOLE (x, D).b}, u_short); END htons; BEGIN END Uin.