Specify the family at run-time for TCP/UDP servers

This is still using IPv4 by default for the moment.
This commit is contained in:
Pierre Pronchery 2018-07-10 15:43:10 +02:00
parent d6ce22b989
commit 32cdd1183e
6 changed files with 7 additions and 9 deletions

View File

@ -259,7 +259,7 @@ main(int argc, char **argv)
if(opts.enable_udp_server || if(opts.enable_udp_server ||
strncasecmp(opts.config[CONF_ENABLE_UDP_SERVER], "Y", 1) == 0) strncasecmp(opts.config[CONF_ENABLE_UDP_SERVER], "Y", 1) == 0)
{ {
if(run_udp_server(&opts) < 0) if(run_udp_server(&opts, AF_INET) < 0)
{ {
log_msg(LOG_ERR, "Fatal run_udp_server() error"); log_msg(LOG_ERR, "Fatal run_udp_server() error");
clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE); clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE);
@ -280,7 +280,7 @@ main(int argc, char **argv)
*/ */
if(strncasecmp(opts.config[CONF_ENABLE_TCP_SERVER], "Y", 1) == 0) if(strncasecmp(opts.config[CONF_ENABLE_TCP_SERVER], "Y", 1) == 0)
{ {
if(run_tcp_server(&opts) < 0) if(run_tcp_server(&opts, AF_INET) < 0)
{ {
log_msg(LOG_ERR, "Fatal run_tcp_server() error"); log_msg(LOG_ERR, "Fatal run_tcp_server() error");
clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE); clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE);

View File

@ -211,7 +211,7 @@ pcap_capture(fko_srv_options_t *opts)
/* Attempt to restart tcp server ? */ /* Attempt to restart tcp server ? */
usleep(1000000); usleep(1000000);
run_tcp_server(opts); run_tcp_server(opts, AF_INET);
} }
} }

View File

@ -51,9 +51,8 @@
* the child process or -1 if there is a fork error. * the child process or -1 if there is a fork error.
*/ */
int int
run_tcp_server(fko_srv_options_t *opts) run_tcp_server(fko_srv_options_t *opts, int family)
{ {
const int family = AF_INET;
#if !CODE_COVERAGE #if !CODE_COVERAGE
pid_t pid, ppid; pid_t pid, ppid;
#endif #endif

View File

@ -32,7 +32,7 @@
/* Function prototypes /* Function prototypes
*/ */
int run_tcp_server(fko_srv_options_t *opts); int run_tcp_server(fko_srv_options_t *opts, int family);
#endif /* TCP_SERVER_H */ #endif /* TCP_SERVER_H */

View File

@ -50,9 +50,8 @@
#include <sys/select.h> #include <sys/select.h>
int int
run_udp_server(fko_srv_options_t *opts) run_udp_server(fko_srv_options_t *opts, int family)
{ {
const int family = AF_INET;
int s_sock, sfd_flags, selval, pkt_len; int s_sock, sfd_flags, selval, pkt_len;
int rv=1, chk_rm_all=0; int rv=1, chk_rm_all=0;
fd_set sfd_set; fd_set sfd_set;

View File

@ -32,7 +32,7 @@
/* Function prototypes /* Function prototypes
*/ */
int run_udp_server(fko_srv_options_t *opts); int run_udp_server(fko_srv_options_t *opts, int family);
#endif /* UDP_SERVER_H */ #endif /* UDP_SERVER_H */