|
Lines 1-5
Link Here
|
| 1 |
--- bsd/kernel.cc.orig 2013-08-23 13:40:35.000000000 +0400 |
1 |
--- bsd/kernel.cc.orig 2015-09-23 13:28:14 UTC |
| 2 |
+++ bsd/kernel.cc 2014-10-03 00:35:05.000000000 +0400 |
2 |
+++ bsd/kernel.cc |
| 3 |
@@ -28,6 +28,7 @@ |
3 |
@@ -28,6 +28,7 @@ |
| 4 |
#include <string.h> |
4 |
#include <string.h> |
| 5 |
#include <err.h> |
5 |
#include <err.h> |
|
Lines 8-22
Link Here
|
| 8 |
#include <sysexits.h> |
8 |
#include <sysexits.h> |
| 9 |
#include <sys/types.h> |
9 |
#include <sys/types.h> |
| 10 |
#include <sys/queue.h> |
10 |
#include <sys/queue.h> |
| 11 |
@@ -43,7 +44,6 @@ |
11 |
@@ -44,7 +45,6 @@ |
| 12 |
#if defined(XOSVIEW_FREEBSD) || defined(XOSVIEW_DFBSD) |
|
|
| 13 |
static const char ACPIDEV[] = "/dev/acpi"; |
12 |
static const char ACPIDEV[] = "/dev/acpi"; |
| 14 |
static const char APMDEV[] = "/dev/apm"; |
13 |
static const char APMDEV[] = "/dev/apm"; |
|
|
14 |
static int maxcpus = 1; |
| 15 |
-#include <net/if_var.h> |
15 |
-#include <net/if_var.h> |
| 16 |
#include <sys/ioctl.h> |
16 |
#include <sys/ioctl.h> |
|
|
17 |
#include <sys/resource.h> |
| 17 |
#include <dev/acpica/acpiio.h> |
18 |
#include <dev/acpica/acpiio.h> |
| 18 |
#include <machine/apm_bios.h> |
19 |
@@ -114,56 +114,41 @@ static struct nlist nlst[] = |
| 19 |
@@ -115,56 +115,41 @@ |
|
|
| 20 |
// this later on. This keeps the indices within the nlist constant. |
20 |
// this later on. This keeps the indices within the nlist constant. |
| 21 |
#define DUMMY_SYM "dummy_sym" |
21 |
#define DUMMY_SYM "dummy_sym" |
| 22 |
|
22 |
|
|
Lines 83-89
Link Here
|
| 83 |
#endif |
83 |
#endif |
| 84 |
{ NULL } |
84 |
{ NULL } |
| 85 |
}; |
85 |
}; |
| 86 |
@@ -337,7 +322,21 @@ |
86 |
@@ -338,7 +323,21 @@ BSDGetPageStats(uint64_t *meminfo, uint6 |
| 87 |
#else /* HAVE_UVM */ |
87 |
#else /* HAVE_UVM */ |
| 88 |
struct vmmeter vm; |
88 |
struct vmmeter vm; |
| 89 |
#if defined(XOSVIEW_FREEBSD) |
89 |
#if defined(XOSVIEW_FREEBSD) |
|
Lines 106-112
Link Here
|
| 106 |
#else /* XOSVIEW_DFBSD */ |
106 |
#else /* XOSVIEW_DFBSD */ |
| 107 |
struct vmstats vms; |
107 |
struct vmstats vms; |
| 108 |
size_t size = sizeof(vms); |
108 |
size_t size = sizeof(vms); |
| 109 |
@@ -421,99 +420,37 @@ |
109 |
@@ -468,99 +467,37 @@ BSDGetCPUTimes(uint64_t *timeArray, unsi |
| 110 |
int |
110 |
int |
| 111 |
BSDNetInit() { |
111 |
BSDNetInit() { |
| 112 |
OpenKDIfNeeded(); |
112 |
OpenKDIfNeeded(); |
|
Lines 118-124
Link Here
|
| 118 |
} |
118 |
} |
| 119 |
|
119 |
|
| 120 |
void |
120 |
void |
| 121 |
BSDGetNetInOut(unsigned long long *inbytes, unsigned long long *outbytes, const char *netIface, bool ignored) { |
121 |
BSDGetNetInOut(uint64_t *inbytes, uint64_t *outbytes, const char *netIface, bool ignored) { |
| 122 |
- char ifname[IFNAMSIZ]; |
122 |
- char ifname[IFNAMSIZ]; |
| 123 |
+ struct ifaddrs *ifap, *ifa; |
123 |
+ struct ifaddrs *ifap, *ifa; |
| 124 |
*inbytes = 0; |
124 |
*inbytes = 0; |
|
Lines 129-144
Link Here
|
| 129 |
- struct if_msghdr *ifm; |
129 |
- struct if_msghdr *ifm; |
| 130 |
- struct if_data ifd; |
130 |
- struct if_data ifd; |
| 131 |
- struct sockaddr_dl *sdl; |
131 |
- struct sockaddr_dl *sdl; |
| 132 |
- |
132 |
|
| 133 |
- if ( sysctl(mib_ifl, 6, NULL, &size, NULL, 0) < 0 ) |
133 |
- if ( sysctl(mib_ifl, 6, NULL, &size, NULL, 0) < 0 ) |
| 134 |
- err(EX_OSERR, "BSDGetNetInOut(): sysctl 1 failed"); |
134 |
- err(EX_OSERR, "BSDGetNetInOut(): sysctl 1 failed"); |
| 135 |
- if ( (buf = (char *)malloc(size)) == NULL) |
135 |
- if ( (buf = (char *)malloc(size)) == NULL) |
| 136 |
- err(EX_OSERR, "BSDGetNetInOut(): malloc failed"); |
136 |
- err(EX_OSERR, "BSDGetNetInOut(): malloc failed"); |
| 137 |
- if ( sysctl(mib_ifl, 6, buf, &size, NULL, 0) < 0 ) |
137 |
- if ( sysctl(mib_ifl, 6, buf, &size, NULL, 0) < 0 ) |
| 138 |
- err(EX_OSERR, "BSDGetNetInOut(): sysctl 2 failed"); |
138 |
- err(EX_OSERR, "BSDGetNetInOut(): sysctl 2 failed"); |
|
|
139 |
+ if (getifaddrs(&ifap) != 0) |
| 140 |
+ return; |
| 139 |
|
141 |
|
| 140 |
- for (next = buf; next < buf + size; next += ifm->ifm_msglen) { |
142 |
- for (next = buf; next < buf + size; next += ifm->ifm_msglen) { |
| 141 |
- bool skipif = false; |
143 |
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
|
|
144 |
bool skipif = false; |
| 142 |
- ifm = (struct if_msghdr *)next; |
145 |
- ifm = (struct if_msghdr *)next; |
| 143 |
- if (ifm->ifm_type != RTM_IFINFO || ifm->ifm_addrs & RTAX_IFP == 0) |
146 |
- if (ifm->ifm_type != RTM_IFINFO || ifm->ifm_addrs & RTAX_IFP == 0) |
| 144 |
- continue; |
147 |
- continue; |
|
Lines 168-181
Link Here
|
| 168 |
-#endif |
171 |
-#endif |
| 169 |
- safe_kvm_read(nlst[IFNET_SYM_INDEX].n_value, &ifnethd, sizeof(ifnethd)); |
172 |
- safe_kvm_read(nlst[IFNET_SYM_INDEX].n_value, &ifnethd, sizeof(ifnethd)); |
| 170 |
- ifnetp = TAILQ_FIRST(&ifnethd); |
173 |
- ifnetp = TAILQ_FIRST(&ifnethd); |
| 171 |
+ if (getifaddrs(&ifap) != 0) |
|
|
| 172 |
+ return; |
| 173 |
|
174 |
|
| 174 |
- while (ifnetp) { |
175 |
- while (ifnetp) { |
| 175 |
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
176 |
- bool skipif = false; |
| 176 |
bool skipif = false; |
|
|
| 177 |
- // Now, dereference the pointer to get the ifnet struct. |
177 |
- // Now, dereference the pointer to get the ifnet struct. |
| 178 |
- safe_kvm_read((u_long)ifnetp, &ifnet, sizeof(ifnet)); |
178 |
- safe_kvm_read((unsigned long)ifnetp, &ifnet, sizeof(ifnet)); |
| 179 |
- strlcpy(ifname, ifnet.if_xname, sizeof(ifname)); |
179 |
- strlcpy(ifname, ifnet.if_xname, sizeof(ifname)); |
| 180 |
-#if defined(XOSVIEW_NETBSD) |
180 |
-#if defined(XOSVIEW_NETBSD) |
| 181 |
- ifnetp = TAILQ_NEXT(&ifnet, if_list); |
181 |
- ifnetp = TAILQ_NEXT(&ifnet, if_list); |
|
Lines 183-189
Link Here
|
| 183 |
- ifnetp = TAILQ_NEXT(&ifnet, if_link); |
183 |
- ifnetp = TAILQ_NEXT(&ifnet, if_link); |
| 184 |
-#endif |
184 |
-#endif |
| 185 |
- if (!(ifnet.if_flags & IFF_UP)) |
185 |
- if (!(ifnet.if_flags & IFF_UP)) |
| 186 |
+ |
|
|
| 187 |
+ if (ifa->ifa_addr->sa_family != AF_LINK) |
186 |
+ if (ifa->ifa_addr->sa_family != AF_LINK) |
| 188 |
continue; |
187 |
continue; |
| 189 |
+ |
188 |
+ |
|
Lines 201-207
Link Here
|
| 201 |
- struct ifdata_pcpu ifdata; |
200 |
- struct ifdata_pcpu ifdata; |
| 202 |
- int ncpus = BSDCountCpus(); |
201 |
- int ncpus = BSDCountCpus(); |
| 203 |
- for (int cpu = 0; cpu < ncpus; cpu++) { |
202 |
- for (int cpu = 0; cpu < ncpus; cpu++) { |
| 204 |
- safe_kvm_read((u_long)ifdatap + cpu * sizeof(ifdata), |
203 |
- safe_kvm_read((unsigned long)ifdatap + cpu * sizeof(ifdata), |
| 205 |
- &ifdata, sizeof(ifdata)); |
204 |
- &ifdata, sizeof(ifdata)); |
| 206 |
- *inbytes += ifdata.ifd_ibytes; |
205 |
- *inbytes += ifdata.ifd_ibytes; |
| 207 |
- *outbytes += ifdata.ifd_obytes; |
206 |
- *outbytes += ifdata.ifd_obytes; |