2 cdbe1d7d 2022-08-06 thomas * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 cdbe1d7d 2022-08-06 thomas * Permission to use, copy, modify, and distribute this software for any
5 cdbe1d7d 2022-08-06 thomas * purpose with or without fee is hereby granted, provided that the above
6 cdbe1d7d 2022-08-06 thomas * copyright notice and this permission notice appear in all copies.
8 cdbe1d7d 2022-08-06 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 cdbe1d7d 2022-08-06 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 cdbe1d7d 2022-08-06 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 cdbe1d7d 2022-08-06 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 cdbe1d7d 2022-08-06 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 cdbe1d7d 2022-08-06 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 cdbe1d7d 2022-08-06 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 cdbe1d7d 2022-08-06 thomas #include <sys/socket.h>
18 cdbe1d7d 2022-08-06 thomas #include <netinet/in.h>
20 cdbe1d7d 2022-08-06 thomas #include <string.h>
22 cdbe1d7d 2022-08-06 thomas #include "got_sockaddr.h"
25 cdbe1d7d 2022-08-06 thomas * These interfaces wrap BSD-specific internals of internet address
26 cdbe1d7d 2022-08-06 thomas * data structures in a single compilation unit, allowing got-portable
27 cdbe1d7d 2022-08-06 thomas * to override them as needed, without a need for #ifdef macros.
31 cdbe1d7d 2022-08-06 thomas got_sockaddr_inet_init(struct sockaddr_in *in, struct in_addr *ina)
33 cdbe1d7d 2022-08-06 thomas in->sin_len = sizeof(struct sockaddr_in); /* BSD-specific */
34 cdbe1d7d 2022-08-06 thomas in->sin_family = AF_INET;
35 cdbe1d7d 2022-08-06 thomas in->sin_addr.s_addr = ina->s_addr;
39 cdbe1d7d 2022-08-06 thomas got_sockaddr_inet6_init(struct sockaddr_in6 *in6, struct in6_addr *in6a,
40 cdbe1d7d 2022-08-06 thomas uint32_t sin6_scope_id)
42 cdbe1d7d 2022-08-06 thomas in6->sin6_len = sizeof(struct sockaddr_in6); /* BSD-specific */
43 cdbe1d7d 2022-08-06 thomas in6->sin6_family = AF_INET6;
44 cdbe1d7d 2022-08-06 thomas memcpy(&in6->sin6_addr, in6a, sizeof(in6->sin6_addr));
45 cdbe1d7d 2022-08-06 thomas in6->sin6_scope_id = sin6_scope_id;