Added --ifr-name name command line option to enable the broacaster to customize the ifreq.ifr_name
This commit is contained in:
@@ -68,6 +68,13 @@
|
||||
|
||||
Broadcaster::Broadcaster( void )
|
||||
{
|
||||
#if defined (__linux) || defined(__CYGWIN__)
|
||||
_ifr_name = "eth0";
|
||||
#elif defined(__sun)
|
||||
_ifr_name = "hme0";
|
||||
#elif !defined (WIN32)
|
||||
_ifr_name = "ef0";
|
||||
#endif
|
||||
_port = 0;
|
||||
_initialized = false;
|
||||
_buffer = 0L;
|
||||
@@ -128,19 +135,14 @@ bool Broadcaster::init( void )
|
||||
#if !defined (WIN32) || defined(__CYGWIN__)
|
||||
struct ifreq ifr;
|
||||
#endif
|
||||
#if defined (__linux) || defined(__CYGWIN__)
|
||||
strcpy( ifr.ifr_name, "eth0" );
|
||||
#elif defined(__sun)
|
||||
strcpy( ifr.ifr_name, "hme0" );
|
||||
#elif !defined (WIN32)
|
||||
strcpy( ifr.ifr_name, "ef0" );
|
||||
#endif
|
||||
strcpy( ifr.ifr_name, _ifr_name.c_str());
|
||||
#if defined (WIN32) // get the server address
|
||||
saddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||
}
|
||||
#else
|
||||
if( (ioctl( _so, SIOCGIFBRDADDR, &ifr)) < 0 )
|
||||
{
|
||||
printf(" ifr.ifr_name = %s\n",ifr.ifr_name);
|
||||
perror( "Broadcaster::init() Cannot get Broadcast Address" );
|
||||
return false;
|
||||
}
|
||||
@@ -161,6 +163,11 @@ bool Broadcaster::init( void )
|
||||
return _initialized;
|
||||
}
|
||||
|
||||
void Broadcaster::setIFRName( const std::string& name )
|
||||
{
|
||||
_ifr_name = name;
|
||||
}
|
||||
|
||||
void Broadcaster::setHost( const char *hostname )
|
||||
{
|
||||
struct hostent *h;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef __BROADCASTER_H
|
||||
#define __BROADCASTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Broadcaster.h
|
||||
//
|
||||
@@ -44,6 +46,10 @@ class Broadcaster
|
||||
// Set the buffer to be broadcast
|
||||
void setBuffer( void *buffer, const unsigned int buffer_size );
|
||||
|
||||
// Set the IFRName i.e. eth0, will default to platform appropriate setting where possible.
|
||||
void setIFRName( const std::string& name );
|
||||
|
||||
|
||||
// Set a recipient host. If this is used, the Broadcaster
|
||||
// no longer broadcasts, but rather directs UDP packets at
|
||||
// host.
|
||||
@@ -56,6 +62,9 @@ class Broadcaster
|
||||
bool init( void );
|
||||
|
||||
private :
|
||||
|
||||
std::string _ifr_name;
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
SOCKET _so;
|
||||
#else
|
||||
|
||||
@@ -488,6 +488,17 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
// objects for managing the broadcasting and receiving of camera packets.
|
||||
Broadcaster bc;
|
||||
Receiver rc;
|
||||
|
||||
std::string ifrName;
|
||||
if (arguments.read("--ifr-name", ifrName)) { bc.setIFRName(ifrName); }
|
||||
|
||||
bc.setPort(static_cast<short int>(socketNumber));
|
||||
rc.setPort(static_cast<short int>(socketNumber));
|
||||
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
@@ -541,12 +552,6 @@ int main( int argc, char **argv )
|
||||
|
||||
CameraPacket *cp = new CameraPacket;
|
||||
|
||||
// objects for managing the broadcasting and receiving of camera packets.
|
||||
Broadcaster bc;
|
||||
Receiver rc;
|
||||
|
||||
bc.setPort(static_cast<short int>(socketNumber));
|
||||
rc.setPort(static_cast<short int>(socketNumber));
|
||||
|
||||
bool masterKilled = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user