commit - 82a8b7ecf5c23c6bb7dc0b1bf17d5608316834f9
commit + cdbe1d7d5e05803418c160eaac35442489398f49
blob - 1f6c99727d2651417486997179bd6c788573e6ca
blob + 283b66d78660ef036a7c9e31cd7923e69844dbe3
--- gotwebd/parse.y
+++ gotwebd/parse.y
#include "proc.h"
#include "gotwebd.h"
-#include "got_compat.h"
+#include "got_sockaddr.h"
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
static struct file {
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(__func__);
sain = (struct sockaddr_in *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sain->sin_len = sizeof(struct sockaddr_in);
-#endif
- sain->sin_family = AF_INET;
- sain->sin_addr.s_addr = ina.s_addr;
+ got_sockaddr_inet_init(sain, &ina);
if (sain->sin_addr.s_addr == INADDR_ANY)
h->prefixlen = 0; /* 0.0.0.0 address */
else
host_v6(const char *s)
{
struct addrinfo hints, *res;
- struct sockaddr_in6 *sa_in6;
+ struct sockaddr_in6 *sa_in6, *ra;
struct address *h = NULL;
memset(&hints, 0, sizeof(hints));
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(__func__);
sa_in6 = (struct sockaddr_in6 *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sa_in6->sin6_len = sizeof(struct sockaddr_in6);
-#endif
- sa_in6->sin6_family = AF_INET6;
- memcpy(&sa_in6->sin6_addr,
- &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
- sizeof(sa_in6->sin6_addr));
- sa_in6->sin6_scope_id =
- ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
+ ra = (struct sockaddr_in6 *)res->ai_addr;
+ got_sockaddr_inet6_init(sa_in6, &ra->sin6_addr,
+ ra->sin6_scope_id);
if (memcmp(&sa_in6->sin6_addr, &in6addr_any,
sizeof(sa_in6->sin6_addr)) == 0)
h->prefixlen = 0; /* any address */
h->prefixlen = -1; /* host address */
if (res->ai_family == AF_INET) {
+ struct sockaddr_in *ra;
sain = (struct sockaddr_in *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sain->sin_len = sizeof(struct sockaddr_in);
-#endif
- sain->sin_addr.s_addr = ((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr;
+ ra = (struct sockaddr_in *)res->ai_addr;
+ got_sockaddr_inet_init(sain, &ra->sin_addr);
} else {
+ struct sockaddr_in6 *ra;
sin6 = (struct sockaddr_in6 *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sin6->sin6_len = sizeof(struct sockaddr_in6);
-#endif
- memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
- res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
+ ra = (struct sockaddr_in6 *)res->ai_addr;
+ got_sockaddr_inet6_init(sin6, &ra->sin6_addr, 0);
}
TAILQ_INSERT_HEAD(al, h, entry);
h->prefixlen = -1; /* host address */
if (af == AF_INET) {
+ struct sockaddr_in *ra;
sain = (struct sockaddr_in *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sain->sin_len = sizeof(struct sockaddr_in);
-#endif
- sain->sin_addr.s_addr = ((struct sockaddr_in *)
- p->ifa_addr)->sin_addr.s_addr;
+ ra = (struct sockaddr_in *)p->ifa_addr;
+ got_sockaddr_inet_init(sain, &ra->sin_addr);
} else {
+ struct sockaddr_in6 *ra;
sin6 = (struct sockaddr_in6 *)&h->ss;
-/* TA: Iffy... */
-#ifndef __linux__
- sin6->sin6_len = sizeof(struct sockaddr_in6);
-#endif
- memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
- p->ifa_addr)->sin6_addr, sizeof(struct in6_addr));
- sin6->sin6_scope_id = ((struct sockaddr_in6 *)
- p->ifa_addr)->sin6_scope_id;
+ ra = (struct sockaddr_in6 *)p->ifa_addr;
+ got_sockaddr_inet6_init(sin6, &ra->sin6_addr,
+ ra->sin6_scope_id);
}
TAILQ_INSERT_HEAD(al, h, entry);
blob - /dev/null
blob + 809c5c9b65985619eabf4ad948d80348f606762c (mode 644)
--- /dev/null
+++ include/got_sockaddr.h
+/*
+ * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+void got_sockaddr_inet_init(struct sockaddr_in *in, struct in_addr *ina);
+void got_sockaddr_inet6_init(struct sockaddr_in6 *in6, struct in6_addr *in6a,
+ uint32_t sin6_scope_id);
blob - /dev/null
blob + 7a76593a59f98468b3891e3823c6d7fd0cfa960d (mode 644)
--- /dev/null
+++ lib/sockaddr.c
+/*
+ * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <string.h>
+
+#include "got_sockaddr.h"
+
+/*
+ * These interfaces wrap BSD-specific internals of internet address
+ * data structures in a single compilation unit, allowing got-portable
+ * to override them as needed, without a need for #ifdef macros.
+ */
+
+void
+got_sockaddr_inet_init(struct sockaddr_in *in, struct in_addr *ina)
+{
+ in->sin_len = sizeof(struct sockaddr_in); /* BSD-specific */
+ in->sin_family = AF_INET;
+ in->sin_addr.s_addr = ina->s_addr;
+}
+
+void
+got_sockaddr_inet6_init(struct sockaddr_in6 *in6, struct in6_addr *in6a,
+ uint32_t sin6_scope_id)
+{
+ in6->sin6_len = sizeof(struct sockaddr_in6); /* BSD-specific */
+ in6->sin6_family = AF_INET6;
+ memcpy(&in6->sin6_addr, in6a, sizeof(in6->sin6_addr));
+ in6->sin6_scope_id = sin6_scope_id;
+}