In a network environment, the code sets of the communicating systems and the protocols of communication determine the transformation of user-specified data so that it can be sent to the remote system in a meaningful way. The user data (not user names) may need to be transformed from the sender's code set to the receiver's code set, or 8-bit data may need to be transformed into a 7-bit form to conform to protocols. A uniform interface is needed to accomplish this.
In the following examples, using the iconv() interface is illustrated by explaining how to use iconv_open(), iconv(), and iconv_close(). To do the conversion, iconv_open() must be followed by iconv(). The terms 7-bit interchange and 8-bit interchange are used to refer to any interchange encoding used for 7-bit and 8-bit data, respectively.
If the protocol allows 8-bit data, use 8-bit data because the same code set is being used. No conversion is needed.
If the protocol allows only 7-bit data, use iconv():
If the protocol allows 8-bit data:
Sender
cd = iconv_open(locale_codeset, 8-bitinterchange );
Receiver
cd = iconv_open(8-bitinterchange, locale_codeset );
If the protocol allows only 7-bit data, do the following:
Sender
cd = iconv_open(locale_codeset, 7-bitinterchange );
Receiver
cd = iconv_open(7-bitinterchange, locale_codeset );
The locale_codeset() refers to the code set used locally by the application. It is implementation-dependent whether any conversion names match the return from the nl_langinfo()(CODESET) function. Table 3-1 outlines how the use of iconv() to perform conversions for various conditions. Specific protocols may dictate other conversions needed.
Table 3-1 Using iconv to Perform Conversions