Changes between Initial Version and Version 1 of Ticket #60852, comment 6


Ignore:
Timestamp:
Feb 21, 2022, 8:24:00 AM (3 years ago)
Author:
nospam2000 (Michael Dreher)
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #60852, comment 6

    initial v1  
    1414}}}
    1515
    16 I don't know if this is the correct way is to include <machine/endian.h>, maybe someone else has more experience how to use includes which come from the "machine" folder.
     16This is not the correct way it is just to show that the file is in the default search path.
     17
     18The following one also works because it indirectly includes machine/endian.h via <sys/type.h>
     19
     20{{{
     21#include <stdio.h>
     22#include <stdint.h>
     23/* #include <machine/endian.h> */
     24#include <sys/types.h>
     25
     26int main(void)
     27{
     28        uint16_t a = 0x1234;
     29        printf("%hx\n", htons(a));
     30}
     31
     32}}}
     33
     34The documentation of 'htons' says:
     35
     36{{{
     37
     38BYTEORDER(3)             BSD Library Functions Manual             BYTEORDER(3)
     39
     40NAME
     41     htonl, htons, htonll, ntohl, ntohs, ntohll -- convert values between host and network byte order
     42
     43LIBRARY
     44     Standard C Library (libc, -lc)
     45
     46SYNOPSIS
     47     #include <arpa/inet.h>
     48
     49}}}
     50
     51This works and would be the conformant way on macOS:
     52{{{
     53#include <stdio.h>
     54#include <stdint.h>
     55#include <arpa/inet.h>
     56
     57int main(void)
     58{
     59        uint16_t a = 0x1234;
     60        printf("%hx\n", htons(a));
     61}
     62
     63}}}
     64