aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2023-06-08 16:07:01 +0000
committerOmar Polo <op@omarpolo.com>2023-06-08 16:07:01 +0000
commit4f4937f06a536661ffafa589d1cfb5d91ca27bf3 (patch)
treef7feada38dd6187317cb5cda8160879c579a5dee /config.c
parentfc9cc497e075cf321fe0dcf4c6783e2eeb8b9d43 (diff)
move make_socket to config.c and make it private
Diffstat (limited to 'config.c')
-rw-r--r--config.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/config.c b/config.c
index feb0ca9..71e1824 100644
--- a/config.c
+++ b/config.c
@@ -134,6 +134,61 @@ config_send_file(struct privsep *ps, int fd, int type)
}
static int
+make_socket(int port, int family)
+{
+ int sock, v;
+ struct sockaddr_in addr4;
+ struct sockaddr_in6 addr6;
+ struct sockaddr *addr;
+ socklen_t len;
+
+ switch (family) {
+ case AF_INET:
+ memset(&addr4, 0, sizeof(addr4));
+ addr4.sin_family = family;
+ addr4.sin_port = htons(port);
+ addr4.sin_addr.s_addr = INADDR_ANY;
+ addr = (struct sockaddr*)&addr4;
+ len = sizeof(addr4);
+ break;
+
+ case AF_INET6:
+ memset(&addr6, 0, sizeof(addr6));
+ addr6.sin6_family = AF_INET6;
+ addr6.sin6_port = htons(port);
+ addr6.sin6_addr = in6addr_any;
+ addr = (struct sockaddr*)&addr6;
+ len = sizeof(addr6);
+ break;
+
+ default:
+ /* unreachable */
+ abort();
+ }
+
+ if ((sock = socket(family, SOCK_STREAM, 0)) == -1)
+ fatal("socket");
+
+ v = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) == -1)
+ fatal("setsockopt(SO_REUSEADDR)");
+
+ v = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(v)) == -1)
+ fatal("setsockopt(SO_REUSEPORT)");
+
+ mark_nonblock(sock);
+
+ if (bind(sock, addr, len) == -1)
+ fatal("bind");
+
+ if (listen(sock, 16) == -1)
+ fatal("listen");
+
+ return sock;
+}
+
+static int
config_send_socks(struct conf *conf)
{
struct privsep *ps = conf->ps;