Setting the SO_BROADCAST
Option
The SO_BROADCAST option
is a Boolean flag option, which is defined, fetched, and set with the int data
type. The following example shows how to enable the SO_BROADCAST Option:
Example
#define TRUE 1
#define FALSE 0
int z; /* Status code */
int s; /* Socket s */
int so_broadcast;
. . .
so_broadcast =
TRUE;
z = setsockopt(s,
SOL_SOCKET,
SO_BROADCAST,
&so_broadcast,
sizeof so_broadcast);
if ( z ) {
perror("setsockopt(2)");
}
If the setsockopt(2)
function returns zero, the socket s has been enabled to perform broadcasting.
Note, however, that the socket type chosen must be one that is capable of broadcasting,
such as a UDP socket.
See Also
SO_PASSCRED & SO_PEERCRED, SO_KEEPALIVE, SO_LINGER, SO_REUSEADD, SO_OBINLINE, SO_TYPE
No comments:
Post a Comment