If you use the address conversion functions described above, you will seldom have to directly handle addresses in an Internet user program. You can then develop services that are independent of networks to a large degree. However, some network dependency still remains as the IPv4 or IPv6 address has to be specified in a user program if a name is assigned to a service or socket.
In addition to the library functions for converting names to addresses, there are also macros which simplify handling names and addresses.
The host byte order and network byte order differ in some architectures. Because of this, programs sometimes have to change the byte order. The macros summarized in the following table convert long and short integer values from host byte order to network byte order and vice versa.
Call | Meaning |
htonl(val) | Convert 32-bit fields from host byte order to network byte order |
Table 1: Library macros for converting byte orders
The byte order conversion macros are needed because the library functions expect IPv4 addresses and port numbers in network byte order. The library functions that return network addresses supply them in network byte order, so they can be easily copied into data structures passed to other library functions when called.
However, problems can arise when interpreting network addresses.
With IPv6 addresses, there is by definition no difference between host byte order and network byte order, and there is therefore no corresponding conversion function.
The host and network byte orders are identical in BS2000. The macros listed in the table are therefore defined as null macros (macros without contents). However, it is strongly recommended that you use the macros for creating portable programs.