Use a constant for AF_INET

This should eventually help with portability to IPv6.
This commit is contained in:
2018-07-09 18:34:57 +02:00
parent d1625c71ad
commit 3b8ff51691
2 changed files with 8 additions and 6 deletions

View File

@@ -53,6 +53,7 @@
int
run_tcp_server(fko_srv_options_t *opts)
{
const int family = AF_INET;
#if !CODE_COVERAGE
pid_t pid, ppid;
#endif
@@ -94,7 +95,7 @@ run_tcp_server(fko_srv_options_t *opts)
/* Now, let's make a TCP server
*/
if ((s_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
if ((s_sock = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
log_msg(LOG_ERR, "run_tcp_server: socket() failed: %s",
strerror(errno));
@@ -136,7 +137,7 @@ run_tcp_server(fko_srv_options_t *opts)
/* Construct local address structure */
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET; /* Internet address family */
saddr.sin_family = family; /* Internet address family */
saddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
saddr.sin_port = htons(opts->tcpserv_port); /* Local port */
@@ -226,7 +227,7 @@ run_tcp_server(fko_srv_options_t *opts)
if(opts->verbose)
{
memset(sipbuf, 0x0, sizeof(sipbuf));
inet_ntop(AF_INET, &(caddr.sin_addr.s_addr), sipbuf, sizeof(sipbuf));
inet_ntop(family, &(caddr.sin_addr.s_addr), sipbuf, sizeof(sipbuf));
log_msg(LOG_INFO, "tcp_server: Got TCP connection from %s.", sipbuf);
}

View File

@@ -52,6 +52,7 @@
int
run_udp_server(fko_srv_options_t *opts)
{
const int family = AF_INET;
int s_sock, sfd_flags, selval, pkt_len;
int rv=1, chk_rm_all=0;
fd_set sfd_set;
@@ -66,7 +67,7 @@ run_udp_server(fko_srv_options_t *opts)
/* Now, let's make a UDP server
*/
if ((s_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
if ((s_sock = socket(family, SOCK_DGRAM, 0)) < 0)
{
log_msg(LOG_ERR, "run_udp_server: socket() failed: %s",
strerror(errno));
@@ -96,7 +97,7 @@ run_udp_server(fko_srv_options_t *opts)
/* Construct local address structure */
memset(&saddr, 0x0, sizeof(saddr));
saddr.sin_family = AF_INET; /* Internet address family */
saddr.sin_family = family; /* Internet address family */
saddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
saddr.sin_port = htons(opts->udpserv_port); /* Local port */
@@ -194,7 +195,7 @@ run_udp_server(fko_srv_options_t *opts)
if(opts->verbose)
{
memset(sipbuf, 0x0, sizeof(sipbuf));
inet_ntop(AF_INET, &(caddr.sin_addr.s_addr), sipbuf, sizeof(sipbuf));
inet_ntop(family, &(caddr.sin_addr.s_addr), sipbuf, sizeof(sipbuf));
log_msg(LOG_INFO, "udp_server: Got UDP datagram (%d bytes) from: %s",
pkt_len, sipbuf);
}