Merge pull request #2182 from colinleroy/add-ntohs

Add ntohs/htons and ntohl/htonl
This commit is contained in:
Bob Andrews
2023-09-08 18:47:09 +02:00
committed by GitHub
6 changed files with 270 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
/*
!!DESCRIPTION!! A small test for htons.
!!ORIGIN!!
!!LICENCE!!
!!AUTHOR!! Colin Leroy-Mira
*/
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
static unsigned int Failures = 0;
static void CheckHtonl (long input, long expected)
{
long result = htonl(input);
if (result != expected) {
printf ("htonl error:\n"
" result = %ld for %ld, should be %ld\n", result, input, expected);
++Failures;
}
}
int main (void)
{
CheckHtonl(0x00000000, 0x00000000);
CheckHtonl(0x12345678, 0x78563412);
CheckHtonl(0xAABBCCDD, 0xDDCCBBAA);
CheckHtonl(0xFFFFFFFF, 0xFFFFFFFF);
printf ("Failures: %u\n", Failures);
return Failures;
}

View File

@@ -0,0 +1,34 @@
/*
!!DESCRIPTION!! A small test for htons.
!!ORIGIN!!
!!LICENCE!!
!!AUTHOR!! Colin Leroy-Mira
*/
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
static unsigned int Failures = 0;
static void CheckHtons (int input, int expected)
{
int result = htons(input);
if (result != expected) {
printf ("htons error:\n"
" result = %d for %d, should be %d\n", result, input, expected);
++Failures;
}
}
int main (void)
{
CheckHtons(0x0000, 0x0000);
CheckHtons(0x1234, 0x3412);
CheckHtons(0xA0F2, 0xF2A0);
CheckHtons(0xFFFF, 0xFFFF);
printf ("Failures: %u\n", Failures);
return Failures;
}