You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
7 years ago
7 years ago
​
7 years ago
​
7 years ago
​
​
7 years ago
​
​
​
​
7 years ago
7 years ago
​
​
7 years ago
​
​
7 years ago
​
7 years ago
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
7 years ago
7 years ago
​
​
7 years ago
7 years ago
​
​
7 years ago
7 years ago
​
​
7 years ago
​
7 years ago
​
7 years ago
7 years ago
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
  1. /* $Id: printresponse.c,v 1.2 2016/01/19 10:24:59 nanard Exp $ */
  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. #include "codelength.h"
  10. #include <stdio.h>
  11. #define NOTIF_NEW 1
  12. #define NOTIF_UPDATE 2
  13. #define NOTIF_REMOVE 3
  14. void printresponse(const unsigned char * resp, int n)
  15. {
  16. int i, l;
  17. int notif_type;
  18. unsigned int nresp;
  19. const unsigned char * p;
  20. if (n == 0)
  21. {
  22. return;
  23. }
  24. /* first, hexdump the response : */
  25. for (i = 0; i < n; i += 16)
  26. {
  27. printf("%06x | ", i);
  28. for (l = i; l < n && l < (i + 16); l++)
  29. {
  30. printf("%02x ", resp[l]);
  31. }
  32. while (l < (i + 16))
  33. {
  34. printf(" ");
  35. l++;
  36. }
  37. printf("| ");
  38. for (l = i; l < n && l < (i + 16); l++)
  39. {
  40. putchar((resp[l] >= ' ' && resp[l] < 128) ? resp[l] : '.');
  41. }
  42. putchar('\n');
  43. }
  44. for (p = resp; p < resp + n;)
  45. {
  46. /* now parse and display all devices of response */
  47. nresp = p[0]; /* 1st byte : number of devices in response */
  48. if (nresp == 0xff)
  49. {
  50. /* notification */
  51. notif_type = p[1];
  52. nresp = p[2];
  53. printf("Notification : ");
  54. switch (notif_type)
  55. {
  56. case NOTIF_NEW : printf("new\n"); break;
  57. case NOTIF_UPDATE: printf("update\n"); break;
  58. case NOTIF_REMOVE: printf("remove\n"); break;
  59. default : printf("**UNKNOWN**\n");
  60. }
  61. p += 3;
  62. }
  63. else
  64. {
  65. p++;
  66. }
  67. for (i = 0; i < (int) nresp; i++)
  68. {
  69. if (p >= resp + n)
  70. {
  71. goto error;
  72. }
  73. /*l = *(p++);*/
  74. DECODELENGTH(l, p);
  75. if (p + l > resp + n)
  76. {
  77. goto error;
  78. }
  79. printf("%d - %.*s\n", i, l, p); /* URL */
  80. p += l;
  81. if (p >= resp + n)
  82. {
  83. goto error;
  84. }
  85. /*l = *(p++);*/
  86. DECODELENGTH(l, p);
  87. if (p + l > resp + n)
  88. {
  89. goto error;
  90. }
  91. printf(" %.*s\n", l, p); /* ST */
  92. p += l;
  93. if (p >= resp + n)
  94. {
  95. goto error;
  96. }
  97. /*l = *(p++);*/
  98. DECODELENGTH(l, p);
  99. if (p + l > resp + n)
  100. {
  101. goto error;
  102. }
  103. printf(" %.*s\n", l, p); /* USN */
  104. p += l;
  105. }
  106. }
  107. return;
  108. error:
  109. printf("*** WARNING : TRUNCATED RESPONSE ***\n");
  110. }