| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $ */ | | 1 | /* $NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2017 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Manuel Bouyer | | 8 | * by Manuel Bouyer |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
23 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY | | 23 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY |
24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
26 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
28 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | 28 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | | 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
30 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 30 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | #ifndef lint | | 34 | #ifndef lint |
35 | __RCSID("$NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $"); | | 35 | __RCSID("$NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $"); |
36 | #endif /* not lint */ | | 36 | #endif /* not lint */ |
37 | | | 37 | |
38 | #include <sys/types.h> | | 38 | #include <sys/types.h> |
39 | #include <sys/resource.h> | | 39 | #include <sys/resource.h> |
40 | #include <sys/wait.h> | | 40 | #include <sys/wait.h> |
41 | #include <sys/sockio.h> | | 41 | #include <sys/sockio.h> |
42 | #include <sys/param.h> | | 42 | #include <sys/param.h> |
43 | | | 43 | |
44 | #include <atf-c.h> | | 44 | #include <atf-c.h> |
45 | #include <assert.h> | | 45 | #include <assert.h> |
46 | #include <fcntl.h> | | 46 | #include <fcntl.h> |
47 | #include <stdio.h> | | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | | 48 | #include <stdlib.h> |
| @@ -60,34 +60,36 @@ __RCSID("$NetBSD: h_canutils.c,v 1.3 201 | | | @@ -60,34 +60,36 @@ __RCSID("$NetBSD: h_canutils.c,v 1.3 201 |
60 | | | 60 | |
61 | void | | 61 | void |
62 | cancfg_rump_createif(const char *ifname) | | 62 | cancfg_rump_createif(const char *ifname) |
63 | { | | 63 | { |
64 | int s, rv; | | 64 | int s, rv; |
65 | struct ifreq ifr; | | 65 | struct ifreq ifr; |
66 | | | 66 | |
67 | s = -1; | | 67 | s = -1; |
68 | if ((s = rump_sys_socket(AF_CAN, SOCK_RAW, CAN_RAW)) < 0) { | | 68 | if ((s = rump_sys_socket(AF_CAN, SOCK_RAW, CAN_RAW)) < 0) { |
69 | atf_tc_fail_errno("if config socket"); | | 69 | atf_tc_fail_errno("if config socket"); |
70 | } | | 70 | } |
71 | | | 71 | |
72 | memset(&ifr, 0, sizeof(ifr)); | | 72 | memset(&ifr, 0, sizeof(ifr)); |
73 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); | | 73 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1); |
| | | 74 | ifr.ifr_name[IFNAMSIZ - 1] = '\0'; |
74 | | | 75 | |
75 | if ((rv = rump_sys_ioctl(s, SIOCIFCREATE, &ifr)) < 0) { | | 76 | if ((rv = rump_sys_ioctl(s, SIOCIFCREATE, &ifr)) < 0) { |
76 | atf_tc_fail_errno("if config create"); | | 77 | atf_tc_fail_errno("if config create"); |
77 | } | | 78 | } |
78 | | | 79 | |
79 | memset(&ifr, 0, sizeof(ifr)); | | 80 | memset(&ifr, 0, sizeof(ifr)); |
80 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); | | 81 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1); |
| | | 82 | ifr.ifr_name[IFNAMSIZ - 1] = '\0'; |
81 | | | 83 | |
82 | if ((rv = rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr)) < 0) { | | 84 | if ((rv = rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr)) < 0) { |
83 | atf_tc_fail_errno("if config get flags"); | | 85 | atf_tc_fail_errno("if config get flags"); |
84 | } | | 86 | } |
85 | | | 87 | |
86 | ifr.ifr_flags |= IFF_UP; | | 88 | ifr.ifr_flags |= IFF_UP; |
87 | if ((rv = rump_sys_ioctl(s, SIOCSIFFLAGS, &ifr)) < 0) { | | 89 | if ((rv = rump_sys_ioctl(s, SIOCSIFFLAGS, &ifr)) < 0) { |
88 | atf_tc_fail_errno("if config set flags"); | | 90 | atf_tc_fail_errno("if config set flags"); |
89 | } | | 91 | } |
90 | } | | 92 | } |
91 | | | 93 | |
92 | int | | 94 | int |
93 | can_recvfrom(int s, struct can_frame *cf, int *len, struct sockaddr_can *sa) | | 95 | can_recvfrom(int s, struct can_frame *cf, int *len, struct sockaddr_can *sa) |