Commit 09f9be17 authored by julien.delange's avatar julien.delange

* include/drivers/po_hi_driver_sockets.h

   include/drivers/po_hi_driver_sockets_common.h
   src/drivers/po_hi_driver_sockets_common.c
   src/drivers/po_hi_driver_sockets_asn1.c
   src/drivers/po_hi_driver_sockets.c
   src/drivers/configuration/Makefile.am
   - Delete old sockets driver
   - Delete old ASN.1 driver
   - Keep only ne2000 driver for RTEMS
     and generic driver configured using ASN.1 types




git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@2047 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent daeb8d8a
......@@ -13,25 +13,50 @@
#if (defined (__PO_HI_NEED_DRIVER_SOCKETS) \
|| defined (__PO_HI_NEED_DRIVER_SOCKETSNEW) \
|| defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))
|| defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))
#include <po_hi_transport.h>
#include <drivers/po_hi_driver_sockets_common.h>
/* Files from PolyORB-HI-C */
typedef __po_hi_uint16_t __po_hi_inetport_t;
typedef char* __po_hi_inetaddr_t;
#define __PO_HI_NOPORT 1
#define __PO_HI_NOADDR ""
typedef struct
{
int socket;
} __po_hi_inetnode_t;
extern __po_hi_node_t __po_hi_mynode;
void __po_hi_driver_sockets_receiver (void);
#ifdef __PO_HI_NEED_DRIVER_SOCKETS
int __po_hi_driver_sockets_send (__po_hi_entity_t from, __po_hi_entity_t to, __po_hi_msg_t* msg);
/* We only need to set the timeout for the NE2000 driver socket.
* So, this function is used only for this driver.
*/
#ifdef __PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS
#include <sys/time.h>
#define __PO_HI_SET_SOCKET_TIMEOUT(mysocket,nsec) { struct timeval timeout; \
timeout.tv_sec = nsec; \
timeout.tv_usec = 0; \
setsockopt (mysocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof (timeout)); }
#else
#define __PO_HI_SET_SOCKET_TIMEOUT(mysocket,nsec)
#endif
#ifdef __PO_HI_NEED_DRIVER_SOCKETSNEW
#define __PO_HI_TRANSPORT_SOCKET_NEED_RECEIVER_TASK() \
(node_port[mynode] != __PO_HI_NOPORT)
/*
* Maccro that declare if we need to activate another thread
* that receives data from a socket (receiver task)
*/
void __po_hi_driver_sockets_receiver (void);
int __po_hi_driver_sockets_send (__po_hi_task_id task_id,
__po_hi_port_t port);
#endif
/*
* Send data through the sending socket
*/
......
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2010, European Space Agency
*/
#ifndef __PO_HI_DRIVER_SOCKETS_COMMON_H__
#define __PO_HI_DRIVER_SOCKETS_COMMON_H__
#include <deployment.h>
typedef __po_hi_uint16_t __po_hi_inetport_t;
typedef char* __po_hi_inetaddr_t;
#if (defined (__PO_HI_NEED_DRIVER_SOCKETS) \
|| defined (__PO_HI_NEED_DRIVER_SOCKETS_ASN1) \
|| defined (__PO_HI_NEED_DRIVER_SOCKETSNEW) \
|| defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))
#define __PO_HI_NOPORT 1
#define __PO_HI_NOADDR ""
typedef struct
{
int socket;
} __po_hi_inetnode_t;
extern __po_hi_inetport_t __po_hi_node_port[__PO_HI_NB_NODES];
extern __po_hi_inetaddr_t __po_hi_node_addr[__PO_HI_NB_NODES];
extern __po_hi_node_t __po_hi_mynode;
/* We only need to set the timeout for the NE2000 driver socket.
* So, this function is used only for this driver.
*/
#ifdef __PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS
#include <sys/time.h>
#define __PO_HI_SET_SOCKET_TIMEOUT(mysocket,nsec) { struct timeval timeout; \
timeout.tv_sec = nsec; \
timeout.tv_usec = 0; \
setsockopt (mysocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof (timeout)); }
#else
#define __PO_HI_SET_SOCKET_TIMEOUT(mysocket,nsec)
#endif
#define __PO_HI_TRANSPORT_SOCKET_NEED_RECEIVER_TASK() \
(node_port[mynode] != __PO_HI_NOPORT)
/*
* Maccro that declare if we need to activate another thread
* that receives data from a socket (receiver task)
*/
void __po_hi_driver_sockets_common_generic_init (__po_hi_device_id id, void* (*poller) (void));
#endif /* __PO_HI_DRIVER_SOCKETS_COMMON_H__ */
#endif /* __PO_HI_NEED_DRIVER_SOCKETS || __PO_HI_NEED_DRIVER_SOCKETS_ASN1 */
......@@ -11,7 +11,9 @@ $(srcdir)/1553.c:
asn1.exe -c -typePrefix __po_hi_c_ 1553.asn
sed -e 's/Mil\_1553\_Conf\_T/mil\_1553\_conf\_t/g' 1553.h > 1553new.h
mv 1553new.h 1553.h
sed -e 's/Mil\_1553\_Conf\_T/mil\_1553\_conf\_t/g' 1553.c > 1553new.c
echo "#if (defined (__PO_HI_NEED_DRIVER_1553_RASTA))\n" > 1553new.c
sed -e 's/Mil\_1553\_Conf\_T/mil\_1553\_conf\_t/g' 1553.c >> 1553new.c
echo "\n#endif" >> 1553new.c
mv 1553new.c 1553.c
mv 1553.h ../../../include/drivers/configuration/
mv asn1crt.h ../../../include/drivers/configuration/
......@@ -20,7 +22,9 @@ $(srcdir)/spacewire.c:
asn1.exe -c -typePrefix __po_hi_c_ spacewire.asn
sed -e 's/Spacewire\_Conf\_T/spacewire\_conf\_t/g' spacewire.h > spacewirenew.h
mv spacewirenew.h spacewire.h
sed -e 's/Spacewire\_Conf\_T/spacewire\_conf\_t/g' spacewire.c > spacewirenew.c
echo "#if (defined (__PO_HI_NEED_DRIVER_SPACEWIRE_RASTA))\n" > spacewirenew.c
sed -e 's/Spacewire\_Conf\_T/spacewire\_conf\_t/g' spacewire.c >> spacewirenew.c
echo "\n#endif" >> spacewirenew.c
mv spacewirenew.c spacewire.c
mv spacewire.h ../../../include/drivers/configuration/
mv asn1crt.h ../../../include/drivers/configuration/
......@@ -30,7 +34,9 @@ $(srcdir)/ip.c:
mv asn1crt.h ../../../include/drivers/configuration/
sed -e 's/IP\_Conf\_T/ip\_conf\_t/g' ip.h > ipnew.h
mv ipnew.h ip.h
sed -e 's/IP\_Conf\_T/ip\_conf\_t/g' ip.c > ipnew.c
echo "#if (defined (__PO_HI_NEED_DRIVER_SOCKETS) || defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))\n" > ipnew.c
sed -e 's/IP\_Conf\_T/ip\_conf\_t/g' ip.c >> ipnew.c
echo "\n#endif" >> ipnew.c
mv ipnew.c ip.c
mv ip.h ../../../include/drivers/configuration/
......@@ -38,7 +44,9 @@ $(srcdir)/serial.c:
asn1.exe -c -typePrefix __po_hi_c_ serial.asn
sed -e 's/Serial\_Conf\_T/serial\_conf\_t/g' serial.h > serialnew.h
mv serialnew.h serial.h
sed -e 's/Serial\_Conf\_T/serial\_conf\_t/g' serial.c > serialnew.c
echo "#if (defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX) || defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX_RECEIVER) || defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX_SENDER) || defined (__PO_HI_NEED_DRIVER_SERIAL_RASTA) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON_SENDER) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON_RECEIVER))\n" > serialnew.c
sed -e 's/Serial\_Conf\_T/serial\_conf\_t/g' serial.c >> serialnew.c
echo "\n#endif" >> serialnew.c
mv serialnew.c serial.c
mv serial.h ../../../include/drivers/configuration/
mv asn1crt.h ../../../include/drivers/configuration/
......
This diff is collapsed.
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2010, European Space Agency
*/
#include <deployment.h>
#include <marshallers.h>
#ifdef __PO_HI_NEED_DRIVER_SOCKETS_ASN1
#include <po_hi_common.h>
#include <po_hi_config.h>
#include <po_hi_task.h>
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
#include <po_hi_debug.h>
#include <po_hi_types.h>
#include <po_hi_messages.h>
#include <po_hi_returns.h>
#include <po_hi_main.h>
#include <po_hi_marshallers.h>
#include <po_hi_task.h>
#include <drivers/po_hi_driver_sockets_common.h>
#include <drivers/po_hi_driver_sockets_asn1.h>
#include <asn1_deployment.h>
/* PolyORB-HI-C headers */
#include <activity.h>
/* Generated code headers */
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
/* POSIX headers */
#include <asn1crt.h>
/* ASN1SCC headers */
/*
* This file contains an implementation of a socket driver
* that send and receive data through POSIX sockets but encode
* data with the ASN1 protocol.
*/
/* The following declarations avoid conflicts
* with current generated code.
*/
#ifndef __PO_HI_NB_NODES
#define __PO_HI_NB_NODES 1
#endif
__po_hi_inetnode_t nodes[__PO_HI_NB_DEVICES];
__po_hi_inetnode_t rnodes[__PO_HI_NB_DEVICES];
extern __po_hi_device_id socket_device_id;
void __po_hi_driver_sockets_asn1_init (__po_hi_device_id id)
{
__po_hi_driver_sockets_common_generic_init (id, __po_hi_sockets_asn1_poller);
}
int __po_hi_driver_sockets_asn1_send (__po_hi_task_id task_id,
__po_hi_port_t port)
{
int len;
int size_to_write;
int optval = 0;
socklen_t optlen = 0;
__po_hi_device_id associated_device;
__po_hi_local_port_t local_port;
__po_hi_request_t* request;
__po_hi_asn1_pkt_t asn1_pkt;
__po_hi_port_t destination_port;
BitStream asn1_bitstream;
int asn1_error_code;
__po_hi_byte_t asn1_buffer[Pkt_REQUIRED_BYTES_FOR_ENCODING];
local_port = __po_hi_get_local_port_from_global_port (port);
request = __po_hi_gqueue_get_most_recent_value (task_id, local_port);
destination_port = __po_hi_gqueue_get_destination (task_id, local_port, 0);
associated_device = __po_hi_get_device_from_port (destination_port);
if (nodes[associated_device].socket == -1 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG (" [DRIVER SOCKETS] Invalid socket for port-id %d, device-id %d\n", destination_port, associated_device);
#endif
return __PO_HI_ERROR_TRANSPORT_SEND;
}
/*
* After sending the entity identifier, we send the message which
* contains the request.
*/
size_to_write = __PO_HI_MESSAGES_MAX_SIZE;
if (getsockopt (nodes[associated_device].socket, SOL_SOCKET, SO_ERROR, &optval, &optlen) == -1)
{
__DEBUGMSG (" [error getsockopt() in file %s, line%d ]\n", __FILE__, __LINE__);
close (nodes[associated_device].socket);
nodes[associated_device].socket = -1;
return __PO_HI_ERROR_TRANSPORT_SEND;
}
if (optval != 0)
{
__DEBUGMSG (" [error getsockopt() return code in file %s, line%d ]\n", __FILE__, __LINE__);
close (nodes[associated_device].socket);
nodes[associated_device].socket = -1;
return __PO_HI_ERROR_TRANSPORT_SEND;
}
/* Ignore SIGPIPE to be able to recover from errors instead of crashing the node */
if (signal (SIGPIPE, SIG_IGN) == SIG_ERR)
{
__DEBUGMSG (" [error signal() return code in file %s, line%d ]\n", __FILE__, __LINE__);
close (nodes[associated_device].socket);
nodes[associated_device].socket = -1;
return __PO_HI_ERROR_TRANSPORT_SEND;
}
request->port = destination_port;
__po_hi_marshall_asn1_request (request, &asn1_pkt);
asn1_pkt.sender_port = 0;
asn1_pkt.sender_thread = 0;
asn1_pkt.receiver_thread = 0;
asn1_pkt.receiver_port = 0;
__DEBUGMSG("[SOCKETS ASN1] Marshall ASN1 Packet, kind=%d\n", asn1_pkt.msg.kind);
BitStream_Init (&asn1_bitstream, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if ( ! Pkt_Encode (&asn1_pkt, &asn1_bitstream, &asn1_error_code, TRUE))
{
__DEBUGMSG ("[SOCKETS ASN1] Unable to encode data, error_code=%d\n", asn1_error_code);
return __PO_HI_ERROR_TRANSPORT_SEND;
}
// size_to_write = BitStream_GetLength (&asn1_bitstream);
size_to_write = Pkt_REQUIRED_BYTES_FOR_ENCODING;
len = write (nodes[associated_device].socket, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if (len != size_to_write)
{
__DEBUGMSG (" [error write() length in file %s, line%d ]\n", __FILE__, __LINE__);
close (nodes[associated_device].socket);
nodes[associated_device].socket = -1;
return __PO_HI_ERROR_TRANSPORT_SEND;
}
__DEBUGMSG (" [SUCCESS len=%d]\n", len);
__DEBUGMSG ("[DRIVER_SOCKETS] Sent message content: |0x");
{
int n;
for (n=0 ; n < len ; n++)
{
__DEBUGMSG ("%x", asn1_buffer[n]);
}
}
__DEBUGMSG ("|\n");
return __PO_HI_SUCCESS;
}
void* __po_hi_sockets_asn1_poller (void)
{
socklen_t socklen = sizeof (struct sockaddr);
/* See ACCEPT (2) for details on initial value of socklen */
__po_hi_uint32_t len;
int sock;
int max_socket;
fd_set selector;
struct sockaddr_in sa;
__po_hi_node_t dev;
__po_hi_node_t dev_init;
__po_hi_request_t received_request;
__po_hi_byte_t asn1_buffer[Pkt_REQUIRED_BYTES_FOR_ENCODING];
__po_hi_asn1_pkt_t asn1_pkt;
int asn1_error_code;
BitStream asn1_bitstream;
max_socket = 0; /* Used to compute the max socket number, useful for listen() call */
/*
* We initialize each node socket with -1 value. This value means
* that the socket is not active.
*/
for (dev = 0 ; dev < __PO_HI_NB_DEVICES ; dev++)
{
rnodes[dev].socket = -1;
}
/*
* Create a socket for each node that will communicate with us.
*/
for (dev = 0; dev < __PO_HI_NB_DEVICES ; dev++)
{
if (dev != socket_device_id)
{
sock = accept (nodes[socket_device_id].socket, (struct sockaddr*) &sa, &socklen);
if (read (sock, &dev_init, sizeof (__po_hi_device_id)) != sizeof (__po_hi_device_id))
{
__DEBUGMSG ("[DRIVER SOCKETS] Cannot read device-id for device %d, socket=%d\n", dev, sock);
continue;
}
__DEBUGMSG ("[DRIVER SOCKETS] read device-id %d from socket=%d\n", dev_init, sock);
rnodes[dev].socket = sock;
if (sock > max_socket )
{
max_socket = sock;
}
}
}
__DEBUGMSG ("[DRIVER SOCKETS] Poller initialization finished\n");
__po_hi_wait_initialization ();
/*
* Then, listen and receive data on the socket, identify the node
* which send the data and put it in its message queue
*/
while (1)
{
FD_ZERO( &selector );
for (dev = 0; dev < __PO_HI_NB_DEVICES ; dev++)
{
if ( (dev != socket_device_id ) && ( rnodes[dev].socket != -1 ) )
{
FD_SET( rnodes[dev].socket , &selector );
}
}
if (select (max_socket + 1, &selector, NULL, NULL, NULL) == -1 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("[DRIVER SOCKETS] Error on select for node %d\n", __po_hi_mynode);
#endif
}
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("[DRIVER SOCKETS] Receive message\n");
#endif
for (dev = 0; dev < __PO_HI_NB_DEVICES ; dev++)
{
if ( (rnodes[dev].socket != -1 ) && FD_ISSET(rnodes[dev].socket, &selector))
{
__DEBUGMSG ("[DRIVER SOCKETS] Receive message from dev %d\n", dev);
memset (asn1_buffer, '\0', Pkt_REQUIRED_BYTES_FOR_ENCODING);
len = recv (rnodes[dev].socket, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING, MSG_WAITALL);
__DEBUGMSG ("[DRIVER SOCKETS] Message received len=%d\n",len);
__DEBUGMSG ("[DRIVER_SOCKETS] Received message content: |0x");
{
int n;
for (n=0 ; n < len ; n++)
{
__DEBUGMSG ("%x", asn1_buffer[n]);
}
}
__DEBUGMSG ("|\n");
BitStream_AttachBuffer (&asn1_bitstream, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if (len == 0)
{
rnodes[dev].socket = -1;
continue;
}
if (! Pkt_Decode (&asn1_pkt, &asn1_bitstream, &asn1_error_code))
{
__DEBUGMSG ("[SOCKETS ASN1] Unable to decode, error_code=%d\n", asn1_error_code);
continue;
}
__DEBUGMSG("[SOCKETS ASN1] Unmarshall ASN1 Packet of kind=%d\n", asn1_pkt.msg.kind);
__po_hi_unmarshall_asn1_request (&received_request, &asn1_pkt);
__DEBUGMSG ("[SOCKETS ASN1] deliver for port : %d\n", (int)received_request.port);
__po_hi_main_deliver (&received_request);
}
}
}
return NULL;
}
#endif /* __PO_HI_NEED_DRIVER_SOCKETS_ASN1 */
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2010, European Space Agency
*/
#include <deployment.h>
#if (defined (__PO_HI_NEED_DRIVER_SOCKETS) || \
defined (__PO_HI_NEED_DRIVER_SOCKETS_ASN1) || \
defined (__PO_HI_NEED_DRIVER_SOCKETSNEW) || \
defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))
#include <activity.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <drivers/configuration/ip.h>
#include <po_hi_debug.h>
#include <po_hi_transport.h>
#include <po_hi_main.h>
#include <po_hi_time.h>
#include <po_hi_task.h>
#include <drivers/po_hi_driver_sockets_asn1.h>
#include <drivers/po_hi_driver_sockets_common.h>
#include <drivers/po_hi_driver_sockets.h>
#ifdef __PO_HI_NEED_DRIVER_SOCKETS
__po_hi_inetnode_t nodes[__PO_HI_NB_NODES];
__po_hi_inetnode_t rnodes[__PO_HI_NB_NODES];
#else
__po_hi_inetnode_t nodes[__PO_HI_NB_DEVICES];
__po_hi_inetnode_t rnodes[__PO_HI_NB_DEVICES];
#endif
__po_hi_device_id socket_device_id;
#if (defined (__PO_HI_NEED_DRIVER_SOCKETS_ASN1) || \
defined (__PO_HI_NEED_DRIVER_SOCKETSNEW) || \
defined (__PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS))
void __po_hi_driver_sockets_common_generic_init (__po_hi_device_id id, void* (*poller)(void))
{
int i;
int ret;
int reuse;
char *tmp;
__po_hi_uint16_t dev;
__po_hi_time_t mytime;
struct sockaddr_in sa;
struct hostent* hostinfo;
__po_hi_c_ip_conf_t* ipconf;
char ip_addr[16];
int ip_port;
int node;
socket_device_id = id;
for (node = 0 ; node < __PO_HI_NB_DEVICES ; node++)
{
nodes[node].socket = -1;
}
ipconf = (__po_hi_c_ip_conf_t*)__po_hi_get_device_configuration (id);
ip_port = (int)ipconf->port;
__DEBUGMSG ("My configuration, addr=%s, port=%lld\n", ipconf->address, ipconf->port );
/*
* If the current node port has a port number, then it has to
* listen to other nodes. So, we create a socket, bind it and
* listen to other nodes.
*/
if (ip_port != 0)
{
nodes[id].socket = socket (AF_INET, SOCK_STREAM, 0);
if (nodes[id].socket == -1 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("Cannot create socket for device %d\n", id);
#endif
return;
}
reuse = 1;
setsockopt (nodes[id].socket, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
sa.sin_addr.s_addr = htonl (INADDR_ANY); /* We listen on all adresses */
sa.sin_family = AF_INET;
sa.sin_port = htons (ip_port); /* Port provided by the generated code */
if( bind( nodes[id].socket , ( struct sockaddr * ) &sa , sizeof( struct sockaddr_in ) ) < 0 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("Unable to bind socket and port on socket %d\n", nodes[id].socket);
#endif
}
if( listen( nodes[id].socket , __PO_HI_NB_ENTITIES ) < 0 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("Cannot listen on socket %d\n", nodes[id].socket);
#endif
}
/*
* Create the thread which receive all data from other
* nodes. This thread will execute the function
* __po_hi_receiver_task
*/
__po_hi_initialize_add_task ();
__po_hi_create_generic_task
(-1, 0,__PO_HI_MAX_PRIORITY, 0, poller);
}
/*
* For each node in the sytem that may communicate with the current
* node we create a socket. This socket will be used to send data.
*/
for (dev = 0 ; dev < __PO_HI_NB_DEVICES ; dev++ )
{
if (dev == id)
{
continue;
}
__DEBUGMSG ("[DRIVER SOCKETS] Will initialize connection with device %d\n", dev);
memset (ip_addr, '\0', 16);
ip_port = 0;
ipconf = (__po_hi_c_ip_conf_t*) __po_hi_get_device_configuration (dev);
ip_port = (int)ipconf->port;
__DEBUGMSG ("[DRIVER SOCKETS] Configuration for device %d, addr=%s, port=%d\n", dev, ipconf->address, ip_port);
if (ip_port == 0)
{
__DEBUGMSG ("[DRIVER SOCKETS] Invalid remote port\n");
continue;
}
while (1)
{
nodes[dev].socket = socket (AF_INET, SOCK_STREAM, 0);
if (nodes[dev].socket == -1 )
{
__DEBUGMSG ("[DRIVER SOCKETS] Socket for dev %d is not created\n", dev);
return;
}
__DEBUGMSG ("[DRIVER SOCKETS] Socket for dev %d created, value=%d\n", dev, nodes[dev].socket);
hostinfo = gethostbyname ((char*)ipconf->address);
if (hostinfo == NULL )
{
__DEBUGMSG ("[DRIVER SOCKETS] Error while getting host informations for device %d\n", dev);
}
sa.sin_port = htons (ip_port);
sa.sin_family = AF_INET;
/* The following lines are used to copy the
* hostinfo->h_length to the sa.sin_addr member. Most
* of program use the memcpy to do that, but the
* RT-POSIX profile we use forbid the use of this
* function. We use a loop instead to perform the
* copy. So, these lines replace the code :
*
* memcpy( (char*) &( sa.sin_addr ) , (char*)hostinfo->h_addr , hostinfo->h_length );
*/
tmp = (char*) &(sa.sin_addr);
for (i=0 ; i<hostinfo->h_length ; i++)
{
tmp[i] = hostinfo->h_addr[i];
}