18 #ifdef TGT_OS_TYPE_VXWORKS
30 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
31 #include <sys/socket.h>
33 #include <arpa/inet.h>
35 #error OS not supported for IP Socket Communications
71 this->m_recv_port = port;
79 U16 port = this->m_recv_port;
86 struct sockaddr_in address;
90 address.sin_family = AF_INET;
92 address.sin_port = htons(m_recv_port);
95 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN
96 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
104 if (::
bind(fd,
reinterpret_cast<struct sockaddr*
>(&address),
sizeof(address)) < 0) {
108 socklen_t size =
sizeof(address);
109 if (::getsockname(fd,
reinterpret_cast<struct sockaddr *
>(&address), &size) == -1) {
112 U16 port = ntohs(address.sin_port);
115 FW_ASSERT(
sizeof(this->m_state->
m_addr_recv) ==
sizeof(address),
sizeof(this->m_state->m_addr_recv),
sizeof(address));
116 memcpy(&this->m_state->
m_addr_recv, &address,
sizeof(this->m_state->m_addr_recv));
117 this->m_recv_port = port;
126 struct sockaddr_in address;
133 if ((socketFd = ::socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
140 address.sin_family = AF_INET;
142 address.sin_port = htons(this->
m_port);
146 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN
147 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
162 FW_ASSERT(
sizeof(this->m_state->
m_addr_send) ==
sizeof(address),
sizeof(this->m_state->m_addr_send),
164 memcpy(&this->m_state->
m_addr_send, &address,
sizeof(this->m_state->m_addr_send));
174 U16 recv_port = this->m_recv_port;
195 reinterpret_cast<struct sockaddr *
>(&this->m_state->
m_addr_send),
sizeof(this->m_state->m_addr_send)));
PlatformPointerCastType POINTER_CAST
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
C++-compatible configuration header for fprime configuration.
@ SOCKET_MAX_HOSTNAME_SIZE
Helper base-class for setting up Berkeley sockets.
void close()
closes the socket
U16 m_port
IP address port used.
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with host and transmission timeouts
static SocketIpStatus addressToIp4(const char *address, void *ip4)
converts a given address in dot form x.x.x.x to an ip address. ONLY works for IPv4.
virtual bool isValidPort(U16 port)
Check if the given port is valid for the socket.
SocketIpStatus setupTimeouts(NATIVE_INT_TYPE socketFd)
setup the socket timeout properties of the opened outgoing socket
U16 getRecvPort()
get the port being received on
SocketIpStatus bind(NATIVE_INT_TYPE fd)
bind the UDP to a port such that it can receive packets at the previously configured port
UdpSocket()
Constructor for client socket udp implementation.
SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd) override
udp specific implementation for opening a socket.
I32 sendProtocol(const U8 *const data, const U32 size) override
Protocol specific implementation of send. Called directly with retry from send.
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the udp socket for outgoing transmissions
I32 recvProtocol(U8 *const data, const U32 size) override
Protocol specific implementation of recv. Called directly with error handling from recv.
virtual ~UdpSocket()
to cleanup state created at instantiation
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
void unlock()
alias for unLock to meet BasicLockable requirements
void lock()
lock the mutex
SocketIpStatus
Status enumeration for socket return values.
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
@ SOCK_SUCCESS
Socket operation successful.
@ SOCK_FAILED_TO_BIND
Failed to bind to socket.
@ SOCK_FAILED_TO_GET_SOCKET
Socket open failed.
@ SOCK_FAILED_TO_READ_BACK_PORT
Failed to read back port from connection.
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
struct sockaddr_in m_addr_send
UDP server address, maybe unused.
struct sockaddr_in m_addr_recv
UDP server address, maybe unused.