diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-12-18 09:46:02 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-01-10 07:16:12 +0100 |
commit | 8029c1387c240fcd085be13f38d9adadc97c03bf (patch) | |
tree | 68a96ca17aff21607433cef7f89a457cc73db5ee /src/daemon/dlt_daemon_socket.c | |
parent | b7a37dc39a2a975e594bdb554e752c8ed563673e (diff) | |
download | DLT-daemon-8029c1387c240fcd085be13f38d9adadc97c03bf.tar.gz |
Moved daemon client functions to new source file.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/daemon/dlt_daemon_socket.c')
-rw-r--r-- | src/daemon/dlt_daemon_socket.c | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c index 6bb9236..033ea15 100644 --- a/src/daemon/dlt_daemon_socket.c +++ b/src/daemon/dlt_daemon_socket.c @@ -48,21 +48,81 @@ ** aw Alexander Wenzel BMW ** *******************************************************************************/ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <netdb.h> +#include <ctype.h> +#include <stdio.h> /* for printf() and fprintf() */ +#include <sys/socket.h> /* for socket(), connect(), (), and recv() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ +#include <stdlib.h> /* for atoi() and exit() */ +#include <string.h> /* for memset() */ +#include <unistd.h> /* for close() */ +#include <fcntl.h> +#include <signal.h> #include <syslog.h> #include <errno.h> -#include <unistd.h> -#include <fcntl.h> +#include <pthread.h> -#include <sys/types.h> /* send() */ -#include <sys/socket.h> /* send() */ +#include <sys/timerfd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <linux/stat.h> #include "dlt_types.h" +#include "dlt-daemon.h" +#include "dlt-daemon_cfg.h" +#include "dlt_daemon_common_cfg.h" #include "dlt_daemon_socket.h" +/** Global text output buffer, mainly used for creation of error/warning strings */ +static char str[DLT_DAEMON_TEXTBUFSIZE]; + +int dlt_daemon_socket_open(int *sock) +{ + int yes = 1; + + struct sockaddr_in servAddr; + unsigned int servPort = DLT_DAEMON_TCP_PORT; + + if ((*sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + dlt_log(LOG_ERR, "dlt_daemon_socket_open: socket() failed!\n"); + return -1; + } /* if */ + + if ( -1 == setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))) + { + sprintf(str,"dlt_daemon_socket_open: Setsockopt error in dlt_daemon_local_connection_init: %s\n",strerror(errno)); + dlt_log(LOG_ERR, str); + return -1; + } + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = INADDR_ANY; + servAddr.sin_port = htons(servPort); + + if (bind(*sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + dlt_log(LOG_ERR, "dlt_daemon_socket_open: bind() failed!\n"); + return -1; + } /* if */ + + if (listen(*sock, 3) < 0) + { + dlt_log(LOG_ERR, "dlt_daemon_socket_open: listen() failed!\n"); + return -1; + } /* if */ + + return 0; /* OK */ +} + +int dlt_daemon_socket_close(int sock) +{ + close(sock); + + return 0; +} + int dlt_daemon_socket_send(int sock,void* data1,int size1,void* data2,int size2,char serialheader) { /* Optional: Send serial header, if requested */ |