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