34 #include <sys/socket.h> 35 #include <arpa/inet.h> 44 #include <sys/ioctl.h> 48 #include <sys/timerfd.h> 53 #include <linux/stat.h> 69 char portnumbuffer[33];
70 struct addrinfo hints, *servinfo, *p;
73 memset(&hints, 0,
sizeof hints);
75 hints.ai_family = AF_INET6;
77 hints.ai_family = AF_INET;
79 hints.ai_socktype = SOCK_STREAM;
80 hints.ai_flags = AI_PASSIVE;
82 snprintf(portnumbuffer, 32,
"%d", servPort);
83 if ((rv = getaddrinfo(
NULL, portnumbuffer, &hints, &servinfo)) != 0) {
84 dlt_vlog(LOG_WARNING,
"getaddrinfo error %d: %s\n", rv, gai_strerror(rv));
88 for(p = servinfo; p !=
NULL; p = p->ai_next) {
89 if ((*sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
90 const int lastErrno = errno;
91 dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, strerror(lastErrno));
96 __FUNCTION__, p->ai_family, p->ai_socktype, p->ai_protocol);
99 if (setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(
int)) == -1)
101 const int lastErrno = errno;
102 dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_open: Setsockopt error %d in dlt_daemon_local_connection_init: %s\n", lastErrno, strerror(lastErrno));
106 if (bind(*sock, p->ai_addr, p->ai_addrlen) == -1) {
107 const int lastErrno = errno;
109 dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_open: bind() error %d: %s\n", lastErrno, strerror(lastErrno));
117 dlt_log(LOG_WARNING,
"failed to bind socket\n");
121 freeaddrinfo(servinfo);
130 if (listen(*sock, 3) < 0)
132 const int lastErrno = errno;
133 dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_open: listen() failed with error %d: %s\n", lastErrno, strerror(lastErrno));
159 if(data1 !=
NULL && size1 > 0)
166 if(data2 !=
NULL && size2 > 0)
180 while (data_sent < message_size)
182 ssize_t ret = send(sock, buffer + data_sent, message_size - data_sent, 0);
185 const int lastErrno=errno;
186 if (lastErrno==EINTR || lastErrno==EAGAIN || lastErrno==EWOULDBLOCK)
189 dlt_vlog(LOG_INFO,
"dlt_daemon_socket_sendreliable: socket send() error %d: %s, trying again.\n", lastErrno, strerror(lastErrno));
193 dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_sendreliable: socket send() error %d: %s\n", lastErrno, strerror(lastErrno));
209 socklen_t m =
sizeof(n);
210 getsockopt(sock,SOL_SOCKET,SO_SNDBUF,(
void *)&n, &m);
#define DLT_DAEMON_ERROR_OK
DltReturnValue dlt_log(int prio, char *s)
int dlt_daemon_socket_open(int *sock, unsigned int servPort)
#define DLT_DAEMON_ERROR_SEND_FAILED
int dlt_daemon_socket_close(int sock)
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
const char dltSerialHeader[DLT_ID_SIZE]
int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader)
int dlt_daemon_socket_sendreliable(int sock, void *buffer, int message_size)
dlt_daemon_socket_sendreliable - sends data to socket with additional checks and resending functional...
int dlt_daemon_socket_get_send_qeue_max_size(int sock)
static char str[DLT_DAEMON_TEXTBUFSIZE]
#define DLT_DAEMON_TEXTBUFSIZE
DltReturnValue dlt_vlog(int prio, const char *format,...)