2 * Distributed Universal Number Discovery (DUNDi)
4 * Copyright (C) 2004 - 2005, Digium Inc.
6 * Written by Mark Spencer <markster@digium.com>
8 * This program is Free Software distributed under the terms of
9 * of the GNU General Public License.
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
23 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
25 #include "asterisk/frame.h"
26 #include "asterisk/utils.h"
27 #include "asterisk/dundi.h"
28 #include "dundi-parser.h"
29 #include "asterisk/dundi.h"
31 static void internaloutput(const char *str)
36 static void internalerror(const char *str)
38 fprintf(stderr, "WARNING: %s", str);
41 static void (*outputf)(const char *str) = internaloutput;
42 static void (*errorf)(const char *str) = internalerror;
44 char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid)
49 if (s && (maxlen > 0))
53 sprintf(s, "%02x:", eid->eid[x]);
56 sprintf(s, "%02x", eid->eid[5]);
61 char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
66 if (s && (maxlen > 0))
70 sprintf(s, "%02X", eid->eid[x]);
77 int dundi_str_to_eid(dundi_eid *eid, char *s)
79 unsigned int eid_int[6];
81 if (sscanf(s, "%x:%x:%x:%x:%x:%x", &eid_int[0], &eid_int[1], &eid_int[2],
82 &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
85 eid->eid[x] = eid_int[x];
89 int dundi_str_short_to_eid(dundi_eid *eid, char *s)
91 unsigned int eid_int[6];
93 if (sscanf(s, "%2x%2x%2x%2x%2x%2x", &eid_int[0], &eid_int[1], &eid_int[2],
94 &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
97 eid->eid[x] = eid_int[x];
101 int dundi_eid_zero(dundi_eid *eid)
104 for (x=0;x<sizeof(eid->eid) / sizeof(eid->eid[0]);x++)
105 if (eid->eid[x]) return 0;
109 int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2)
111 return memcmp(eid1, eid2, sizeof(dundi_eid));
114 static void dump_string(char *output, int maxlen, void *value, int len)
119 strncpy(output,value, maxlen);
120 output[maxlen] = '\0';
123 static void dump_cbypass(char *output, int maxlen, void *value, int len)
126 strncpy(output, "Bypass Caches", maxlen);
127 output[maxlen] = '\0';
130 static void dump_eid(char *output, int maxlen, void *value, int len)
133 dundi_eid_to_str(output, maxlen, (dundi_eid *)value);
135 snprintf(output, maxlen, "Invalid EID len %d", len);
138 char *dundi_hint2str(char *buf, int bufsiz, int flags)
141 buf[bufsiz-1] = '\0';
142 if (flags & DUNDI_HINT_TTL_EXPIRED) {
143 strncat(buf, "TTLEXPIRED|", bufsiz - strlen(buf) - 1);
145 if (flags & DUNDI_HINT_DONT_ASK) {
146 strncat(buf, "DONTASK|", bufsiz - strlen(buf) - 1);
148 if (flags & DUNDI_HINT_UNAFFECTED) {
149 strncat(buf, "UNAFFECTED|", bufsiz - strlen(buf) - 1);
151 /* Get rid of trailing | */
152 if (ast_strlen_zero(buf))
153 strcpy(buf, "NONE|");
154 buf[strlen(buf)-1] = '\0';
158 static void dump_hint(char *output, int maxlen, void *value, int len)
160 unsigned short flags;
164 strncpy(output, "<invalid contents>", maxlen);
167 memcpy(&flags, value, sizeof(flags));
168 flags = ntohs(flags);
169 memset(tmp, 0, sizeof(tmp));
170 dundi_hint2str(tmp2, sizeof(tmp2), flags);
171 snprintf(tmp, sizeof(tmp), "[%s] ", tmp2);
172 memcpy(tmp + strlen(tmp), value + 2, len - 2);
173 strncpy(output, tmp, maxlen - 1);
176 static void dump_cause(char *output, int maxlen, void *value, int len)
178 static char *causes[] = {
189 strncpy(output, "<invalid contents>", maxlen);
192 cause = *((unsigned char *)value);
193 memset(tmp2, 0, sizeof(tmp2));
197 memcpy(tmp2, value + 1, mlen);
198 if (cause < sizeof(causes) / sizeof(causes[0])) {
200 snprintf(tmp, sizeof(tmp), "%s: %s", causes[cause], tmp2);
202 snprintf(tmp, sizeof(tmp), "%s", causes[cause]);
205 snprintf(tmp, sizeof(tmp), "%d: %s", cause, tmp2);
207 snprintf(tmp, sizeof(tmp), "%d", cause);
210 strncpy(output,tmp, maxlen);
211 output[maxlen] = '\0';
214 static void dump_int(char *output, int maxlen, void *value, int len)
216 if (len == (int)sizeof(unsigned int))
217 snprintf(output, maxlen, "%lu", (unsigned long)ntohl(*((unsigned int *)value)));
219 snprintf(output, maxlen, "Invalid INT");
222 static void dump_short(char *output, int maxlen, void *value, int len)
224 if (len == (int)sizeof(unsigned short))
225 snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
227 snprintf(output, maxlen, "Invalid SHORT");
230 static void dump_byte(char *output, int maxlen, void *value, int len)
232 if (len == (int)sizeof(unsigned char))
233 snprintf(output, maxlen, "%d", *((unsigned char *)value));
235 snprintf(output, maxlen, "Invalid BYTE");
238 static char *proto2str(int proto, char *buf, int bufsiz)
241 case DUNDI_PROTO_NONE:
242 strncpy(buf, "None", bufsiz - 1);
244 case DUNDI_PROTO_IAX:
245 strncpy(buf, "IAX", bufsiz - 1);
247 case DUNDI_PROTO_SIP:
248 strncpy(buf, "SIP", bufsiz - 1);
250 case DUNDI_PROTO_H323:
251 strncpy(buf, "H.323", bufsiz - 1);
254 snprintf(buf, bufsiz, "Unknown Proto(%d)", proto);
256 buf[bufsiz-1] = '\0';
260 char *dundi_flags2str(char *buf, int bufsiz, int flags)
263 buf[bufsiz-1] = '\0';
264 if (flags & DUNDI_FLAG_EXISTS) {
265 strncat(buf, "EXISTS|", bufsiz - strlen(buf) - 1);
267 if (flags & DUNDI_FLAG_MATCHMORE) {
268 strncat(buf, "MATCHMORE|", bufsiz - strlen(buf) - 1);
270 if (flags & DUNDI_FLAG_CANMATCH) {
271 strncat(buf, "CANMATCH|", bufsiz - strlen(buf) - 1);
273 if (flags & DUNDI_FLAG_IGNOREPAT) {
274 strncat(buf, "IGNOREPAT|", bufsiz - strlen(buf) - 1);
276 if (flags & DUNDI_FLAG_RESIDENTIAL) {
277 strncat(buf, "RESIDENCE|", bufsiz - strlen(buf) - 1);
279 if (flags & DUNDI_FLAG_COMMERCIAL) {
280 strncat(buf, "COMMERCIAL|", bufsiz - strlen(buf) - 1);
282 if (flags & DUNDI_FLAG_MOBILE) {
283 strncat(buf, "MOBILE", bufsiz - strlen(buf) - 1);
285 if (flags & DUNDI_FLAG_NOUNSOLICITED) {
286 strncat(buf, "NOUNSLCTD|", bufsiz - strlen(buf) - 1);
288 if (flags & DUNDI_FLAG_NOCOMUNSOLICIT) {
289 strncat(buf, "NOCOMUNSLTD|", bufsiz - strlen(buf) - 1);
291 /* Get rid of trailing | */
292 if (ast_strlen_zero(buf))
293 strcpy(buf, "NONE|");
294 buf[strlen(buf)-1] = '\0';
298 static void dump_answer(char *output, int maxlen, void *value, int len)
300 struct dundi_answer *answer;
306 answer = (struct dundi_answer *)(value);
307 memcpy(tmp, answer->data, (len >= 500) ? 500 : len - 10);
308 dundi_eid_to_str(eid_str, sizeof(eid_str), &answer->eid);
309 snprintf(output, maxlen, "[%s] %d <%s/%s> from [%s]",
310 dundi_flags2str(flags, sizeof(flags), ntohs(answer->flags)),
311 ntohs(answer->weight),
312 proto2str(answer->protocol, proto, sizeof(proto)),
315 strncpy(output, "Invalid Answer", maxlen - 1);
318 static void dump_encrypted(char *output, int maxlen, void *value, int len)
322 if ((len > 16) && !(len % 16)) {
325 snprintf(iv + (x << 1), 3, "%02x", ((unsigned char *)value)[x]);
327 snprintf(output, maxlen, "[IV %s] %d encrypted blocks\n", iv, len / 16);
329 snprintf(output, maxlen, "Invalid Encrypted Datalen %d", len);
332 static void dump_raw(char *output, int maxlen, void *value, int len)
335 unsigned char *u = value;
336 output[maxlen - 1] = '\0';
337 strcpy(output, "[ ");
338 for (x=0;x<len;x++) {
339 snprintf(output + strlen(output), maxlen - strlen(output) - 1, "%02x ", u[x]);
341 strncat(output + strlen(output), "]", maxlen - strlen(output) - 1);
344 static struct dundi_ie {
347 void (*dump)(char *output, int maxlen, void *value, int len);
349 { DUNDI_IE_EID, "ENTITY IDENT", dump_eid },
350 { DUNDI_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
351 { DUNDI_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
352 { DUNDI_IE_EID_DIRECT, "DIRECT EID", dump_eid },
353 { DUNDI_IE_ANSWER, "ANSWER", dump_answer },
354 { DUNDI_IE_TTL, "TTL", dump_short },
355 { DUNDI_IE_VERSION, "VERSION", dump_short },
356 { DUNDI_IE_EXPIRATION, "EXPIRATION", dump_short },
357 { DUNDI_IE_UNKNOWN, "UKWN DUNDI CMD", dump_byte },
358 { DUNDI_IE_CAUSE, "CAUSE", dump_cause },
359 { DUNDI_IE_REQEID, "REQUEST EID", dump_eid },
360 { DUNDI_IE_ENCDATA, "ENCDATA", dump_encrypted },
361 { DUNDI_IE_SHAREDKEY, "SHAREDKEY", dump_raw },
362 { DUNDI_IE_SIGNATURE, "SIGNATURE", dump_raw },
363 { DUNDI_IE_KEYCRC32, "KEYCRC32", dump_int },
364 { DUNDI_IE_HINT, "HINT", dump_hint },
365 { DUNDI_IE_DEPARTMENT, "DEPARTMENT", dump_string },
366 { DUNDI_IE_ORGANIZATION, "ORGANIZTN", dump_string },
367 { DUNDI_IE_LOCALITY, "LOCALITY", dump_string },
368 { DUNDI_IE_STATE_PROV, "STATEPROV", dump_string },
369 { DUNDI_IE_COUNTRY, "COUNTRY", dump_string },
370 { DUNDI_IE_EMAIL, "EMAIL", dump_string },
371 { DUNDI_IE_PHONE, "PHONE", dump_string },
372 { DUNDI_IE_IPADDR, "ADDRESS", dump_string },
373 { DUNDI_IE_CACHEBYPASS, "CBYPASS", dump_cbypass },
376 const char *dundi_ie2str(int ie)
379 for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
386 static void dump_ies(unsigned char *iedata, int spaces, int len)
399 /* Encrypted data is the remainder */
400 if (ie == DUNDI_IE_ENCDATA)
402 if (ielen + 2> len) {
403 snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
408 for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
409 if (ies[x].ie == ie) {
411 ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
412 snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), ies[x].name, interp);
416 snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
418 strcpy(interp, "Present");
419 snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), ies[x].name, interp);
426 snprintf(tmp, (int)sizeof(tmp), " %sUnknown IE %03d : Present\n", (spaces ? " " : "" ), ie);
429 iedata += (2 + ielen);
435 void dundi_showframe(struct dundi_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
464 char iabuf[INET_ADDRSTRLEN];
465 if (ntohs(fhi->dtrans) & DUNDI_FLAG_RETRANS)
466 strcpy(retries, "Yes");
468 strcpy(retries, "No");
469 if ((ntohs(fhi->strans) & DUNDI_FLAG_RESERVED)) {
470 /* Ignore frames with high bit set to 1 */
473 if ((fhi->cmdresp & 0x3f) > (int)sizeof(commands)/(int)sizeof(char *)) {
474 snprintf(class2, (int)sizeof(class2), "(%d?)", fhi->cmdresp);
477 class = commands[(int)(fhi->cmdresp & 0x3f)];
479 snprintf(subclass2, (int)sizeof(subclass2), "%02x", fhi->cmdflags);
480 subclass = subclass2;
481 snprintf(tmp, (int)sizeof(tmp),
482 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s (%s)\n",
484 retries, fhi->oseqno, fhi->iseqno, class, fhi->cmdresp & 0x40 ? "Response" : "Command");
486 snprintf(tmp, (int)sizeof(tmp),
487 "%s Flags: %s STrans: %5.5d DTrans: %5.5d [%s:%d]%s\n", (rx > 1) ? " " : "",
488 subclass, ntohs(fhi->strans) & ~DUNDI_FLAG_RESERVED, ntohs(fhi->dtrans) & ~DUNDI_FLAG_RETRANS,
489 ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
490 fhi->cmdresp & 0x80 ? " (Final)" : "");
492 dump_ies(fhi->ies, rx > 1, datalen);
495 int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
498 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
499 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
503 ied->buf[ied->pos++] = ie;
504 ied->buf[ied->pos++] = datalen;
505 memcpy(ied->buf + ied->pos, data, datalen);
510 int dundi_ie_append_cause(struct dundi_ie_data *ied, unsigned char ie, unsigned char cause, unsigned char *data)
513 int datalen = data ? strlen(data) + 1 : 1;
514 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
515 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
519 ied->buf[ied->pos++] = ie;
520 ied->buf[ied->pos++] = datalen;
521 ied->buf[ied->pos++] = cause;
522 memcpy(ied->buf + ied->pos, data, datalen-1);
523 ied->pos += datalen-1;
527 int dundi_ie_append_hint(struct dundi_ie_data *ied, unsigned char ie, unsigned short flags, unsigned char *data)
530 int datalen = data ? strlen(data) + 2 : 2;
531 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
532 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
536 ied->buf[ied->pos++] = ie;
537 ied->buf[ied->pos++] = datalen;
538 flags = htons(flags);
539 memcpy(ied->buf + ied->pos, &flags, sizeof(flags));
541 memcpy(ied->buf + ied->pos, data, datalen-1);
542 ied->pos += datalen-2;
546 int dundi_ie_append_encdata(struct dundi_ie_data *ied, unsigned char ie, unsigned char *iv, void *data, int datalen)
550 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
551 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
555 ied->buf[ied->pos++] = ie;
556 ied->buf[ied->pos++] = datalen;
557 memcpy(ied->buf + ied->pos, iv, 16);
560 memcpy(ied->buf + ied->pos, data, datalen-16);
561 ied->pos += datalen-16;
566 int dundi_ie_append_answer(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid, unsigned char protocol, unsigned short flags, unsigned short weight, unsigned char *data)
569 int datalen = data ? strlen(data) + 11 : 11;
572 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
573 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
577 ied->buf[ied->pos++] = ie;
578 ied->buf[ied->pos++] = datalen;
580 ied->buf[ied->pos++] = eid->eid[x];
581 ied->buf[ied->pos++] = protocol;
583 memcpy(ied->buf + ied->pos, &myw, 2);
586 memcpy(ied->buf + ied->pos, &myw, 2);
588 memcpy(ied->buf + ied->pos, data, datalen-11);
589 ied->pos += datalen-11;
593 int dundi_ie_append_addr(struct dundi_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
595 return dundi_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
598 int dundi_ie_append_int(struct dundi_ie_data *ied, unsigned char ie, unsigned int value)
601 newval = htonl(value);
602 return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
605 int dundi_ie_append_short(struct dundi_ie_data *ied, unsigned char ie, unsigned short value)
607 unsigned short newval;
608 newval = htons(value);
609 return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
612 int dundi_ie_append_str(struct dundi_ie_data *ied, unsigned char ie, unsigned char *str)
614 return dundi_ie_append_raw(ied, ie, str, strlen(str));
617 int dundi_ie_append_eid(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid)
619 return dundi_ie_append_raw(ied, ie, (unsigned char *)eid, sizeof(dundi_eid));
622 int dundi_ie_append_byte(struct dundi_ie_data *ied, unsigned char ie, unsigned char dat)
624 return dundi_ie_append_raw(ied, ie, &dat, 1);
627 int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie)
629 return dundi_ie_append_raw(ied, ie, NULL, 0);
632 void dundi_set_output(void (*func)(const char *))
637 void dundi_set_error(void (*func)(const char *))
642 int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen)
644 /* Parse data into information elements */
648 memset(ies, 0, (int)sizeof(struct dundi_ies));
650 ies->expiration = -1;
651 ies->unknowncmd = -1;
653 while(datalen >= 2) {
656 if (len > datalen - 2) {
657 errorf("Information element length exceeds message size\n");
662 case DUNDI_IE_EID_DIRECT:
663 if (len != (int)sizeof(dundi_eid)) {
664 errorf("Improper entity identifer, expecting 6 bytes!\n");
665 } else if (ies->eidcount < DUNDI_MAX_STACK) {
666 ies->eids[ies->eidcount] = (dundi_eid *)(data + 2);
667 ies->eid_direct[ies->eidcount] = (ie == DUNDI_IE_EID_DIRECT);
670 errorf("Too many entities in stack!\n");
672 case DUNDI_IE_REQEID:
673 if (len != (int)sizeof(dundi_eid)) {
674 errorf("Improper requested entity identifer, expecting 6 bytes!\n");
676 ies->reqeid = (dundi_eid *)(data + 2);
678 case DUNDI_IE_CALLED_CONTEXT:
679 ies->called_context = data + 2;
681 case DUNDI_IE_CALLED_NUMBER:
682 ies->called_number = data + 2;
684 case DUNDI_IE_ANSWER:
685 if (len < sizeof(struct dundi_answer)) {
686 snprintf(tmp, (int)sizeof(tmp), "Answer expected to be >=%d bytes long but was %d\n", (int)sizeof(struct dundi_answer), len);
689 if (ies->anscount < DUNDI_MAX_ANSWERS)
690 ies->answers[ies->anscount++]= (struct dundi_answer *)(data + 2);
692 errorf("Ignoring extra answers!\n");
696 if (len != (int)sizeof(unsigned short)) {
697 snprintf(tmp, (int)sizeof(tmp), "Expecting ttl to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
700 ies->ttl = ntohs(*((unsigned short *)(data + 2)));
702 case DUNDI_IE_VERSION:
703 if (len != (int)sizeof(unsigned short)) {
704 snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
707 ies->version = ntohs(*((unsigned short *)(data + 2)));
709 case DUNDI_IE_EXPIRATION:
710 if (len != (int)sizeof(unsigned short)) {
711 snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
714 ies->expiration = ntohs(*((unsigned short *)(data + 2)));
716 case DUNDI_IE_KEYCRC32:
717 if (len != (int)sizeof(unsigned int)) {
718 snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
721 ies->keycrc32 = ntohl(*((unsigned int *)(data + 2)));
723 case DUNDI_IE_UNKNOWN:
725 ies->unknowncmd = data[2];
727 snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
733 ies->cause = data[2];
734 ies->causestr = data + 3;
736 snprintf(tmp, (int)sizeof(tmp), "Expected at least one byte cause, but was %d long\n", len);
742 ies->hint = (struct dundi_hint *)(data + 2);
744 snprintf(tmp, (int)sizeof(tmp), "Expected at least two byte hint, but was %d long\n", len);
748 case DUNDI_IE_DEPARTMENT:
749 ies->q_dept = data + 2;
751 case DUNDI_IE_ORGANIZATION:
752 ies->q_org = data + 2;
754 case DUNDI_IE_LOCALITY:
755 ies->q_locality = data + 2;
757 case DUNDI_IE_STATE_PROV:
758 ies->q_stateprov = data + 2;
760 case DUNDI_IE_COUNTRY:
761 ies->q_country = data + 2;
764 ies->q_email = data + 2;
767 ies->q_phone = data + 2;
769 case DUNDI_IE_IPADDR:
770 ies->q_ipaddr = data + 2;
772 case DUNDI_IE_ENCDATA:
773 /* Recalculate len as the remainder of the message, regardless of
774 theoretical length */
776 if ((len > 16) && !(len % 16)) {
777 ies->encblock = (struct dundi_encblock *)(data + 2);
778 ies->enclen = len - 16;
780 snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted data length %d\n", len);
784 case DUNDI_IE_SHAREDKEY:
786 ies->encsharedkey = (unsigned char *)(data + 2);
788 snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted shared key length %d\n", len);
792 case DUNDI_IE_SIGNATURE:
794 ies->encsig = (unsigned char *)(data + 2);
796 snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted signature length %d\n", len);
800 case DUNDI_IE_CACHEBYPASS:
804 snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", dundi_ie2str(ie), ie, len);
807 /* Overwrite information element with 0, to null terminate previous portion */
809 datalen -= (len + 2);
812 /* Null-terminate last field */
815 errorf("Invalid information element contents, strange boundary\n");