groupsock/include/GroupsockHelper.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-2014 Live Networks, Inc.  All rights reserved.
00018 // Helper routines to implement 'group sockets'
00019 // C++ header
00020 
00021 #ifndef _GROUPSOCK_HELPER_HH
00022 #define _GROUPSOCK_HELPER_HH
00023 
00024 #ifndef _NET_ADDRESS_HH
00025 #include "NetAddress.hh"
00026 #endif
00027 
00028 int setupDatagramSocket(UsageEnvironment& env, Port port);
00029 int setupStreamSocket(UsageEnvironment& env,
00030                       Port port, Boolean makeNonBlocking = True);
00031 
00032 int readSocket(UsageEnvironment& env,
00033                int socket, unsigned char* buffer, unsigned bufferSize,
00034                struct sockaddr_in& fromAddress);
00035 
00036 Boolean writeSocket(UsageEnvironment& env,
00037                     int socket, struct in_addr address, Port port,
00038                     u_int8_t ttlArg,
00039                     unsigned char* buffer, unsigned bufferSize);
00040 
00041 Boolean writeSocket(UsageEnvironment& env,
00042                     int socket, struct in_addr address, Port port,
00043                     unsigned char* buffer, unsigned bufferSize);
00044     // An optimized version of "writeSocket" that omits the "setsockopt()" call to set the TTL.
00045 
00046 unsigned getSendBufferSize(UsageEnvironment& env, int socket);
00047 unsigned getReceiveBufferSize(UsageEnvironment& env, int socket);
00048 unsigned setSendBufferTo(UsageEnvironment& env,
00049                          int socket, unsigned requestedSize);
00050 unsigned setReceiveBufferTo(UsageEnvironment& env,
00051                             int socket, unsigned requestedSize);
00052 unsigned increaseSendBufferTo(UsageEnvironment& env,
00053                               int socket, unsigned requestedSize);
00054 unsigned increaseReceiveBufferTo(UsageEnvironment& env,
00055                                  int socket, unsigned requestedSize);
00056 
00057 Boolean makeSocketNonBlocking(int sock);
00058 Boolean makeSocketBlocking(int sock);
00059 
00060 Boolean socketJoinGroup(UsageEnvironment& env, int socket,
00061                         netAddressBits groupAddress);
00062 Boolean socketLeaveGroup(UsageEnvironment&, int socket,
00063                          netAddressBits groupAddress);
00064 
00065 // source-specific multicast join/leave
00066 Boolean socketJoinGroupSSM(UsageEnvironment& env, int socket,
00067                            netAddressBits groupAddress,
00068                            netAddressBits sourceFilterAddr);
00069 Boolean socketLeaveGroupSSM(UsageEnvironment&, int socket,
00070                             netAddressBits groupAddress,
00071                             netAddressBits sourceFilterAddr);
00072 
00073 Boolean getSourcePort(UsageEnvironment& env, int socket, Port& port);
00074 
00075 netAddressBits ourIPAddress(UsageEnvironment& env); // in network order
00076 
00077 // IP addresses of our sending and receiving interfaces.  (By default, these
00078 // are INADDR_ANY (i.e., 0), specifying the default interface.)
00079 extern netAddressBits SendingInterfaceAddr;
00080 extern netAddressBits ReceivingInterfaceAddr;
00081 
00082 // Allocates a randomly-chosen IPv4 SSM (multicast) address:
00083 netAddressBits chooseRandomIPv4SSMAddress(UsageEnvironment& env);
00084 
00085 // Returns a simple "hh:mm:ss" string, for use in debugging output (e.g.)
00086 char const* timestampString();
00087 
00088 
00089 #ifdef HAVE_SOCKADDR_LEN
00090 #define SET_SOCKADDR_SIN_LEN(var) var.sin_len = sizeof var
00091 #else
00092 #define SET_SOCKADDR_SIN_LEN(var)
00093 #endif
00094 
00095 #define MAKE_SOCKADDR_IN(var,adr,prt) /*adr,prt must be in network order*/\
00096     struct sockaddr_in var;\
00097     var.sin_family = AF_INET;\
00098     var.sin_addr.s_addr = (adr);\
00099     var.sin_port = (prt);\
00100     SET_SOCKADDR_SIN_LEN(var);
00101 
00102 
00103 // By default, we create sockets with the SO_REUSE_* flag set.
00104 // If, instead, you want to create sockets without the SO_REUSE_* flags,
00105 // Then enclose the creation code with:
00106 //          {
00107 //            NoReuse dummy;
00108 //            ...
00109 //          }
00110 class NoReuse {
00111 public:
00112   NoReuse(UsageEnvironment& env);
00113   ~NoReuse();
00114 
00115 private:
00116   UsageEnvironment& fEnv;
00117 };
00118 
00119 
00120 // Define the "UsageEnvironment"-specific "groupsockPriv" structure:
00121 
00122 struct _groupsockPriv { // There should be only one of these allocated
00123   HashTable* socketTable;
00124   int reuseFlag;
00125 };
00126 _groupsockPriv* groupsockPriv(UsageEnvironment& env); // allocates it if necessary
00127 void reclaimGroupsockPriv(UsageEnvironment& env);
00128 
00129 
00130 #if defined(__WIN32__) || defined(_WIN32)
00131 // For Windoze, we need to implement our own gettimeofday()
00132 extern int gettimeofday(struct timeval*, int*);
00133 #endif
00134 
00135 // The following are implemented in inet.c:
00136 extern "C" netAddressBits our_inet_addr(char const*);
00137 extern "C" void our_srandom(int x);
00138 extern "C" long our_random();
00139 extern "C" u_int32_t our_random32(); // because "our_random()" returns a 31-bit number
00140 
00141 #endif

Generated on Tue Mar 25 14:35:34 2014 for live by  doxygen 1.5.2