From f966e5e186f14110a29d38d03992488d88348108 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Tue, 29 Mar 2005 04:49:24 +0000 Subject: Simplify endianness and fix for unaligned reads (bug #3867) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5295 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_alsa.c | 2 +- channels/chan_oss.c | 18 +------------ channels/iax2-parser.c | 71 ++++++++++++++++++++------------------------------ 3 files changed, 30 insertions(+), 61 deletions(-) (limited to 'channels') diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index 9811cb8d2..fb2b93b30 100755 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #define ALSA_PCM_NEW_HW_PARAMS_API #define ALSA_PCM_NEW_SW_PARAMS_API diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 480408eb7..6a580d48c 100755 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -35,23 +36,6 @@ #include #include -#if defined( __OpenBSD__ ) -# include -#elif defined( __FreeBSD__ ) || defined( __NetBSD__ ) -# include -#elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__) -# include -#elif defined ( SOLARIS ) -# include -#elif defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) -# include -#if !defined(__APPLE__) -# include -#endif -#elif defined( linux ) -# include -#endif - #ifdef __linux #include #elif defined(__FreeBSD__) diff --git a/channels/iax2-parser.c b/channels/iax2-parser.c index 66a69b447..3472b5008 100755 --- a/channels/iax2-parser.c +++ b/channels/iax2-parser.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,22 +31,6 @@ static int frames = 0; static int iframes = 0; static int oframes = 0; -#if defined(SOLARIS) && defined(__sparc__) -static unsigned int get_uint32(unsigned char *p) -{ - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -} - -static unsigned short get_uint16(unsigned char *p) -{ - return (p[0] << 8) | p[1] ; -} - -#else -#define get_uint32(p) (*((unsigned int *)(p))) -#define get_uint16(p) (*((unsigned short *)(p))) -#endif - static void internaloutput(const char *str) { fputs(str, stdout); @@ -102,7 +87,7 @@ static void dump_prefs(char *output, int maxlen, void *value, int len) static void dump_int(char *output, int maxlen, void *value, int len) { if (len == (int)sizeof(unsigned int)) - snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_uint32(value))); + snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_unaligned_uint32(value))); else snprintf(output, maxlen, "Invalid INT"); } @@ -110,7 +95,7 @@ static void dump_int(char *output, int maxlen, void *value, int len) static void dump_short(char *output, int maxlen, void *value, int len) { if (len == (int)sizeof(unsigned short)) - snprintf(output, maxlen, "%d", ntohs(get_uint16(value))); + snprintf(output, maxlen, "%d", ntohs(get_unaligned_uint16(value))); else snprintf(output, maxlen, "Invalid SHORT"); } @@ -140,8 +125,8 @@ static void dump_prov_flags(char *output, int maxlen, void *value, int len) { char buf[256] = ""; if (len == (int)sizeof(unsigned int)) - snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_uint32(value)), - iax_provflags2str(buf, sizeof(buf), ntohl(get_uint32(value)))); + snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_unaligned_uint32(value)), + iax_provflags2str(buf, sizeof(buf), ntohl(get_unaligned_uint32(value)))); else snprintf(output, maxlen, "Invalid INT"); } @@ -600,14 +585,14 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else - ies->capability = ntohl(get_uint32(data + 2)); + ies->capability = ntohl(get_unaligned_uint32(data + 2)); break; case IAX_IE_FORMAT: if (len != (int)sizeof(unsigned int)) { snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else - ies->format = ntohl(get_uint32(data + 2)); + ies->format = ntohl(get_unaligned_uint32(data + 2)); break; case IAX_IE_LANGUAGE: ies->language = data + 2; @@ -617,21 +602,21 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->version = ntohs(get_uint16(data + 2)); + ies->version = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_ADSICPE: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->adsicpe = ntohs(get_uint16(data + 2)); + ies->adsicpe = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_SAMPLINGRATE: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->samprate = ntohs(get_uint16(data + 2)); + ies->samprate = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_DNID: ies->dnid = data + 2; @@ -644,14 +629,14 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->authmethods = ntohs(get_uint16(data + 2)); + ies->authmethods = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_ENCRYPTION: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting encryption to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->encmethods = ntohs(get_uint16(data + 2)); + ies->encmethods = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_CHALLENGE: ies->challenge = data + 2; @@ -670,21 +655,21 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->refresh = ntohs(get_uint16(data + 2)); + ies->refresh = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_DPSTATUS: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->dpstatus = ntohs(get_uint16(data + 2)); + ies->dpstatus = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_CALLNO: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->callno = ntohs(get_uint16(data + 2)); + ies->callno = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_CAUSE: ies->cause = data + 2; @@ -710,7 +695,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->msgcount = ntohs(get_uint16(data + 2)); + ies->msgcount = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_AUTOANSWER: ies->autoanswer = 1; @@ -723,21 +708,21 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else - ies->transferid = ntohl(get_uint32(data + 2)); + ies->transferid = ntohl(get_unaligned_uint32(data + 2)); break; case IAX_IE_DATETIME: if (len != (int)sizeof(unsigned int)) { snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else - ies->datetime = ntohl(get_uint32(data + 2)); + ies->datetime = ntohl(get_unaligned_uint32(data + 2)); break; case IAX_IE_FIRMWAREVER: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->firmwarever = ntohs(get_uint16(data + 2)); + ies->firmwarever = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_DEVICETYPE: ies->devicetype = data + 2; @@ -750,7 +735,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else - ies->fwdesc = ntohl(get_uint32(data + 2)); + ies->fwdesc = ntohl(get_unaligned_uint32(data + 2)); break; case IAX_IE_FWBLOCKDATA: ies->fwdata = data + 2; @@ -766,7 +751,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) errorf(tmp); } else { ies->provverpres = 1; - ies->provver = ntohl(get_uint32(data + 2)); + ies->provver = ntohl(get_unaligned_uint32(data + 2)); } break; case IAX_IE_CALLINGPRES: @@ -790,14 +775,14 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else - ies->calling_tns = ntohs(get_uint16(data + 2)); + ies->calling_tns = ntohs(get_unaligned_uint16(data + 2)); break; case IAX_IE_RR_JITTER: if (len != (int)sizeof(unsigned int)) { snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else { - ies->rr_jitter = ntohl(get_uint32(data + 2)); + ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2)); } break; case IAX_IE_RR_LOSS: @@ -805,7 +790,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else { - ies->rr_loss = ntohl(get_uint32(data + 2)); + ies->rr_loss = ntohl(get_unaligned_uint32(data + 2)); } break; case IAX_IE_RR_PKTS: @@ -813,7 +798,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else { - ies->rr_pkts = ntohl(get_uint32(data + 2)); + ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2)); } break; case IAX_IE_RR_DELAY: @@ -821,7 +806,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); errorf(tmp); } else { - ies->rr_delay = ntohs(get_uint16(data + 2)); + ies->rr_delay = ntohs(get_unaligned_uint16(data + 2)); } break; case IAX_IE_RR_DROPPED: @@ -829,7 +814,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else { - ies->rr_dropped = ntohl(get_uint32(data + 2)); + ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2)); } break; case IAX_IE_RR_OOO: @@ -837,7 +822,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); errorf(tmp); } else { - ies->rr_ooo = ntohl(get_uint32(data + 2)); + ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2)); } break; default: -- cgit v1.2.3