added support for broadcasting to UDP sockets (patch 1740266)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -533,6 +533,8 @@ GSocket::GSocket()
|
||||
m_gui_dependent = NULL;
|
||||
m_non_blocking = false;
|
||||
m_reusable = false;
|
||||
m_broadcast = false;
|
||||
m_dobind = true;
|
||||
m_timeout = 10*60*1000;
|
||||
/* 10 minutes * 60 sec * 1000 millisec */
|
||||
m_establishing = false;
|
||||
@@ -903,6 +905,26 @@ bool GSocket::SetReusable()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GSocket::SetBroadcast()
|
||||
{
|
||||
/* socket must not be in use/already bound */
|
||||
if (m_fd == INVALID_SOCKET) {
|
||||
m_broadcast = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GSocket::DontDoBind()
|
||||
{
|
||||
/* socket must not be in use/already bound */
|
||||
if (m_fd == INVALID_SOCKET) {
|
||||
m_dobind = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Client specific parts */
|
||||
|
||||
/* GSocket_Connect:
|
||||
@@ -1119,19 +1141,25 @@ GSocketError GSocket::SetNonOriented()
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Bind to the local address,
|
||||
* and retrieve the actual address bound.
|
||||
*/
|
||||
if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
|
||||
(getsockname(m_fd,
|
||||
m_local->m_addr,
|
||||
(WX_SOCKLEN_T *) &m_local->m_len) != 0))
|
||||
if (m_broadcast)
|
||||
{
|
||||
Close();
|
||||
m_error = GSOCK_IOERR;
|
||||
return GSOCK_IOERR;
|
||||
setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST, (const char*)&arg, sizeof(arg));
|
||||
}
|
||||
if (m_dobind)
|
||||
{
|
||||
/* Bind to the local address,
|
||||
* and retrieve the actual address bound.
|
||||
*/
|
||||
if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
|
||||
(getsockname(m_fd,
|
||||
m_local->m_addr,
|
||||
(WX_SOCKLEN_T *) &m_local->m_len) != 0))
|
||||
{
|
||||
Close();
|
||||
m_error = GSOCK_IOERR;
|
||||
return GSOCK_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
return GSOCK_NOERROR;
|
||||
}
|
||||
|
||||
@@ -2068,6 +2096,12 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
|
||||
return GSOCK_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
|
||||
}
|
||||
|
||||
GSocketError GAddress_INET_SetAnyAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_ANY);
|
||||
|
||||
Reference in New Issue
Block a user