Bytes On The Wire

#include <stdint.h>
#include <stdio.h>
#include <arpa/inet.h>

int main(void) {
    uint32_t v = 0x12345678;
    uint32_t n = htonl(v);
    unsigned char *p = (unsigned char *)&v;
    unsigned char *q = (unsigned char *)&n;
    printf("%02x %02x %02x %02x | %02x %02x %02x %02x\n",
           p[0], p[1], p[2], p[3], q[0], q[1], q[2], q[3]);
}

What does this print on x86-64?

A

87 65 43 21 | 12 34 56 78

B

78 56 34 12 | 12 34 56 78

C

12 34 56 78 | 78 56 34 12

D

78 56 34 12 | 78 56 34 12, because htonl is a no-op on a little-endian host and only compiles to a swap on big-endian ones.