KwikNet Low Level Services
K
DAK
147
hton– hton–
ntoh– ntoh–
Purpose Convert Between Host and Network Endian Forms
Used by
n Task n ISP n Timer Procedure n Restart Procedure n Exit Procedure
Setup The macro definitions are in file KN_LIB.H.
C dependent, in-line assembly language expansions are in file KNZZZCC.H.
#include "KN_LIB.H"
Convert 32-bit values Convert 16-bit values
netlong = htonl(hostlong) netshort = htons(hostshort)
hostlong = ntohl(netlong) hostshort = ntohs(netshort)
Description Hostlong is any 32-bit value in host endian form.
Netlong is any 32-bit value in net endian form.
Hostshort is any 16-bit value in host endian form.
Netshort is any 16-bit value in net endian form.
If the KwikNet Library has been configured for big endian operation, these
macros do nothing since the input values require no conversion.
If the KwikNet Library has been configured for little endian operation, these
macros may expand to a function call, an in-line function expansion or a
series of C statements, depending upon which C compiler is being used.
The goal is always to ensure the fastest possible execution of these
frequently encountered macros. When possible, these macros have been
implemented using in-line assembly language statements generated by the
C compiler. In some cases, the macros generate calls to assembly
language functions of a form supported by the C compiler. As a last
resort, the macros expand to a series of in-line C statements.
Returns The input value converted to opposite endian form.
Restriction These macros can introduce side effects. Therefore, the macro parameters
must not use expressions which include operators such as
-- or ++ since
they always produce side effects. You must also avoid using expressions
which include function calls to fetch parameters if the functions can
introduce side effects.
Example See examples in the descriptions of
kn_cksum(), kn_dprintf() and
kn_fmt().
Comments to this Manuals