+static int
+httpd_accept_connection(httpd_t *httpd, int server_fd, int is_ipv6)
+{
+ struct sockaddr_storage remote_saddr;
+ socklen_t remote_saddrlen;
+ struct sockaddr_storage local_saddr;
+ socklen_t local_saddrlen;
+ unsigned char *local, *remote;
+ int local_len, remote_len;
+ int ret, fd;
+
+ remote_saddrlen = sizeof(remote_saddr);
+ fd = accept(server_fd, (struct sockaddr *)&remote_saddr, &remote_saddrlen);
+ if (fd == -1) {
+ /* FIXME: Error happened */
+ return -1;
+ }
+
+ local_saddrlen = sizeof(local_saddr);
+ ret = getsockname(fd, (struct sockaddr *)&local_saddr, &local_saddrlen);
+ if (ret == -1) {
+ closesocket(fd);
+ return 0;
+ }
+
+ logger_log(httpd->logger, LOGGER_INFO, "Accepted %s client on socket %d",
+ (is_ipv6 ? "IPv6" : "IPv4"), fd);
+ local = netutils_get_address(&local_saddr, &local_len);
+ remote = netutils_get_address(&remote_saddr, &remote_len);
+
+ httpd_add_connection(httpd, fd, local, local_len, remote, remote_len);
+ return 1;
+}
+