Keith Bryer / udpBroadcastSocket
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers udpBroadcastSocket.cpp Source File

udpBroadcastSocket.cpp

00001 /*
00002  * UDPBroadcastSocket accept socket option flags parameter on bind or init
00003  * usage 
00004  *    mySocket.init(SO_BROADCAST); (not tested)
00005  *   or mySocket.bind(port,SO_BROADCAST); {tested, ok)
00006 
00007  * UDPBroadcastSocket accept socket option flags
00008  * These option flags per-socket from lwip\core\include\lwip\sockets.h
00009  */
00010 //#define  SO_DEBUG       0x0001 /* Unimplemented: turn on debugging info recording */
00011 //#define  SO_ACCEPTCONN  0x0002 /* socket has had listen() */
00012 //#define  SO_REUSEADDR   0x0004 /* Allow local address reuse */
00013 //#define  SO_KEEPALIVE   0x0008 /* keep connections alive */
00014 //#define  SO_DONTROUTE   0x0010 /* Unimplemented: just use interface addresses */
00015 //#define  SO_BROADCAST   0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
00016 //#define  SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
00017 //#define  SO_LINGER      0x0080 /* linger on close if data present */
00018 //#define  SO_OOBINLINE   0x0100 /* Unimplemented: leave received OOB data in line */
00019 //#define  SO_REUSEPORT   0x0200 /* Unimplemented: allow local address & port reuse */
00020 
00021 #include "udpBroadcastSocket.h"
00022 #include "Socket/UDPSocket.h"
00023 
00024 #include <cstring>
00025 
00026 using std::memset;
00027 
00028 int UDPBroadcastSocket::init(int optionFlags) {
00029     int option = 1;
00030     if (init_socket(SOCK_DGRAM)<0)
00031         return -1;
00032     else
00033         return lwip_setsockopt(_sock_fd,SOL_SOCKET,optionFlags,(char*)&option,sizeof(option));
00034 }
00035 
00036 int UDPBroadcastSocket::bind(int port,int optionFlags)
00037 {
00038     int option = 1;
00039     if (UDPSocket::bind(port)<0)
00040         return -1;
00041     else
00042         return lwip_setsockopt(_sock_fd,SOL_SOCKET,optionFlags,(char*)&option,sizeof(option));
00043 }