Skip to content
FROM_BIG_ENDIAN2

FROM_BIG_ENDIAN2

Description

Conditionally converts value from big-endian to native byte order. On little-endian systems, this inverts the byte order. On big-endian systems, this is a no-op.

Parameters

Name Direction Description
x in 16-bit value in big-endian format

Success

Returns value in native byte order.

Failure

Function cannot fail - pure bitwise operation.

Usage example (Cross-references)

Usage examples (Cross-references)
                MemSet(out, 0, sizeof(*out));
                sa->sin_family = AF_INET;
                sa->sin_port   = FROM_BIG_ENDIAN2(port);
                MemCopy(&sa->sin_addr.s_addr, v4, 4);
                out->length = (u32)sizeof(struct sockaddr_in);
                MemSet(out, 0, sizeof(*out));
                sa->sin6_family = AF_INET6;
                sa->sin6_port   = FROM_BIG_ENDIAN2(port);
                // Windows' IN6_ADDR defines `#define s6_addr u.Byte`, so this
                // works the same on both platforms.
                }
                StrResize(&host, ZstrLen(host_data));
                port = FROM_BIG_ENDIAN2(sa->sin_port);
                StrAppendFmt(&out, "{}:{}", (Zstr)host_data, (u32)port);
            } else if (addr->family == SOCKET_FAMILY_INET6) {
                }
                StrResize(&host, ZstrLen(host_data));
                port = FROM_BIG_ENDIAN2(sa->sin6_port);
                StrAppendFmt(&out, "[{}]:{}", (Zstr)host_data, (u32)port);
            } else {
        struct sockaddr_in *sa = (struct sockaddr_in *)a.raw;
        sa->sin_family         = AF_INET;
        sa->sin_port           = FROM_BIG_ENDIAN2(port);
        MemCopy(&sa->sin_addr.s_addr, ip, 4);
        a.length = (u32)sizeof(struct sockaddr_in);
        struct sockaddr_in6 *sa = (struct sockaddr_in6 *)a.raw;
        sa->sin6_family         = AF_INET6;
        sa->sin6_port           = FROM_BIG_ENDIAN2(port);
        MemCopy(sa->sin6_addr.s6_addr, ip, 16);
        a.length = (u32)sizeof(struct sockaddr_in6);
Last updated on