print-mobile.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* $NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */
  2. /*
  3. * (c) 1998 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Heiko W.Rupp <hwr@pilhuhn.de>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the NetBSD
  20. * Foundation, Inc. and its contributors.
  21. * 4. Neither the name of The NetBSD Foundation nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  26. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  29. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /* \summary: IPv4 mobility printer */
  38. #ifdef HAVE_CONFIG_H
  39. #include "config.h"
  40. #endif
  41. #include <netdissect-stdinc.h>
  42. #include "netdissect.h"
  43. #include "addrtoname.h"
  44. #include "extract.h"
  45. #define MOBILE_SIZE (8)
  46. struct mobile_ip {
  47. uint16_t proto;
  48. uint16_t hcheck;
  49. uint32_t odst;
  50. uint32_t osrc;
  51. };
  52. #define OSRC_PRES 0x0080 /* old source is present */
  53. /*
  54. * Deencapsulate and print a mobile-tunneled IP datagram
  55. */
  56. void
  57. mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
  58. {
  59. const struct mobile_ip *mob;
  60. struct cksum_vec vec[1];
  61. u_short proto,crc;
  62. u_char osp =0; /* old source address present */
  63. mob = (const struct mobile_ip *)bp;
  64. if (length < MOBILE_SIZE || !ND_TTEST(*mob)) {
  65. ND_PRINT((ndo, "[|mobile]"));
  66. return;
  67. }
  68. ND_PRINT((ndo, "mobile: "));
  69. proto = EXTRACT_16BITS(&mob->proto);
  70. crc = EXTRACT_16BITS(&mob->hcheck);
  71. if (proto & OSRC_PRES) {
  72. osp=1;
  73. }
  74. if (osp) {
  75. ND_PRINT((ndo, "[S] "));
  76. if (ndo->ndo_vflag)
  77. ND_PRINT((ndo, "%s ", ipaddr_string(ndo, &mob->osrc)));
  78. } else {
  79. ND_PRINT((ndo, "[] "));
  80. }
  81. if (ndo->ndo_vflag) {
  82. ND_PRINT((ndo, "> %s ", ipaddr_string(ndo, &mob->odst)));
  83. ND_PRINT((ndo, "(oproto=%d)", proto>>8));
  84. }
  85. vec[0].ptr = (const uint8_t *)(const void *)mob;
  86. vec[0].len = osp ? 12 : 8;
  87. if (in_cksum(vec, 1)!=0) {
  88. ND_PRINT((ndo, " (bad checksum %d)", crc));
  89. }
  90. }