TunnelEncaps.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "mTunnel" multicast access service
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // Encapsulation trailer for tunnels
  17. // C++ header
  18. #ifndef _TUNNEL_ENCAPS_HH
  19. #define _TUNNEL_ENCAPS_HH
  20. #ifndef _NET_ADDRESS_HH
  21. #include "NetAddress.hh"
  22. #endif
  23. typedef u_int16_t Cookie;
  24. class TunnelEncapsulationTrailer {
  25. // The trailer is layed out as follows:
  26. // bytes 0-1: source 'cookie'
  27. // bytes 2-3: destination 'cookie'
  28. // bytes 4-7: address
  29. // bytes 8-9: port
  30. // byte 10: ttl
  31. // byte 11: command
  32. // Optionally, there may also be a 4-byte 'auxilliary address'
  33. // (e.g., for 'source-specific multicast' preceding this)
  34. // bytes -4 through -1: auxilliary address
  35. public:
  36. Cookie& srcCookie()
  37. { return *(Cookie*)byteOffset(0); }
  38. Cookie& dstCookie()
  39. { return *(Cookie*)byteOffset(2); }
  40. u_int32_t& address()
  41. { return *(u_int32_t*)byteOffset(4); }
  42. Port& port()
  43. { return *(Port*)byteOffset(8); }
  44. u_int8_t& ttl()
  45. { return *(u_int8_t*)byteOffset(10); }
  46. u_int8_t& command()
  47. { return *(u_int8_t*)byteOffset(11); }
  48. u_int32_t& auxAddress()
  49. { return *(u_int32_t*)byteOffset(-4); }
  50. private:
  51. inline char* byteOffset(int charIndex)
  52. { return ((char*)this) + charIndex; }
  53. };
  54. const unsigned TunnelEncapsulationTrailerSize = 12; // bytes
  55. const unsigned TunnelEncapsulationTrailerAuxSize = 4; // bytes
  56. const unsigned TunnelEncapsulationTrailerMaxSize
  57. = TunnelEncapsulationTrailerSize + TunnelEncapsulationTrailerAuxSize;
  58. // Command codes:
  59. // 0: unused
  60. const u_int8_t TunnelDataCmd = 1;
  61. const u_int8_t TunnelJoinGroupCmd = 2;
  62. const u_int8_t TunnelLeaveGroupCmd = 3;
  63. const u_int8_t TunnelTearDownCmd = 4;
  64. const u_int8_t TunnelProbeCmd = 5;
  65. const u_int8_t TunnelProbeAckCmd = 6;
  66. const u_int8_t TunnelProbeNackCmd = 7;
  67. const u_int8_t TunnelJoinRTPGroupCmd = 8;
  68. const u_int8_t TunnelLeaveRTPGroupCmd = 9;
  69. // 0x0A through 0x10: currently unused.
  70. const u_int8_t TunnelExtensionFlag = 0x80; // a flag, not a cmd code
  71. const u_int8_t TunnelDataAuxCmd
  72. = (TunnelExtensionFlag|TunnelDataCmd);
  73. const u_int8_t TunnelJoinGroupAuxCmd
  74. = (TunnelExtensionFlag|TunnelJoinGroupCmd);
  75. const u_int8_t TunnelLeaveGroupAuxCmd
  76. = (TunnelExtensionFlag|TunnelLeaveGroupCmd);
  77. // Note: the TearDown, Probe, ProbeAck, ProbeNack cmds have no Aux version
  78. // 0x84 through 0x87: currently unused.
  79. const u_int8_t TunnelJoinRTPGroupAuxCmd
  80. = (TunnelExtensionFlag|TunnelJoinRTPGroupCmd);
  81. const u_int8_t TunnelLeaveRTPGroupAuxCmd
  82. = (TunnelExtensionFlag|TunnelLeaveRTPGroupCmd);
  83. // 0x8A through 0xFF: currently unused
  84. inline Boolean TunnelIsAuxCmd(u_int8_t cmd) {
  85. return (cmd&TunnelExtensionFlag) != 0;
  86. }
  87. #endif