Annotation of embedaddon/miniupnpd/minissdpd/printresponse.c, revision 1.1
1.1 ! misho 1: /* $Id: $ */
! 2: /* vim: tabstop=4 shiftwidth=4 noexpandtab
! 3: * Project : miniupnp
! 4: * website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
! 5: * Author : Thomas BERNARD
! 6: * copyright (c) 2005-2016 Thomas Bernard
! 7: * This software is subjet to the conditions detailed in the
! 8: * provided LICENCE file. */
! 9:
! 10: #include <stdio.h>
! 11: #include "codelength.h"
! 12:
! 13: #define NOTIF_NEW 1
! 14: #define NOTIF_UPDATE 2
! 15: #define NOTIF_REMOVE 3
! 16:
! 17: void printresponse(const unsigned char * resp, int n)
! 18: {
! 19: int i, l;
! 20: int notif_type;
! 21: unsigned int nresp;
! 22: const unsigned char * p;
! 23:
! 24: if(n == 0)
! 25: return;
! 26: /* first, hexdump the response : */
! 27: for(i = 0; i < n; i += 16) {
! 28: printf("%06x | ", i);
! 29: for(l = i; l < n && l < (i + 16); l++)
! 30: printf("%02x ", resp[l]);
! 31: while(l < (i + 16)) {
! 32: printf(" ");
! 33: l++;
! 34: }
! 35: printf("| ");
! 36: for(l = i; l < n && l < (i + 16); l++)
! 37: putchar((resp[l] >= ' ' && resp[l] < 128) ? resp[l] : '.');
! 38: putchar('\n');
! 39: }
! 40: for(p = resp; p < resp + n; ) {
! 41: /* now parse and display all devices of response */
! 42: nresp = p[0]; /* 1st byte : number of devices in response */
! 43: if(nresp == 0xff) {
! 44: /* notification */
! 45: notif_type = p[1];
! 46: nresp = p[2];
! 47: printf("Notification : ");
! 48: switch(notif_type) {
! 49: case NOTIF_NEW: printf("new\n"); break;
! 50: case NOTIF_UPDATE: printf("update\n"); break;
! 51: case NOTIF_REMOVE: printf("remove\n"); break;
! 52: default: printf("**UNKNOWN**\n");
! 53: }
! 54: p += 3;
! 55: } else {
! 56: p++;
! 57: }
! 58: for(i = 0; i < (int)nresp; i++) {
! 59: if(p >= resp + n)
! 60: goto error;
! 61: /*l = *(p++);*/
! 62: DECODELENGTH(l, p);
! 63: if(p + l > resp + n)
! 64: goto error;
! 65: printf("%d - %.*s\n", i, l, p); /* URL */
! 66: p += l;
! 67: if(p >= resp + n)
! 68: goto error;
! 69: /*l = *(p++);*/
! 70: DECODELENGTH(l, p);
! 71: if(p + l > resp + n)
! 72: goto error;
! 73: printf(" %.*s\n", l, p); /* ST */
! 74: p += l;
! 75: if(p >= resp + n)
! 76: goto error;
! 77: /*l = *(p++);*/
! 78: DECODELENGTH(l, p);
! 79: if(p + l > resp + n)
! 80: goto error;
! 81: printf(" %.*s\n", l, p); /* USN */
! 82: p += l;
! 83: }
! 84: }
! 85: return;
! 86: error:
! 87: printf("*** WARNING : TRUNCATED RESPONSE ***\n");
! 88: }
! 89:
! 90:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>