|  | F´ Flight Software - C/C++ Documentation
    NASA-v1.6.0
    A framework for building embedded system applications to NASA flight quality standards. | 
 
 
 
Go to the documentation of this file.
   14 #include <Fw/Types/Assert.hpp> 
   15 #include <Fw/Types/BasicTypes.hpp> 
   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 
   68     this->m_recv_port = port;
 
   75     struct sockaddr_in address;
 
   80     address.sin_family = AF_INET;
 
   81     address.sin_port = htons(m_recv_port);
 
   83 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN 
   84     address.sin_len = 
static_cast<U8>(
sizeof(
struct sockaddr_in));
 
   92     if (::
bind(fd, 
reinterpret_cast<struct sockaddr*
>(&address), 
sizeof(address)) < 0) {
 
   95     FW_ASSERT(
sizeof(this->m_state->
m_addr_recv) == 
sizeof(address), 
sizeof(this->m_state->m_addr_recv), 
sizeof(address));
 
   96     memcpy(&this->m_state->
m_addr_recv, &address, 
sizeof(this->m_state->m_addr_recv));
 
  103     struct sockaddr_in address;
 
  106     if (
m_port == 0 && m_recv_port == 0) {
 
  111     if ((socketFd = ::socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
 
  118         address.sin_family = AF_INET;
 
  119         address.sin_port = htons(this->
m_port);
 
  122 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN 
  123         address.sin_len = 
static_cast<U8>(
sizeof(
struct sockaddr_in));
 
  138         FW_ASSERT(
sizeof(this->m_state->
m_addr_send) == 
sizeof(address), 
sizeof(this->m_state->m_addr_send),
 
  140         memcpy(&this->m_state->
m_addr_send, &address, 
sizeof(this->m_state->m_addr_send));
 
  144     if ((m_recv_port != 0)  && ((status = this->
bind(socketFd)) != 
SOCK_SUCCESS)) {
 
  148     const char* actions = (m_recv_port != 0 && 
m_port != 0) ? 
"send and receive" : ((
m_port != 0) ? 
"send": 
"receive");
 
  149     Fw::Logger::logMsg(
"Setup to %s udp to %s:%hu\n", 
reinterpret_cast<POINTER_CAST
>(actions),
 
  159                     reinterpret_cast<struct sockaddr *
>(&this->m_state->
m_addr_send), 
sizeof(this->m_state->m_addr_send));
 
  
 
struct sockaddr_in m_addr_recv
UDP server address, maybe unused.
void close()
closes the socket
I32 sendProtocol(const U8 *const data, const U32 size)
Protocol specific implementation of send. Called directly with retry from send.
struct sockaddr_in m_addr_send
UDP server address, maybe unused.
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
SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd)
udp specific implementation for opening a socket.
SocketIpStatus setupTimeouts(NATIVE_INT_TYPE socketFd)
setup the socket timeout properties of the opened outgoing socket
SocketIpStatus bind(NATIVE_INT_TYPE fd)
bind the UDP to a port such that it can receive packets at the previously configured port
Helper base-class for setting up Berkley sockets.
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
@ SOCK_SUCCESS
Socket operation successful.
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)
Protocol specific implementation of recv. Called directly with error handling from recv.
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)
SocketIpStatus
Status enumeration for socket return values.
@ SOCK_FAILED_TO_BIND
Failed to bind to socket.
virtual ~UdpSocket()
to cleanup state created at instantiation
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.
@ SOCK_FAILED_TO_GET_SOCKET
Socket open failed.
@ SOCKET_MAX_HOSTNAME_SIZE
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
U16 m_port
IP address port used.
UdpSocket()
Constructor for client socket udp implementation.