m_timeout.tv_usec = 0;
m_establishing = false;
m_reusable = false;
+ m_broadcast = false;
+ m_dobind = true;
assert(gs_gui_functions);
/* Per-socket GUI-specific initialization */
return false;
}
+/* GSocket_SetBroadcast:
+* Simply sets the m_broadcast flag on the socket. GSocket_SetServer will
+* make the appropriate setsockopt() call.
+* Implemented as a GSocket function because clients (ie, wxSocketServer)
+* don't have access to the GSocket struct information.
+* Returns true if the flag was set correctly, false if an error occurred
+* (ie, if the parameter was NULL)
+*/
+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:
{
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
}
-
- /* 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;
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);