~davewalker/ubuntu/maverick/asterisk/lp_705014

« back to all changes in this revision

Viewing changes to channels/iax2-parser.c

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2005-03-09 22:09:05 UTC
  • mto: (1.2.1 upstream) (8.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050309220905-9afy6hcpw96xbr6j
Tags: upstream-1.0.6
ImportĀ upstreamĀ versionĀ 1.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <string.h>
17
17
#include <netinet/in.h>
18
18
#include <asterisk/frame.h>
 
19
#include <asterisk/utils.h>
19
20
#include <arpa/inet.h>
20
21
#include <unistd.h>
21
22
#include <stdlib.h>
22
23
#include <stdio.h>
23
24
#include "iax2.h"
24
25
#include "iax2-parser.h"
 
26
#include "iax2-provision.h"
25
27
 
26
28
 
27
29
static int frames = 0;
30
32
 
31
33
static void internaloutput(const char *str)
32
34
{
33
 
        printf(str);
 
35
        fputs(str, stdout);
34
36
}
35
37
 
36
38
static void internalerror(const char *str)
44
46
static void dump_addr(char *output, int maxlen, void *value, int len)
45
47
{
46
48
        struct sockaddr_in sin;
47
 
        if (len == sizeof(sin)) {
 
49
        char iabuf[INET_ADDRSTRLEN];
 
50
        if (len == (int)sizeof(sin)) {
48
51
                memcpy(&sin, value, len);
49
 
                snprintf(output, maxlen, "IPV4 %s:%d", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 
52
                snprintf(output, maxlen, "IPV4 %s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
50
53
        } else {
51
54
                snprintf(output, maxlen, "Invalid Address");
52
55
        }
63
66
 
64
67
static void dump_int(char *output, int maxlen, void *value, int len)
65
68
{
66
 
        if (len == sizeof(unsigned int))
 
69
        if (len == (int)sizeof(unsigned int))
67
70
                snprintf(output, maxlen, "%lu", (unsigned long)ntohl(*((unsigned int *)value)));
68
71
        else
69
72
                snprintf(output, maxlen, "Invalid INT");
71
74
 
72
75
static void dump_short(char *output, int maxlen, void *value, int len)
73
76
{
74
 
        if (len == sizeof(unsigned short))
 
77
        if (len == (int)sizeof(unsigned short))
75
78
                snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
76
79
        else
77
80
                snprintf(output, maxlen, "Invalid SHORT");
79
82
 
80
83
static void dump_byte(char *output, int maxlen, void *value, int len)
81
84
{
82
 
        if (len == sizeof(unsigned char))
83
 
                snprintf(output, maxlen, "%d", ntohs(*((unsigned char *)value)));
 
85
        if (len == (int)sizeof(unsigned char))
 
86
                snprintf(output, maxlen, "%d", *((unsigned char *)value));
84
87
        else
85
88
                snprintf(output, maxlen, "Invalid BYTE");
86
89
}
87
90
 
 
91
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
 
92
{
 
93
        struct sockaddr_in sin;
 
94
        char iabuf[INET_ADDRSTRLEN];
 
95
        if (len == (int)sizeof(unsigned int)) {
 
96
                memcpy(&sin.sin_addr, value, len);
 
97
                ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
 
98
                snprintf(output, maxlen, "%s", iabuf);
 
99
        } else
 
100
                snprintf(output, maxlen, "Invalid IPADDR");
 
101
}
 
102
 
 
103
 
 
104
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
 
105
{
 
106
        char buf[256] = "";
 
107
        if (len == (int)sizeof(unsigned int))
 
108
                snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(*((unsigned int *)value)),
 
109
                        iax_provflags2str(buf, sizeof(buf), ntohl(*((unsigned int *)value))));
 
110
        else
 
111
                snprintf(output, maxlen, "Invalid INT");
 
112
}
 
113
 
 
114
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len);
 
115
static void dump_prov(char *output, int maxlen, void *value, int len)
 
116
{
 
117
        dump_prov_ies(output, maxlen, value, len);
 
118
}
 
119
 
88
120
static struct iax2_ie {
89
121
        int ie;
90
122
        char *name;
117
149
        { IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
118
150
        { IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
119
151
        { IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
120
 
        { IAX_IE_PROVISIONING, "PROVISIONING" },
121
 
        { IAX_IE_AESPROVISIONING, "AES PROVISIONING" },
 
152
        { IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
 
153
        { IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
122
154
        { IAX_IE_DATETIME, "DATE TIME", dump_int },
 
155
        { IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
 
156
        { IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
 
157
        { IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
 
158
        { IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
 
159
        { IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
 
160
        { IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
 
161
};
 
162
 
 
163
static struct iax2_ie prov_ies[] = {
 
164
        { PROV_IE_USEDHCP, "USEDHCP" },
 
165
        { PROV_IE_IPADDR, "IPADDR", dump_ipaddr },
 
166
        { PROV_IE_SUBNET, "SUBNET", dump_ipaddr },
 
167
        { PROV_IE_GATEWAY, "GATEWAY", dump_ipaddr },
 
168
        { PROV_IE_PORTNO, "BINDPORT", dump_short },
 
169
        { PROV_IE_USER, "USERNAME", dump_string },
 
170
        { PROV_IE_PASS, "PASSWORD", dump_string },
 
171
        { PROV_IE_LANG, "LANGUAGE", dump_string },
 
172
        { PROV_IE_TOS, "TYPEOFSERVICE", dump_byte },
 
173
        { PROV_IE_FLAGS, "FLAGS", dump_prov_flags },
 
174
        { PROV_IE_FORMAT, "FORMAT", dump_int },
 
175
        { PROV_IE_AESKEY, "AESKEY" },
 
176
        { PROV_IE_SERVERIP, "SERVERIP", dump_ipaddr },
 
177
        { PROV_IE_SERVERPORT, "SERVERPORT", dump_short },
 
178
        { PROV_IE_NEWAESKEY, "NEWAESKEY" },
 
179
        { PROV_IE_PROVVER, "PROV VERSION", dump_int },
 
180
        { PROV_IE_ALTSERVER, "ALTSERVERIP", dump_ipaddr },
123
181
};
124
182
 
125
183
const char *iax_ie2str(int ie)
126
184
{
127
185
        int x;
128
 
        for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
 
186
        for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
129
187
                if (ies[x].ie == ie)
130
188
                        return ies[x].name;
131
189
        }
132
190
        return "Unknown IE";
133
191
}
134
192
 
 
193
 
 
194
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len)
 
195
{
 
196
        int ielen;
 
197
        int ie;
 
198
        int x;
 
199
        int found;
 
200
        char interp[80];
 
201
        char tmp[256];
 
202
        if (len < 2)
 
203
                return;
 
204
        strcpy(output, "\n"); 
 
205
        maxlen -= strlen(output); output += strlen(output);
 
206
        while(len > 2) {
 
207
                ie = iedata[0];
 
208
                ielen = iedata[1];
 
209
                if (ielen + 2> len) {
 
210
                        snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
 
211
                        strncpy(output, tmp, maxlen - 1);
 
212
                        maxlen -= strlen(output); output += strlen(output);
 
213
                        return;
 
214
                }
 
215
                found = 0;
 
216
                for (x=0;x<(int)sizeof(prov_ies) / (int)sizeof(prov_ies[0]); x++) {
 
217
                        if (prov_ies[x].ie == ie) {
 
218
                                if (prov_ies[x].dump) {
 
219
                                        prov_ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
 
220
                                        snprintf(tmp, (int)sizeof(tmp), "       %-15.15s : %s\n", prov_ies[x].name, interp);
 
221
                                        strncpy(output, tmp, maxlen - 1);
 
222
                                        maxlen -= strlen(output); output += strlen(output);
 
223
                                } else {
 
224
                                        if (ielen)
 
225
                                                snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
 
226
                                        else
 
227
                                                strcpy(interp, "Present");
 
228
                                        snprintf(tmp, (int)sizeof(tmp), "       %-15.15s : %s\n", prov_ies[x].name, interp);
 
229
                                        strncpy(output, tmp, maxlen - 1);
 
230
                                        maxlen -= strlen(output); output += strlen(output);
 
231
                                }
 
232
                                found++;
 
233
                        }
 
234
                }
 
235
                if (!found) {
 
236
                        snprintf(tmp, (int)sizeof(tmp), "       Unknown Prov IE %03d  : Present\n", ie);
 
237
                        strncpy(output, tmp, maxlen - 1);
 
238
                        maxlen -= strlen(output); output += strlen(output);
 
239
                }
 
240
                iedata += (2 + ielen);
 
241
                len -= (2 + ielen);
 
242
        }
 
243
}
 
244
 
135
245
static void dump_ies(unsigned char *iedata, int len)
136
246
{
137
247
        int ielen;
138
248
        int ie;
139
249
        int x;
140
250
        int found;
141
 
        char interp[80];
142
 
        char tmp[256];
 
251
        char interp[1024];
 
252
        char tmp[1024];
143
253
        if (len < 2)
144
254
                return;
145
255
        while(len > 2) {
146
256
                ie = iedata[0];
147
257
                ielen = iedata[1];
148
258
                if (ielen + 2> len) {
149
 
                        snprintf(tmp, sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
 
259
                        snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
150
260
                        outputf(tmp);
151
261
                        return;
152
262
                }
153
263
                found = 0;
154
 
                for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
 
264
                for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
155
265
                        if (ies[x].ie == ie) {
156
266
                                if (ies[x].dump) {
157
 
                                        ies[x].dump(interp, sizeof(interp), iedata + 2, ielen);
158
 
                                        snprintf(tmp, sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
 
267
                                        ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
 
268
                                        snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
159
269
                                        outputf(tmp);
160
270
                                } else {
161
 
                                        snprintf(tmp, sizeof(tmp), "   %-15.15s : Present\n", ies[x].name);
 
271
                                        if (ielen)
 
272
                                                snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
 
273
                                        else
 
274
                                                strcpy(interp, "Present");
 
275
                                        snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
162
276
                                        outputf(tmp);
163
277
                                }
164
278
                                found++;
165
279
                        }
166
280
                }
167
281
                if (!found) {
168
 
                        snprintf(tmp, sizeof(tmp), "   Unknown IE %03d  : Present\n", ie);
 
282
                        snprintf(tmp, (int)sizeof(tmp), "   Unknown IE %03d  : Present\n", ie);
169
283
                        outputf(tmp);
170
284
                }
171
285
                iedata += (2 + ielen);
223
337
                "UNSUPPORTED",
224
338
                "TRANSFER",
225
339
                "PROVISION",
 
340
                "FWDOWNLD",
 
341
                "FWDATA"
226
342
        };
227
343
        char *cmds[] = {
228
344
                "(0?)",
240
356
        char *class;
241
357
        char *subclass;
242
358
        char tmp[256];
 
359
        char iabuf[INET_ADDRSTRLEN];
243
360
        if (f) {
244
361
                fh = f->data;
245
 
                snprintf(retries, sizeof(retries), "%03d", f->retries);
 
362
                snprintf(retries, (int)sizeof(retries), "%03d", f->retries);
246
363
        } else {
247
364
                fh = fhi;
248
365
                if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
249
366
                        strcpy(retries, "Yes");
250
367
                else
251
 
                        strcpy(retries, "No");
 
368
                        strcpy(retries, " No");
252
369
        }
253
370
        if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
254
371
                /* Don't mess with mini-frames */
255
372
                return;
256
373
        }
257
 
        if (fh->type > sizeof(frames)/sizeof(char *)) {
258
 
                snprintf(class2, sizeof(class2), "(%d?)", fh->type);
 
374
        if (fh->type > (int)sizeof(frames)/(int)sizeof(char *)) {
 
375
                snprintf(class2, (int)sizeof(class2), "(%d?)", fh->type);
259
376
                class = class2;
260
377
        } else {
261
378
                class = frames[(int)fh->type];
264
381
                sprintf(subclass2, "%c", fh->csub);
265
382
                subclass = subclass2;
266
383
        } else if (fh->type == AST_FRAME_IAX) {
267
 
                if (fh->csub >= sizeof(iaxs)/sizeof(iaxs[0])) {
268
 
                        snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
 
384
                if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
 
385
                        snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
269
386
                        subclass = subclass2;
270
387
                } else {
271
388
                        subclass = iaxs[(int)fh->csub];
272
389
                }
273
390
        } else if (fh->type == AST_FRAME_CONTROL) {
274
 
                if (fh->csub > sizeof(cmds)/sizeof(char *)) {
275
 
                        snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
 
391
                if (fh->csub > (int)sizeof(cmds)/(int)sizeof(char *)) {
 
392
                        snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
276
393
                        subclass = subclass2;
277
394
                } else {
278
395
                        subclass = cmds[(int)fh->csub];
279
396
                }
280
397
        } else {
281
 
                snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
 
398
                snprintf(subclass2, (int)sizeof(subclass2), "%d", fh->csub);
282
399
                subclass = subclass2;
283
400
        }
284
 
snprintf(tmp, sizeof(tmp), 
 
401
snprintf(tmp, (int)sizeof(tmp), 
285
402
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
286
403
        (rx ? "Rx" : "Tx"),
287
404
        retries, fh->oseqno, fh->iseqno, class, subclass);
288
405
        outputf(tmp);
289
 
snprintf(tmp, sizeof(tmp), 
 
406
snprintf(tmp, (int)sizeof(tmp), 
290
407
"   Timestamp: %05lums  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
291
408
        (unsigned long)ntohl(fh->ts),
292
409
        ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
293
 
                inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
 
410
                ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
294
411
        outputf(tmp);
295
412
        if (fh->type == AST_FRAME_IAX)
296
413
                dump_ies(fh->iedata, datalen);
299
416
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen)
300
417
{
301
418
        char tmp[256];
302
 
        if (datalen > (sizeof(ied->buf) - ied->pos)) {
303
 
                snprintf(tmp, sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, sizeof(ied->buf) - ied->pos);
 
419
        if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
 
420
                snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
304
421
                errorf(tmp);
305
422
                return -1;
306
423
        }
313
430
 
314
431
int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
315
432
{
316
 
        return iax_ie_append_raw(ied, ie, sin, sizeof(struct sockaddr_in));
 
433
        return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
317
434
}
318
435
 
319
436
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value) 
320
437
{
321
438
        unsigned int newval;
322
439
        newval = htonl(value);
323
 
        return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
 
440
        return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
324
441
}
325
442
 
326
443
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value) 
327
444
{
328
445
        unsigned short newval;
329
446
        newval = htons(value);
330
 
        return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
 
447
        return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
331
448
}
332
449
 
333
450
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, unsigned char *str)
361
478
        int len;
362
479
        int ie;
363
480
        char tmp[256];
364
 
        memset(ies, 0, sizeof(struct iax_ies));
 
481
        memset(ies, 0, (int)sizeof(struct iax_ies));
365
482
        ies->msgcount = -1;
 
483
        ies->firmwarever = -1;
366
484
        while(datalen >= 2) {
367
485
                ie = data[0];
368
486
                len = data[1];
393
511
                        ies->password = data + 2;
394
512
                        break;
395
513
                case IAX_IE_CAPABILITY:
396
 
                        if (len != sizeof(unsigned int)) {
397
 
                                snprintf(tmp, sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", sizeof(unsigned int), len);
 
514
                        if (len != (int)sizeof(unsigned int)) {
 
515
                                snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
398
516
                                errorf(tmp);
399
517
                        } else
400
518
                                ies->capability = ntohl(*((unsigned int *)(data + 2)));
401
519
                        break;
402
520
                case IAX_IE_FORMAT:
403
 
                        if (len != sizeof(unsigned int)) {
404
 
                                snprintf(tmp, sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", sizeof(unsigned int), len);
 
521
                        if (len != (int)sizeof(unsigned int)) {
 
522
                                snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
405
523
                                errorf(tmp);
406
524
                        } else
407
525
                                ies->format = ntohl(*((unsigned int *)(data + 2)));
410
528
                        ies->language = data + 2;
411
529
                        break;
412
530
                case IAX_IE_VERSION:
413
 
                        if (len != sizeof(unsigned short)) {
414
 
                                snprintf(tmp, sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
531
                        if (len != (int)sizeof(unsigned short)) {
 
532
                                snprintf(tmp, (int)sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
415
533
                                errorf(tmp);
416
534
                        } else
417
535
                                ies->version = ntohs(*((unsigned short *)(data + 2)));
418
536
                        break;
419
537
                case IAX_IE_ADSICPE:
420
 
                        if (len != sizeof(unsigned short)) {
421
 
                                snprintf(tmp, sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
538
                        if (len != (int)sizeof(unsigned short)) {
 
539
                                snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
422
540
                                errorf(tmp);
423
541
                        } else
424
542
                                ies->adsicpe = ntohs(*((unsigned short *)(data + 2)));
430
548
                        ies->rdnis = data + 2;
431
549
                        break;
432
550
                case IAX_IE_AUTHMETHODS:
433
 
                        if (len != sizeof(unsigned short))  {
434
 
                                snprintf(tmp, sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
551
                        if (len != (int)sizeof(unsigned short))  {
 
552
                                snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
435
553
                                errorf(tmp);
436
554
                        } else
437
555
                                ies->authmethods = ntohs(*((unsigned short *)(data + 2)));
449
567
                        ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
450
568
                        break;
451
569
                case IAX_IE_REFRESH:
452
 
                        if (len != sizeof(unsigned short)) {
453
 
                                snprintf(tmp, sizeof(tmp),  "Expecting refresh to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
570
                        if (len != (int)sizeof(unsigned short)) {
 
571
                                snprintf(tmp, (int)sizeof(tmp),  "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
454
572
                                errorf(tmp);
455
573
                        } else
456
574
                                ies->refresh = ntohs(*((unsigned short *)(data + 2)));
457
575
                        break;
458
576
                case IAX_IE_DPSTATUS:
459
 
                        if (len != sizeof(unsigned short)) {
460
 
                                snprintf(tmp, sizeof(tmp),  "Expecting dpstatus to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
577
                        if (len != (int)sizeof(unsigned short)) {
 
578
                                snprintf(tmp, (int)sizeof(tmp),  "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
461
579
                                errorf(tmp);
462
580
                        } else
463
581
                                ies->dpstatus = ntohs(*((unsigned short *)(data + 2)));
464
582
                        break;
465
583
                case IAX_IE_CALLNO:
466
 
                        if (len != sizeof(unsigned short)) {
467
 
                                snprintf(tmp, sizeof(tmp),  "Expecting callno to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
584
                        if (len != (int)sizeof(unsigned short)) {
 
585
                                snprintf(tmp, (int)sizeof(tmp),  "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
468
586
                                errorf(tmp);
469
587
                        } else
470
588
                                ies->callno = ntohs(*((unsigned short *)(data + 2)));
476
594
                        if (len == 1)
477
595
                                ies->iax_unknown = data[2];
478
596
                        else {
479
 
                                snprintf(tmp, sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
 
597
                                snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
480
598
                                errorf(tmp);
481
599
                        }
482
600
                        break;
483
601
                case IAX_IE_MSGCOUNT:
484
 
                        if (len != sizeof(unsigned short)) {
485
 
                                snprintf(tmp, sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", sizeof(unsigned short), len);
 
602
                        if (len != (int)sizeof(unsigned short)) {
 
603
                                snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
486
604
                                errorf(tmp);
487
605
                        } else
488
606
                                ies->msgcount = ntohs(*((unsigned short *)(data + 2))); 
494
612
                        ies->musiconhold = 1;
495
613
                        break;
496
614
                case IAX_IE_TRANSFERID:
497
 
                        if (len != sizeof(unsigned int)) {
498
 
                                snprintf(tmp, sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", sizeof(unsigned int), len);
 
615
                        if (len != (int)sizeof(unsigned int)) {
 
616
                                snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
499
617
                                errorf(tmp);
500
618
                        } else
501
619
                                ies->transferid = ntohl(*((unsigned int *)(data + 2)));
502
620
                        break;
503
621
                case IAX_IE_DATETIME:
504
 
                        if (len != sizeof(unsigned int)) {
505
 
                                snprintf(tmp, sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", sizeof(unsigned int), len);
 
622
                        if (len != (int)sizeof(unsigned int)) {
 
623
                                snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
506
624
                                errorf(tmp);
507
625
                        } else
508
626
                                ies->datetime = ntohl(*((unsigned int *)(data + 2)));
509
627
                        break;
 
628
                case IAX_IE_FIRMWAREVER:
 
629
                        if (len != (int)sizeof(unsigned short)) {
 
630
                                snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
 
631
                                errorf(tmp);
 
632
                        } else
 
633
                                ies->firmwarever = ntohs(*((unsigned short *)(data + 2)));      
 
634
                        break;
 
635
                case IAX_IE_DEVICETYPE:
 
636
                        ies->devicetype = data + 2;
 
637
                        break;
 
638
                case IAX_IE_SERVICEIDENT:
 
639
                        ies->serviceident = data + 2;
 
640
                        break;
 
641
                case IAX_IE_FWBLOCKDESC:
 
642
                        if (len != (int)sizeof(unsigned int)) {
 
643
                                snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
 
644
                                errorf(tmp);
 
645
                        } else
 
646
                                ies->fwdesc = ntohl(*((unsigned int *)(data + 2)));
 
647
                        break;
 
648
                case IAX_IE_FWBLOCKDATA:
 
649
                        ies->fwdata = data + 2;
 
650
                        ies->fwdatalen = len;
 
651
                        break;
 
652
                case IAX_IE_PROVVER:
 
653
                        if (len != (int)sizeof(unsigned int)) {
 
654
                                snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
 
655
                                errorf(tmp);
 
656
                        } else {
 
657
                                ies->provverpres = 1;
 
658
                                ies->provver = ntohl(*((unsigned int *)(data + 2)));
 
659
                        }
 
660
                        break;
510
661
                default:
511
 
                        snprintf(tmp, sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
 
662
                        snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
512
663
                        outputf(tmp);
513
664
                }
514
665
                /* Overwrite information element with 0, to null terminate previous portion */
534
685
        fr->af.samples = f->samples;
535
686
        fr->af.offset = AST_FRIENDLY_OFFSET;
536
687
        fr->af.src = f->src;
 
688
        fr->af.delivery.tv_sec = 0;
 
689
        fr->af.delivery.tv_usec = 0;
537
690
        fr->af.data = fr->afdata;
538
691
        if (fr->af.datalen) 
539
692
                memcpy(fr->af.data, f->data, fr->af.datalen);
542
695
struct iax_frame *iax_frame_new(int direction, int datalen)
543
696
{
544
697
        struct iax_frame *fr;
545
 
        fr = malloc(sizeof(struct iax_frame) + datalen);
 
698
        fr = malloc((int)sizeof(struct iax_frame) + datalen);
546
699
        if (fr) {
547
700
                fr->direction = direction;
548
701
                fr->retrans = -1;