Blame


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