28 #ifndef INCLUDE_OLA_NETWORK_SOCKET_H_
29 #define INCLUDE_OLA_NETWORK_SOCKET_H_
37 #include <sys/socket.h>
38 #include <netinet/in.h>
42 #include <ola/io/Descriptor.h>
43 #include <ola/io/IOQueue.h>
44 #include <ola/network/IPV4Address.h>
45 #include <ola/network/SocketAddress.h>
61 virtual bool Init() = 0;
65 bool Bind(
const IPV4Address &ip,
unsigned short port) {
71 virtual bool Close() = 0;
72 virtual int ReadDescriptor()
const = 0;
73 virtual int WriteDescriptor()
const = 0;
75 virtual ssize_t SendTo(
const uint8_t *buffer,
78 unsigned short port)
const = 0;
79 virtual ssize_t SendTo(
const uint8_t *buffer,
84 unsigned short port)
const = 0;
88 virtual bool RecvFrom(uint8_t *buffer, ssize_t *data_read)
const = 0;
89 virtual bool RecvFrom(uint8_t *buffer,
92 virtual bool RecvFrom(uint8_t *buffer,
95 uint16_t &port)
const = 0;
97 virtual bool EnableBroadcast() = 0;
98 virtual bool SetMulticastInterface(
const IPV4Address &iface) = 0;
99 virtual bool JoinMulticast(
const IPV4Address &iface,
101 bool loop =
false) = 0;
102 virtual bool LeaveMulticast(
const IPV4Address &iface,
104 virtual bool SetTos(uint8_t tos) = 0;
118 m_fd(ola::io::INVALID_DESCRIPTOR),
119 m_bound_to_port(
false) {}
127 int ReadDescriptor()
const {
return m_fd; }
128 int WriteDescriptor()
const {
return m_fd; }
129 ssize_t SendTo(
const uint8_t *buffer,
132 unsigned short port)
const;
133 ssize_t SendTo(
const uint8_t *buffer,
136 return SendTo(buffer, size, dest.Host(), dest.Port());
140 unsigned short port)
const;
143 return SendTo(data, dest.Host(), dest.Port());
146 bool RecvFrom(uint8_t *buffer, ssize_t *data_read)
const;
147 bool RecvFrom(uint8_t *buffer,
150 bool RecvFrom(uint8_t *buffer,
153 uint16_t &port)
const;
155 bool EnableBroadcast();
163 bool SetTos(uint8_t tos);
167 bool m_bound_to_port;
170 bool _RecvFrom(uint8_t *buffer,
172 struct sockaddr_in *source,
173 socklen_t *src_size)
const;
177 #endif // INCLUDE_OLA_NETWORK_SOCKET_H_