Back to index

glibc  2.9
Defines | Functions | Variables
htontest.c File Reference
#include <endian.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>

Go to the source code of this file.

Defines

#define TEST(orig, swapped, fct)

Functions

int main (void)

Variables

u_int32_t lo = 0x67452301
u_int16_t foo = 0x1234

Define Documentation

#define TEST (   orig,
  swapped,
  fct 
)
Value:
if ((fct (orig)) != (orig)) {                                               \
    printf ("Failed for %s -> %#x\n", #fct "(" #orig ")", fct (orig));             \
    result = 1;                                                             \
  }

Definition at line 27 of file htontest.c.


Function Documentation

int main ( void  )

Definition at line 46 of file htontest.c.

{
  int result = 0;

  TEST (0x67452301, 0x01234567, htonl);
  TEST (0x67452301, 0x01234567, (htonl));
  TEST (0x67452301, 0x01234567, ntohl);
  TEST (0x67452301, 0x01234567, (ntohl));

  TEST (lo, 0x01234567, htonl);
  TEST (lo, 0x01234567, (htonl));
  TEST (lo, 0x01234567, ntohl);
  TEST (lo, 0x01234567, (ntohl));

  TEST (0x1234, 0x3412, htons);
  TEST (0x1234, 0x3412, (htons));
  TEST (0x1234, 0x3412, ntohs);
  TEST (0x1234, 0x3412, (ntohs));

  TEST (foo, 0x3412, htons);
  TEST (foo, 0x3412, (htons));
  TEST (foo, 0x3412, ntohs);
  TEST (foo, 0x3412, (ntohs));

  return result;
}

Here is the call graph for this function:


Variable Documentation

void foo = 0x1234

Definition at line 43 of file htontest.c.

u_int32_t lo = 0x67452301

Definition at line 42 of file htontest.c.