Blame


1 cdbe1d7d 2022-08-06 thomas /*
2 cdbe1d7d 2022-08-06 thomas * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
3 cdbe1d7d 2022-08-06 thomas *
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.
7 cdbe1d7d 2022-08-06 thomas *
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.
15 cdbe1d7d 2022-08-06 thomas */
16 cdbe1d7d 2022-08-06 thomas
17 cdbe1d7d 2022-08-06 thomas #include <sys/socket.h>
18 cdbe1d7d 2022-08-06 thomas #include <netinet/in.h>
19 cdbe1d7d 2022-08-06 thomas
20 cdbe1d7d 2022-08-06 thomas #include <string.h>
21 cdbe1d7d 2022-08-06 thomas
22 cdbe1d7d 2022-08-06 thomas #include "got_sockaddr.h"
23 cdbe1d7d 2022-08-06 thomas
24 cdbe1d7d 2022-08-06 thomas /*
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.
28 cdbe1d7d 2022-08-06 thomas */
29 cdbe1d7d 2022-08-06 thomas
30 cdbe1d7d 2022-08-06 thomas void
31 cdbe1d7d 2022-08-06 thomas got_sockaddr_inet_init(struct sockaddr_in *in, struct in_addr *ina)
32 cdbe1d7d 2022-08-06 thomas {
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;
36 cdbe1d7d 2022-08-06 thomas }
37 cdbe1d7d 2022-08-06 thomas
38 cdbe1d7d 2022-08-06 thomas void
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)
41 cdbe1d7d 2022-08-06 thomas {
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;
46 cdbe1d7d 2022-08-06 thomas }