groupsock/include/TunnelEncaps.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "mTunnel" multicast access service
00017 // Copyright (c) 1996-2008 Live Networks, Inc.  All rights reserved.
00018 // Encapsulation trailer for tunnels
00019 // C++ header
00020 
00021 #ifndef _TUNNEL_ENCAPS_HH
00022 #define _TUNNEL_ENCAPS_HH
00023 
00024 #ifndef _NET_ADDRESS_HH
00025 #include "NetAddress.hh"
00026 #endif
00027 
00028 typedef u_int16_t Cookie;
00029 
00030 class TunnelEncapsulationTrailer {
00031         // The trailer is layed out as follows:
00032         // bytes 0-1:   source 'cookie'
00033         // bytes 2-3:   destination 'cookie'
00034         // bytes 4-7:   address
00035         // bytes 8-9:   port
00036         // byte 10:     ttl
00037         // byte 11:     command
00038 
00039         // Optionally, there may also be a 4-byte 'auxilliary address'
00040         // (e.g., for 'source-specific multicast' preceding this)
00041         // bytes -4 through -1: auxilliary address
00042 
00043     public:
00044         Cookie& srcCookie()
00045                 { return *(Cookie*)byteOffset(0); }
00046         Cookie& dstCookie()
00047                 { return *(Cookie*)byteOffset(2); }
00048         u_int32_t& address()
00049                 { return *(u_int32_t*)byteOffset(4); }
00050         Port& port()
00051                 { return *(Port*)byteOffset(8); }
00052         u_int8_t& ttl()
00053                 { return *(u_int8_t*)byteOffset(10); }
00054         u_int8_t& command()
00055                 { return *(u_int8_t*)byteOffset(11); }
00056 
00057         u_int32_t& auxAddress()
00058                 { return *(u_int32_t*)byteOffset(-4); }
00059 
00060     private:
00061         inline char* byteOffset(int charIndex)
00062                 { return ((char*)this) + charIndex; }
00063 };
00064 
00065 const unsigned TunnelEncapsulationTrailerSize = 12; // bytes
00066 const unsigned TunnelEncapsulationTrailerAuxSize = 4; // bytes
00067 const unsigned TunnelEncapsulationTrailerMaxSize
00068     = TunnelEncapsulationTrailerSize + TunnelEncapsulationTrailerAuxSize;
00069 
00070 // Command codes:
00071 // 0: unused
00072 const u_int8_t TunnelDataCmd = 1;
00073 const u_int8_t TunnelJoinGroupCmd = 2;
00074 const u_int8_t TunnelLeaveGroupCmd = 3;
00075 const u_int8_t TunnelTearDownCmd = 4;
00076 const u_int8_t TunnelProbeCmd = 5;
00077 const u_int8_t TunnelProbeAckCmd = 6;
00078 const u_int8_t TunnelProbeNackCmd = 7;
00079 const u_int8_t TunnelJoinRTPGroupCmd = 8;
00080 const u_int8_t TunnelLeaveRTPGroupCmd = 9;
00081 // 0x0A through 0x10: currently unused.
00082 const u_int8_t TunnelExtensionFlag = 0x80; // a flag, not a cmd code
00083 const u_int8_t TunnelDataAuxCmd
00084     = (TunnelExtensionFlag|TunnelDataCmd);
00085 const u_int8_t TunnelJoinGroupAuxCmd
00086     = (TunnelExtensionFlag|TunnelJoinGroupCmd);
00087 const u_int8_t TunnelLeaveGroupAuxCmd
00088     = (TunnelExtensionFlag|TunnelLeaveGroupCmd);
00089 // Note: the TearDown, Probe, ProbeAck, ProbeNack cmds have no Aux version
00090 // 0x84 through 0x87: currently unused.
00091 const u_int8_t TunnelJoinRTPGroupAuxCmd
00092     = (TunnelExtensionFlag|TunnelJoinRTPGroupCmd);
00093 const u_int8_t TunnelLeaveRTPGroupAuxCmd
00094     = (TunnelExtensionFlag|TunnelLeaveRTPGroupCmd);
00095 // 0x8A through 0xFF: currently unused
00096 
00097 inline Boolean TunnelIsAuxCmd(u_int8_t cmd) {
00098   return (cmd&TunnelExtensionFlag) != 0;
00099 }
00100 
00101 #endif

Generated on Tue Oct 7 15:38:08 2008 for live by  doxygen 1.5.2