dklibs(3)

NAME
dkenc - Encoding module

SYNOPSIS
  #include <dkenc.h>

  unsigned long   dkenc_ntohl(unsigned long);
  unsigned long   dkenc_htonl(unsigned long);
  unsigned short  dkenc_ntohs(unsigned short);
  unsigned short  dkenc_htons(unsigned short);

  int
  dkenc_utf82uc(dk_unicodechar *ucp, dk_utf8 *u8p, int u8l, int *u8u);
  int  dkenc_uc2utf8(dk_unicodechar c, dk_utf8 *u8p, int u8l);
  int  dkenc_ipaddr_to_ul(char *str, unsigned long *ul);

DESCRIPTION
dkenc_ntohl(), dkenc_htonl(), dkenc_ntohs() and dkenc_htons() convert long (32 bit) and short (16 bit) unsigned integers between host and net representation. ntoh means net-to-host, hton means host-to-net, l or s means long or short.

On most systems there are functions ntohl(), htonl(), ntohs() and htons() available. Unfortunately some systems have all TCP/IP related functions in one DLL. This DLL must be initialized by calling a WSAStartup() function before using any other function. To avoid initializing that library (which might end up in establishing an Internet connection the user has to pay for) it is recommended to use these replacement function.

The dk_unicodechar data type is a 32 bit word used for direct representation of UNICODE characters.

The dkenc_utf82uc() function converts a byte array of UTF8-encoded characters into one direct UNICODE double-word. The u8p argument points to the UTF8-encoded array, u8l specifies the length of the array. u8u points to a variable, the number of UTF8-bytes used is stored in that variable. The ucp argument points to a variable to store the 32-bit UNICODE result. Only one UNICODE character is converted by each call to dkenc_utf82uc(). Converting an array of UTF8-bytes into an array of 32-bit UNICODE characters requires multiple calls to dkenc_utf82uc(). After a sucessfull call to dkenc_utf82uc() the UTF8-representation of the next UNICODE character begins x=(*u8u) bytes after the beginning of the current representation.

The dkenc_uc2utf8() function converts a UNICODE character into the appropriate UTF8-representation. The c argument is the UNICODE character, u8p points to a byte buffer for the conversion result, u8l is the length of the result buffer. On success the function returns the number of UTF8-bytes used to store the result, on error 0 is returned.

The dkenc_ipaddr_to_ul() function converts a string containing an IP address into a 32 bit unsigned long in host representation.

RETURN VALUE
All functions returning int values return a nonzero value on success, 0 on error if not stated otherwise.

NOTES
UNICODE is a registered trade mark.

AUTHOR
Dirk Krause

COPYRIGHT AND LICENSE
Copyright (c) 2001-2008, Dirk Krause All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above
   copyright notice, this list of conditions and the
   following disclaimer.

 * Redistributions in binary form must reproduce the above
   copyright notice, this list of conditions and the following
   disclaimer in the documentation and/or other materials
   provided with the distribution.

 * Neither the name of the Dirk Krause nor the names of
   contributors may be used to endorse or promote products
   derived from this software without specific prior written
   permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.