[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdelibs/kdecore/network
From: Thiago Macieira <thiago.macieira () kdemail ! net>
Date: 2004-08-01 2:39:23
Message-ID: 20040801023923.67E719985 () office ! kde ! org
[Download RAW message or body]
CVS commit by thiago:
Adding method and flag for SO_BROADCAST, which is needed to send datagrams
to broadcast addresses.
M +10 -0 ksocketbase.cpp 1.8
M +27 -3 ksocketbase.h 1.17
M +15 -1 ksocketdevice.cpp 1.18
--- kdelibs/kdecore/network/ksocketbase.h #1.16:1.17
@@ -112,4 +112,6 @@ public:
* - KeepAlive: whether TCP should send keepalive probes when a connection
* has gone idle for far too long.
+ * - Broadcast: whether this socket is allowed to send broadcast packets
+ * and will receive packets sent to broadcast.
*/
enum SocketOptions
@@ -118,5 +120,6 @@ public:
AddressReuseable = 0x02,
IPv6Only = 0x04,
- Keepalive = 0x08
+ Keepalive = 0x08,
+ Broadcast = 0x10
};
@@ -279,10 +282,31 @@ public:
* Retrieves this socket's IPv6 Only flag.
*
- * @returns true if this socket's address can be reused,
- * false if it can't.
+ * @returns true if this socket will ignore IPv4-compatible and IPv4-mapped
+ * addresses, false if it will accept them.
*/
bool isIPv6Only() const;
/**
+ * Sets this socket Broadcast flag.
+ *
+ * Datagram-oriented sockets cannot normally send packets to broadcast
+ * addresses, nor will they receive packets that were sent to a broadcast
+ * address. To do so, you need to enable the Broadcast flag.
+ *
+ * This option has no effect on stream-oriented sockets.
+ *
+ * @returns true if setting this flag was successful.
+ */
+ virtual bool setBroadcast(bool enable);
+
+ /**
+ * Retrieves this socket's Broadcast flag.
+ *
+ * @returns true if this socket can send and receive broadcast packets,
+ * false if it can't.
+ */
+ bool broadcast() const;
+
+ /**
* Retrieves the socket implementation used on this socket.
*
--- kdelibs/kdecore/network/ksocketbase.cpp #1.7:1.8
@@ -104,4 +104,14 @@ bool KSocketBase::isIPv6Only() const
}
+bool KSocketBase::setBroadcast(bool enable)
+{
+ return setSocketOptions((socketOptions() & ~Broadcast) | (enable ? Broadcast : 0));
+}
+
+bool KSocketBase::broadcast() const
+{
+ return socketOptions() & Broadcast;
+}
+
KSocketDevice* KSocketBase::socketDevice() const
{
--- kdelibs/kdecore/network/ksocketdevice.cpp #1.17:1.18
@@ -61,4 +61,5 @@ class KNetwork::KSocketDevicePrivate
public:
mutable QSocketNotifier *input, *output, *exception;
+ int af;
inline KSocketDevicePrivate()
@@ -138,6 +139,9 @@ bool KSocketDevice::setSocketOptions(int
}
-#ifdef IPV6_V6ONLY
+#if defined(IPV6_V6ONLY) && defined(AF_INET6)
+ if (d->af == AF_INET6)
{
+ // don't try this on non-IPv6 sockets, or we'll get an error
+
int on = opts & IPv6Only ? 1 : 0;
if (setsockopt(m_sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&on, sizeof(on)) == -1)
@@ -149,4 +153,13 @@ bool KSocketDevice::setSocketOptions(int
#endif
+ {
+ int on = opts & Broadcast ? 1 : 0;
+ if (setsockopt(m_sockfd, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on)) == -1)
+ {
+ setError(IO_UnspecifiedError, UnknownError);
+ return false; // error
+ }
+ }
+
return true; // all went well
}
@@ -197,4 +210,5 @@ bool KSocketDevice::create(int family, i
setSocketOptions(socketOptions());
+ d->af = family;
return true; // successfully created
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic