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

Generated on Tue Jun 18 13:16:50 2013 for live by  doxygen 1.5.2