Added --ifr-name name command line option to enable the broacaster to customize the ifreq.ifr_name

This commit is contained in:
Robert Osfield
2017-03-30 17:02:37 +01:00
parent a30e5df6f2
commit ad0434c415
3 changed files with 34 additions and 13 deletions

View File

@@ -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;