From 750a6d8d361ba61e59b88d698d24189659637da0 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 9 Jun 2021 22:02:05 -0400 Subject: Started work on adding the socket initialization code. --- pullreqd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pullreqd.c b/pullreqd.c index 635a69c..c7764d7 100644 --- a/pullreqd.c +++ b/pullreqd.c @@ -79,6 +79,26 @@ int init_config(char *config_file, config **cfg) { return (*cfg != NULL); } +int init_socket(config *cfg) { + union sock_addr { + struct sockaddr sa; + struct sockaddr_un sa_un; + struct sockaddr_in sa_in; + } sock_addr; + /* Set socket type to unix socket, if socket-type was set to unix, otherwise set it to network socket. */ + const int sock_type = (!strcasecmp(cfg->sock_type, "unix")) ? AF_UNIX : AF_INET; + /* Create a new listen socket. */ + int fd = socket(sock_type, SOCK_SEQPACKET, 0); + + /* TODO: Add rest of init code. */ + + if (sock_type == AF_UNIX) { + + } + + return fd; +} + int main_loop(config *cfg, int listen_socket) { int done = 0; @@ -91,6 +111,7 @@ int main(int argc, char **argv) { config *cfg; char *config_file = "test.conf"; int config_read = 0; + int listen_socket = -1; int exit_status = EXIT_FAILURE; init_daemon(1, "/"); @@ -101,6 +122,12 @@ int main(int argc, char **argv) { /* Did we successfully read the config file? */ if (config_read) { + /* Create the Listen socket. */ + listen_socket = init_socket(cfg); + } + + /* Did we successfully read the config file, and create the listen socket? */ + if (config_read && listen_socket >= 0) { exit_status = main_loop(cfg, listen_socket); } -- cgit v1.2.3-13-gbd6f