While using Windows' API functions InetNtopW and InetPtonW I made comment in my post demonstrating those functions that IMO (In My Opinion) the UNIONs for the numeric/binary form of IP numbers are overly complicated. I also found a couple out-of-date REMs in the #INCLUDE files.
struct in_addr {
union {
struct {
u_char s_b1;
u_char s_b2;
u_char s_b3;
u_char s_b4;
} S_un_b;
struct {
u_short s_w1;
u_short s_w2;
} S_un_w;
u_long S_addr;
} S_un;
};
typedef struct in6_addr {
union {
u_char Byte[16];
u_short Word[8];
} u;
} IN6_ADDR, *PIN6_ADDR, FAR *LPIN6_ADDR;
TYPE IN_ADDR_union_type1
s_b1 AS BYTE
s_b2 AS BYTE
s_b3 AS BYTE
s_b4 AS BYTE
END TYPE
TYPE IN_ADDR_union_type2
s_w1 AS WORD
s_w2 AS WORD
END TYPE
UNION IN_ADDR_union
S_un_b AS IN_ADDR_union_type1
S_un_w AS IN_ADDR_union_type2
S_addr AS DWORD
END UNION
TYPE IN_ADDR
S_un AS IN_ADDR_union
END TYPE
MACROs that ref IMP REMed out, see below my comments.
UNION IN6_ADDR_union
nByte(15) AS BYTE
nWord(7) AS WORD
END UNION
TYPE IN6_ADDR
u AS IN6_ADDR_union
END TYPE
TYPE in_addr6
in6_addr
END TYPE
MACRO s6_bytes = u.Byte
MACRO s6_words = u.Word
' // Size = 4 bytes TYPE S_un_b_type BYTE s_b1 AS BYTE s_b2 AS BYTE s_b3 AS BYTE s_b4 AS BYTE END TYPE ' // Size = 4 bytes TYPE S_un_w_type WORD s_w1 AS WORD s_w2 AS WORD END TYPE ' // Size = 4 bytes UNION S_un S_un_b AS S_un_b_type S_un_w AS S_un_w_type S_addr AS DWORD s AS STRING * 4 END UNION ' // Size = 4 bytes UNION in_addr S_un S_un AS S_un END UNION ' can be used for most tcp & ip code MACRO s_addrm = S_un.S_addr ' host on imp MACRO s_hostm = S_Un.S_un_b.s_b2 ' network MACRO s_netm = S_Un.S_un_b.s_b1 ' imp MACRO s_impm = S_un.S_un_w.s_w2 ' imp # MACRO s_impnom = S_un.S_un_b.s_b4 ' logical host MACRO s_lhm = S_un.S_un_b.s_b3
UNION IN6_ADDR_UNION BYTE Byte(15) AS BYTE Word(7) AS WORD nByte(15) AS BYTE nWord(7) AS WORD END UNION MACRO S6_un = IN6_ADDR_UNION UNION IN6_ADDR_UNION_2 BYTE IN6_ADDR_UNION u AS IN6_ADDR_UNION END UNION ' // Size = 16 bytes TYPE in6_addr BYTE IN6_ADDR_UNION_2 END TYPE '#define in_addr6 in6_addr MACRO in_addr6 = in6_addr '// '// Defines to match RFC 2553. '// '#define _S6_un u '#define _S6_u8 Byte '#define s6_addr _S6_un._S6_u8 '// '// Defines for our implementation. '// '#define s6_bytes u.Byte '#define s6_words u.Word MACRO s6_bytes = u.Byte MACRO s6_words = u.Word
UNION IN4_Addr DWORD byt(3) AS BYTE 'zero based index dwd AS DWORD 'beware endian str AS STRING * 4 'not text, string of bytes END UNION ' UNION IN6_Addr QWORD '(64 bit OS?, ignored in 32) byt(15) AS BYTE 'zero based index wrd(7) AS WORD 'beware endian str AS STRING * 16 'not text, string of bytes END UNION
Why keep in two files? I suggest they be put in Ws2Def.inc with ADDRINFOW and ADDRINFOEXW ("A" versions should be considered legacy IMO).
Created on 15 February 2024.
To Dale's Notebook
| To Programs
|