--- channels/iax2-parser.c.orig 2010-01-28 15:00:09.000000000 -0500 +++ channels/iax2-parser.c 2011-01-07 20:59:49.000000000 -0500 @@ -42,6 +42,21 @@ #include "iax2-parser.h" #include "iax2-provision.h" +/* htonll and ntohll convert between network byte order (which is defined as big endian) + * and host byte order (which varies). On a BIG_ENDIAN machine, these two routines do + * nothing. + * Issue #18583 shows that beginning with 1.8, when these were first used for the + * 64-bit expanded codec fields, Darwin PPC (BIG_ENDIAN) machines can no longer do + * codec negotiation with Linux i386 (LITTLE_ENDIAN) machines. + * It appears that the network byte order change is being handled elsewhere in the code, + * and that htonll and ntohll should never have been called. However, to make that change + * at this point in time would introduce a new incompatibility between LITTLE_ENDIAN + * machines dependent on their version. + * This patch seeks to limit any impact by only removing the incompatibility where it must + * be removed: for Darwin. For Darwin machines only, we call OSSwapInt64, since calls to + * xtoyll do not do the necessary swap. + */ + static int frames = 0; static int iframes = 0; static int oframes = 0; @@ -219,7 +234,11 @@ char *version = (char *) value; if (version[0] == 0) { if (len == (int) (sizeof(format_t) + sizeof(char))) { +#ifndef __Darwin__ format_t codec = ntohll(get_unaligned_uint64(value + 1)); +#else + format_t codec = OSSwapInt64(get_unaligned_uint64(value + 1)); +#endif ast_copy_string(output, ast_getformatname(codec), maxlen); } else { ast_copy_string(output, "Invalid length!", maxlen); @@ -702,7 +721,11 @@ unsigned char version; uint64_t value; } __attribute__((packed)) newval = { version, }; +#ifndef __Darwin__ put_unaligned_uint64(&newval.value, htonll(value)); +#else + put_unaligned_uint64(&newval.value, OSSwapInt64(value)); +#endif return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval)); } @@ -808,7 +831,11 @@ snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) (sizeof(format_t) + sizeof(char)), len); errorf(tmp); } else { +#ifndef __Darwin__ ies->capability = (format_t) ntohll(get_unaligned_uint64(data + 3)); +#else + ies->capability = (format_t) OSSwapInt64(get_unaligned_uint64(data + 3)); +#endif } } /* else unknown version */ } @@ -829,7 +856,11 @@ snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) (sizeof(format_t) + sizeof(char)), len); errorf(tmp); } else { +#ifndef __Darwin__ ies->format = (format_t) ntohll(get_unaligned_uint64(data + 3)); +#else + ies->format = (format_t) OSSwapInt64(get_unaligned_uint64(data + 3)); +#endif } } /* else unknown version */ }