hyperic-sigar 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/EXCEPTIONS +104 -0
- data/README +2 -0
- data/Rakefile +87 -0
- data/bindings/SigarWrapper.pm +2934 -0
- data/bindings/ruby/examples/cpu_info.rb +16 -0
- data/bindings/ruby/examples/df.rb +32 -0
- data/bindings/ruby/examples/free.rb +19 -0
- data/bindings/ruby/examples/ifconfig.rb +67 -0
- data/bindings/ruby/examples/netstat.rb +54 -0
- data/bindings/ruby/examples/pargs.rb +18 -0
- data/bindings/ruby/examples/penv.rb +14 -0
- data/bindings/ruby/examples/route.rb +31 -0
- data/bindings/ruby/examples/who.rb +13 -0
- data/bindings/ruby/extconf.rb +110 -0
- data/bindings/ruby/rbsigar.c +628 -0
- data/include/sigar.h +901 -0
- data/include/sigar_fileinfo.h +141 -0
- data/include/sigar_format.h +65 -0
- data/include/sigar_getline.h +18 -0
- data/include/sigar_log.h +82 -0
- data/include/sigar_private.h +365 -0
- data/include/sigar_ptql.h +55 -0
- data/include/sigar_util.h +192 -0
- data/src/os/aix/aix_sigar.c +1927 -0
- data/src/os/aix/sigar_os.h +71 -0
- data/src/os/darwin/darwin_sigar.c +3450 -0
- data/src/os/darwin/sigar_os.h +82 -0
- data/src/os/hpux/dlpi.c +284 -0
- data/src/os/hpux/hpux_sigar.c +1205 -0
- data/src/os/hpux/sigar_os.h +51 -0
- data/src/os/linux/linux_sigar.c +2595 -0
- data/src/os/linux/sigar_os.h +84 -0
- data/src/os/netware/netware_sigar.c +719 -0
- data/src/os/netware/sigar_os.h +26 -0
- data/src/os/osf1/osf1_sigar.c +593 -0
- data/src/os/osf1/sigar_os.h +42 -0
- data/src/os/solaris/get_mib2.c +321 -0
- data/src/os/solaris/get_mib2.h +127 -0
- data/src/os/solaris/hmekstat.h +77 -0
- data/src/os/solaris/kstats.c +182 -0
- data/src/os/solaris/procfs.c +99 -0
- data/src/os/solaris/sigar_os.h +225 -0
- data/src/os/solaris/solaris_sigar.c +2561 -0
- data/src/os/stub/sigar_os.h +8 -0
- data/src/os/stub/stub_sigar.c +303 -0
- data/src/os/win32/peb.c +213 -0
- data/src/os/win32/sigar_os.h +623 -0
- data/src/os/win32/sigar_pdh.h +49 -0
- data/src/os/win32/win32_sigar.c +3718 -0
- data/src/sigar.c +2292 -0
- data/src/sigar_cache.c +181 -0
- data/src/sigar_fileinfo.c +792 -0
- data/src/sigar_format.c +649 -0
- data/src/sigar_getline.c +1849 -0
- data/src/sigar_ptql.c +1966 -0
- data/src/sigar_signal.c +218 -0
- data/src/sigar_util.c +1061 -0
- data/version.properties +11 -0
- metadata +112 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
3
|
+
* This file is part of SIGAR.
|
4
|
+
*
|
5
|
+
* SIGAR is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms version 2 of the GNU General Public License as
|
7
|
+
* published by the Free Software Foundation. This program is distributed
|
8
|
+
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
9
|
+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
10
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
11
|
+
* details.
|
12
|
+
*
|
13
|
+
* You should have received a copy of the GNU General Public License
|
14
|
+
* along with this program; if not, write to the Free Software
|
15
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
16
|
+
* USA.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef SIGAR_OS_H
|
20
|
+
#define SIGAR_OS_H
|
21
|
+
|
22
|
+
#include <assert.h>
|
23
|
+
|
24
|
+
#include <stdlib.h>
|
25
|
+
#include <unistd.h>
|
26
|
+
#include <fcntl.h>
|
27
|
+
#include <ctype.h>
|
28
|
+
#include <time.h>
|
29
|
+
|
30
|
+
#include <netinet/in.h>
|
31
|
+
#include <sys/types.h>
|
32
|
+
#include <sys/socket.h>
|
33
|
+
#include <arpa/inet.h>
|
34
|
+
|
35
|
+
typedef struct {
|
36
|
+
sigar_pid_t pid;
|
37
|
+
time_t mtime;
|
38
|
+
sigar_uint64_t vsize;
|
39
|
+
sigar_uint64_t rss;
|
40
|
+
sigar_uint64_t minor_faults;
|
41
|
+
sigar_uint64_t major_faults;
|
42
|
+
sigar_uint64_t ppid;
|
43
|
+
int tty;
|
44
|
+
int priority;
|
45
|
+
int nice;
|
46
|
+
sigar_uint64_t start_time;
|
47
|
+
sigar_uint64_t utime;
|
48
|
+
sigar_uint64_t stime;
|
49
|
+
char name[SIGAR_PROC_NAME_LEN];
|
50
|
+
char state;
|
51
|
+
int processor;
|
52
|
+
} linux_proc_stat_t;
|
53
|
+
|
54
|
+
typedef enum {
|
55
|
+
IOSTAT_NONE,
|
56
|
+
IOSTAT_PARTITIONS, /* 2.4 */
|
57
|
+
IOSTAT_DISKSTATS, /* 2.6 */
|
58
|
+
IOSTAT_SYS /* 2.6 */
|
59
|
+
} linux_iostat_e;
|
60
|
+
|
61
|
+
struct sigar_t {
|
62
|
+
SIGAR_T_BASE;
|
63
|
+
int pagesize;
|
64
|
+
int ram;
|
65
|
+
int proc_signal_offset;
|
66
|
+
linux_proc_stat_t last_proc_stat;
|
67
|
+
int lcpu;
|
68
|
+
linux_iostat_e iostat;
|
69
|
+
char *proc_net;
|
70
|
+
/* Native POSIX Thread Library 2.6+ kernel */
|
71
|
+
int has_nptl;
|
72
|
+
};
|
73
|
+
|
74
|
+
#define HAVE_STRERROR_R
|
75
|
+
#ifndef __USE_XOPEN2K
|
76
|
+
/* use gnu version of strerror_r */
|
77
|
+
#define HAVE_STRERROR_R_GLIBC
|
78
|
+
#endif
|
79
|
+
#define HAVE_READDIR_R
|
80
|
+
#define HAVE_GETPWNAM_R
|
81
|
+
#define HAVE_GETPWUID_R
|
82
|
+
#define HAVE_GETGRGID_R
|
83
|
+
|
84
|
+
#endif /* SIGAR_OS_H */
|
@@ -0,0 +1,719 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
3
|
+
* This file is part of SIGAR.
|
4
|
+
*
|
5
|
+
* SIGAR is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms version 2 of the GNU General Public License as
|
7
|
+
* published by the Free Software Foundation. This program is distributed
|
8
|
+
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
9
|
+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
10
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
11
|
+
* details.
|
12
|
+
*
|
13
|
+
* You should have received a copy of the GNU General Public License
|
14
|
+
* along with this program; if not, write to the Free Software
|
15
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
16
|
+
* USA.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#define WIN32_LEAN_AND_MEAN
|
20
|
+
|
21
|
+
#include "sigar.h"
|
22
|
+
#include "sigar_private.h"
|
23
|
+
#include "sigar_os.h"
|
24
|
+
#include "sigar_util.h"
|
25
|
+
|
26
|
+
#include <errno.h>
|
27
|
+
#include <monitor.h>
|
28
|
+
#include <stdio.h>
|
29
|
+
#include <windows.h>
|
30
|
+
#include <netware.h>
|
31
|
+
#include <novsock2.h>
|
32
|
+
#include <ws2tcpip.h>
|
33
|
+
#include <sys/statfs.h>
|
34
|
+
#define _STRUCT_TM
|
35
|
+
#include <nwtime.h>
|
36
|
+
#include <nit/nwservst.h>
|
37
|
+
#include <monitor.h>
|
38
|
+
/*
|
39
|
+
* http://developer.novell.com/research/appnotes/2003/may/05/a0305058.htm
|
40
|
+
*/
|
41
|
+
int _NonAppStart(void *NLMHandle,
|
42
|
+
void *errorScreen,
|
43
|
+
const char *cmdLine,
|
44
|
+
const char *loadDirPath,
|
45
|
+
size_t uninitializedDataLength,
|
46
|
+
void *NLMFileHandle,
|
47
|
+
int (*readRoutineP)(int conn,
|
48
|
+
void *fileHandle,
|
49
|
+
size_t offset,
|
50
|
+
size_t nbytes,
|
51
|
+
size_t *bytesRead,
|
52
|
+
void *buffer),
|
53
|
+
size_t customDataOffset,
|
54
|
+
size_t customDataSize,
|
55
|
+
int messageCount,
|
56
|
+
const char **messages)
|
57
|
+
{
|
58
|
+
|
59
|
+
#pragma unused(cmdLine)
|
60
|
+
#pragma unused(loadDirPath)
|
61
|
+
#pragma unused(uninitializedDataLength)
|
62
|
+
#pragma unused(NLMFileHandle)
|
63
|
+
#pragma unused(readRoutineP)
|
64
|
+
#pragma unused(customDataOffset)
|
65
|
+
#pragma unused(customDataSize)
|
66
|
+
#pragma unused(messageCount)
|
67
|
+
#pragma unused(messages)
|
68
|
+
|
69
|
+
WSADATA wsaData;
|
70
|
+
|
71
|
+
NWCallsInit(NULL, NULL);
|
72
|
+
|
73
|
+
return WSAStartup((WORD)MAKEWORD(2, 0), &wsaData);
|
74
|
+
}
|
75
|
+
|
76
|
+
void _NonAppStop(void)
|
77
|
+
{
|
78
|
+
NWCallsTerm(NULL);
|
79
|
+
WSACleanup();
|
80
|
+
}
|
81
|
+
|
82
|
+
int _NonAppCheckUnload(void)
|
83
|
+
{
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
int sigar_os_open(sigar_t **sigar)
|
88
|
+
{
|
89
|
+
*sigar = malloc(sizeof(**sigar));
|
90
|
+
|
91
|
+
return SIGAR_OK;
|
92
|
+
}
|
93
|
+
|
94
|
+
int sigar_os_close(sigar_t *sigar)
|
95
|
+
{
|
96
|
+
free(sigar);
|
97
|
+
return SIGAR_OK;
|
98
|
+
}
|
99
|
+
|
100
|
+
char *sigar_os_error_string(sigar_t *sigar, int err)
|
101
|
+
{
|
102
|
+
return NULL;
|
103
|
+
}
|
104
|
+
|
105
|
+
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
106
|
+
{
|
107
|
+
struct memory_info info;
|
108
|
+
if (netware_mem_info(&info) != 0) {
|
109
|
+
return errno;
|
110
|
+
}
|
111
|
+
mem->total = info.TotalKnownSystemMemoryUnder4Gb;
|
112
|
+
mem->used = info.TotalWorkMemory;
|
113
|
+
mem->free = mem->total - mem->used;
|
114
|
+
mem->actual_free = mem->free;
|
115
|
+
mem->actual_used = mem->used;
|
116
|
+
|
117
|
+
sigar_mem_calc_ram(sigar, mem);
|
118
|
+
|
119
|
+
return SIGAR_OK;
|
120
|
+
}
|
121
|
+
|
122
|
+
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
123
|
+
{
|
124
|
+
struct vmemory_info info;
|
125
|
+
|
126
|
+
if (netware_vmem_info(&info) != 0) {
|
127
|
+
return errno;
|
128
|
+
}
|
129
|
+
|
130
|
+
swap->used = info.SwapPageCount * PAGESIZE;
|
131
|
+
swap->free = info.SwapFreeCount * PAGESIZE;
|
132
|
+
swap->total = swap->used + swap->free;
|
133
|
+
swap->page_in = swap->page_out = -1;
|
134
|
+
|
135
|
+
return SIGAR_OK;
|
136
|
+
}
|
137
|
+
|
138
|
+
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
139
|
+
{
|
140
|
+
cpu->user = -1;
|
141
|
+
cpu->nice = -1;
|
142
|
+
cpu->sys = -1;
|
143
|
+
cpu->idle = -1;
|
144
|
+
cpu->wait = -1;
|
145
|
+
|
146
|
+
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
|
147
|
+
|
148
|
+
return SIGAR_OK;
|
149
|
+
}
|
150
|
+
|
151
|
+
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
152
|
+
{
|
153
|
+
return SIGAR_ENOTIMPL;
|
154
|
+
}
|
155
|
+
|
156
|
+
int sigar_uptime_get(sigar_t *sigar,
|
157
|
+
sigar_uptime_t *uptime)
|
158
|
+
{
|
159
|
+
LONG seconds, tenths;
|
160
|
+
|
161
|
+
TicksToSeconds(GetCurrentTicks(), &seconds, &tenths);
|
162
|
+
uptime->uptime = seconds;
|
163
|
+
|
164
|
+
return SIGAR_OK;
|
165
|
+
}
|
166
|
+
|
167
|
+
int sigar_loadavg_get(sigar_t *sigar,
|
168
|
+
sigar_loadavg_t *loadavg)
|
169
|
+
{
|
170
|
+
loadavg->loadavg[0] = -1;
|
171
|
+
loadavg->loadavg[1] = -1;
|
172
|
+
loadavg->loadavg[2] = -1;
|
173
|
+
|
174
|
+
return SIGAR_OK;
|
175
|
+
}
|
176
|
+
|
177
|
+
int sigar_proc_list_get(sigar_t *sigar,
|
178
|
+
sigar_proc_list_t *proclist)
|
179
|
+
{
|
180
|
+
return SIGAR_ENOTIMPL;
|
181
|
+
}
|
182
|
+
|
183
|
+
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
184
|
+
sigar_proc_mem_t *procmem)
|
185
|
+
{
|
186
|
+
procmem->size = -1;
|
187
|
+
procmem->vsize = -1;
|
188
|
+
procmem->share = -1;
|
189
|
+
procmem->rss = -1;
|
190
|
+
procmem->resident = -1;
|
191
|
+
procmem->page_faults = -1;
|
192
|
+
procmem->minor_faults = -1;
|
193
|
+
procmem->major_faults = -1;
|
194
|
+
|
195
|
+
return SIGAR_OK;
|
196
|
+
}
|
197
|
+
|
198
|
+
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
199
|
+
sigar_proc_cred_t *proccred)
|
200
|
+
{
|
201
|
+
proccred->uid = -1;
|
202
|
+
proccred->gid = -1;
|
203
|
+
proccred->euid = -1;
|
204
|
+
proccred->egid = -1;
|
205
|
+
|
206
|
+
return SIGAR_OK;
|
207
|
+
}
|
208
|
+
|
209
|
+
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
210
|
+
sigar_proc_time_t *proctime)
|
211
|
+
{
|
212
|
+
proctime->start_time = -1;
|
213
|
+
proctime->user = -1;
|
214
|
+
proctime->sys = -1;
|
215
|
+
proctime->total = proctime->user + proctime->sys;
|
216
|
+
|
217
|
+
return SIGAR_OK;
|
218
|
+
}
|
219
|
+
|
220
|
+
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
|
221
|
+
sigar_proc_state_t *procstate)
|
222
|
+
{
|
223
|
+
SIGAR_SSTRCPY(procstate->name, "java");
|
224
|
+
procstate->ppid = -1;
|
225
|
+
procstate->priority = -1;
|
226
|
+
procstate->nice = -1;
|
227
|
+
procstate->tty = -1;
|
228
|
+
procstate->state = 'R';
|
229
|
+
procstate->threads = -1;
|
230
|
+
procstate->processor = -1;
|
231
|
+
|
232
|
+
return SIGAR_OK;
|
233
|
+
}
|
234
|
+
|
235
|
+
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
236
|
+
sigar_proc_args_t *procargs)
|
237
|
+
{
|
238
|
+
return SIGAR_ENOTIMPL;
|
239
|
+
}
|
240
|
+
|
241
|
+
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
242
|
+
sigar_proc_env_t *procenv)
|
243
|
+
{
|
244
|
+
return SIGAR_ENOTIMPL;
|
245
|
+
}
|
246
|
+
|
247
|
+
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
|
248
|
+
sigar_proc_fd_t *procfd)
|
249
|
+
{
|
250
|
+
procfd->total = -1;
|
251
|
+
return SIGAR_OK;
|
252
|
+
}
|
253
|
+
|
254
|
+
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
255
|
+
sigar_proc_exe_t *procexe)
|
256
|
+
{
|
257
|
+
return SIGAR_ENOTIMPL;
|
258
|
+
}
|
259
|
+
|
260
|
+
int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
|
261
|
+
sigar_proc_modules_t *procmods)
|
262
|
+
{
|
263
|
+
return SIGAR_ENOTIMPL;
|
264
|
+
}
|
265
|
+
|
266
|
+
int sigar_thread_cpu_get(sigar_t *sigar,
|
267
|
+
sigar_uint64_t id,
|
268
|
+
sigar_thread_cpu_t *cpu)
|
269
|
+
{
|
270
|
+
return SIGAR_ENOTIMPL;
|
271
|
+
}
|
272
|
+
|
273
|
+
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
|
274
|
+
{
|
275
|
+
fsp->type = SIGAR_FSTYPE_UNKNOWN;
|
276
|
+
|
277
|
+
return SIGAR_OK;
|
278
|
+
}
|
279
|
+
|
280
|
+
int sigar_file_system_list_get(sigar_t *sigar,
|
281
|
+
sigar_file_system_list_t *fslist)
|
282
|
+
{
|
283
|
+
struct volume_info info;
|
284
|
+
int num = 0;
|
285
|
+
|
286
|
+
sigar_file_system_list_create(fslist);
|
287
|
+
|
288
|
+
while (netware_vol_info(&info, &num) == 0) {
|
289
|
+
sigar_file_system_t *fsp;
|
290
|
+
int len;
|
291
|
+
char *type = NULL;
|
292
|
+
|
293
|
+
SIGAR_FILE_SYSTEM_LIST_GROW(fslist);
|
294
|
+
|
295
|
+
fsp = &fslist->data[fslist->number++];
|
296
|
+
SIGAR_SSTRCPY(fsp->dev_name, info.name);
|
297
|
+
SIGAR_SSTRCPY(fsp->dir_name, info.name);
|
298
|
+
len = strlen(info.name);
|
299
|
+
fsp->dir_name[len] = ':';
|
300
|
+
fsp->dir_name[len+1] = '/';
|
301
|
+
fsp->dir_name[len+2] = '\0';
|
302
|
+
|
303
|
+
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
304
|
+
type = "nss";
|
305
|
+
|
306
|
+
sigar_fs_type_get(fsp);
|
307
|
+
if (!type) {
|
308
|
+
type = fsp->type_name;
|
309
|
+
}
|
310
|
+
|
311
|
+
SIGAR_SSTRCPY(fsp->sys_type_name, type);
|
312
|
+
fsp->options[0] = '\0'; /*XXX*/
|
313
|
+
}
|
314
|
+
|
315
|
+
return SIGAR_OK;
|
316
|
+
}
|
317
|
+
|
318
|
+
int sigar_disk_usage_get(sigar_t *sigar, const char *name,
|
319
|
+
sigar_disk_usage_t *usage)
|
320
|
+
{
|
321
|
+
return SIGAR_ENOTIMPL;
|
322
|
+
}
|
323
|
+
|
324
|
+
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
|
325
|
+
((buf.f * (buf.f_bsize / 512)) >> 1)
|
326
|
+
|
327
|
+
int sigar_file_system_usage_get(sigar_t *sigar,
|
328
|
+
const char *dirname,
|
329
|
+
sigar_file_system_usage_t *fsusage)
|
330
|
+
{
|
331
|
+
struct statfs buf;
|
332
|
+
|
333
|
+
if (statfs(dirname, &buf) != 0) {
|
334
|
+
return errno;
|
335
|
+
}
|
336
|
+
|
337
|
+
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_blocks);
|
338
|
+
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bfree);
|
339
|
+
fsusage->avail = fsusage->free;
|
340
|
+
fsusage->used = fsusage->total - fsusage->free;
|
341
|
+
fsusage->files = buf.f_files;
|
342
|
+
fsusage->free_files = buf.f_ffree;
|
343
|
+
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
|
344
|
+
|
345
|
+
SIGAR_DISK_STATS_INIT(&fsusage->disk);
|
346
|
+
|
347
|
+
return SIGAR_OK;
|
348
|
+
}
|
349
|
+
|
350
|
+
int sigar_cpu_info_list_get(sigar_t *sigar,
|
351
|
+
sigar_cpu_info_list_t *cpu_infos)
|
352
|
+
{
|
353
|
+
struct cpu_info cpu;
|
354
|
+
int num = 0;
|
355
|
+
|
356
|
+
sigar_cpu_info_list_create(cpu_infos);
|
357
|
+
|
358
|
+
while (netware_cpu_info(&cpu, &num) == 0) {
|
359
|
+
sigar_cpu_info_t *info;
|
360
|
+
|
361
|
+
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
|
362
|
+
|
363
|
+
info = &cpu_infos->data[cpu_infos->number++];
|
364
|
+
|
365
|
+
SIGAR_SSTRCPY(info->vendor, "vendor");
|
366
|
+
SIGAR_SSTRCPY(info->model, "model");
|
367
|
+
info->mhz = cpu.Speed;
|
368
|
+
info->cache_size = cpu.L2CacheSize;
|
369
|
+
}
|
370
|
+
|
371
|
+
return SIGAR_OK;
|
372
|
+
}
|
373
|
+
|
374
|
+
int sigar_net_route_list_get(sigar_t *sigar,
|
375
|
+
sigar_net_route_list_t *routelist)
|
376
|
+
{
|
377
|
+
return SIGAR_ENOTIMPL;
|
378
|
+
}
|
379
|
+
|
380
|
+
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
|
381
|
+
sigar_net_interface_stat_t *ifstat)
|
382
|
+
{
|
383
|
+
LONG board = 1; /* XXX derive from name */
|
384
|
+
LONG block = 0;
|
385
|
+
BYTE buffer[SS_DEFAULT_BUFFER_SIZE];
|
386
|
+
WORD len = sizeof(buffer);
|
387
|
+
CommonLANStructure *info;
|
388
|
+
|
389
|
+
if (SSGetLANCommonCounters(board, block, buffer, len) != 0) {
|
390
|
+
return ENOENT;
|
391
|
+
}
|
392
|
+
|
393
|
+
info = &((GetLANCommonCountersStructure *)buffer)->info;
|
394
|
+
|
395
|
+
ifstat->rx_bytes = info->TotalTxOKByteCountHigh;
|
396
|
+
ifstat->rx_packets = info->TotalRxPacketCount;
|
397
|
+
ifstat->rx_errors = info->PacketRxMiscErrorCount;
|
398
|
+
ifstat->rx_dropped = -1;
|
399
|
+
ifstat->rx_overruns = info->PacketRxTooBigCount;
|
400
|
+
ifstat->rx_frame = -1;
|
401
|
+
|
402
|
+
ifstat->tx_bytes = info->TotalTxOKByteCountHigh;
|
403
|
+
ifstat->tx_packets = info->TotalTxPacketCount;
|
404
|
+
ifstat->tx_errors = info->PacketTxMiscErrorCount;
|
405
|
+
ifstat->tx_dropped = info->RetryTxCount;
|
406
|
+
ifstat->tx_overruns = info->PacketTxTooBigCount;
|
407
|
+
ifstat->tx_collisions = -1;
|
408
|
+
ifstat->tx_carrier = -1;
|
409
|
+
|
410
|
+
ifstat->speed = SIGAR_FIELD_NOTIMPL;
|
411
|
+
|
412
|
+
return SIGAR_OK;
|
413
|
+
}
|
414
|
+
|
415
|
+
int sigar_net_connection_walk(sigar_net_connection_walker_t *walker)
|
416
|
+
{
|
417
|
+
return SIGAR_ENOTIMPL;
|
418
|
+
}
|
419
|
+
|
420
|
+
int sigar_net_info_get(sigar_t *sigar,
|
421
|
+
sigar_net_info_t *netinfo)
|
422
|
+
{
|
423
|
+
return SIGAR_ENOTIMPL;
|
424
|
+
}
|
425
|
+
|
426
|
+
int sigar_proc_port_get(sigar_t *sigar, int protocol,
|
427
|
+
unsigned long port, sigar_pid_t *pid)
|
428
|
+
{
|
429
|
+
return SIGAR_ENOTIMPL;
|
430
|
+
}
|
431
|
+
|
432
|
+
int sigar_nfs_ping(char *host)
|
433
|
+
{
|
434
|
+
return SIGAR_ENOTIMPL;
|
435
|
+
}
|
436
|
+
|
437
|
+
int sigar_os_sys_info_get(sigar_t *sigar,
|
438
|
+
sigar_sys_info_t *sysinfo)
|
439
|
+
{
|
440
|
+
SIGAR_SSTRCPY(sysinfo->vendor, "Novell");
|
441
|
+
|
442
|
+
return SIGAR_OK;
|
443
|
+
}
|
444
|
+
|
445
|
+
int sigar_get_iftype(const char *name, int *type, int *inst)
|
446
|
+
{
|
447
|
+
if (strnEQ(name, "eth", IFTYPE_ETH)) {
|
448
|
+
*type = IFTYPE_ETH;
|
449
|
+
}
|
450
|
+
else if (strnEQ(name, "lo", IFTYPE_LO)) {
|
451
|
+
*type = IFTYPE_LO;
|
452
|
+
}
|
453
|
+
else {
|
454
|
+
return EINVAL;
|
455
|
+
}
|
456
|
+
|
457
|
+
if (isdigit(*(name + *type))) {
|
458
|
+
*inst = atoi(name + *type);
|
459
|
+
}
|
460
|
+
else {
|
461
|
+
return EINVAL;
|
462
|
+
}
|
463
|
+
|
464
|
+
return SIGAR_OK;
|
465
|
+
}
|
466
|
+
|
467
|
+
static void hwaddr_lookup(sigar_t *sigar,
|
468
|
+
sigar_net_interface_config_t *ifconfig,
|
469
|
+
int num)
|
470
|
+
{
|
471
|
+
uint8_t addr[SIGAR_IFHWADDRLEN];
|
472
|
+
|
473
|
+
if (netware_net_macaddr(num+1, addr) == 0) {
|
474
|
+
sigar_net_address_mac_set(ifconfig->hwaddr,
|
475
|
+
addr,
|
476
|
+
sizeof(addr));
|
477
|
+
}
|
478
|
+
else {
|
479
|
+
sigar_hwaddr_set_null(ifconfig);
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
static int sigar_ioctl_iflist(sigar_t *sigar,
|
484
|
+
SOCKET sock,
|
485
|
+
DWORD *bytes)
|
486
|
+
{
|
487
|
+
return WSAIoctl(sock,
|
488
|
+
SIO_GET_INTERFACE_LIST,
|
489
|
+
NULL,
|
490
|
+
0,
|
491
|
+
(void *)sigar->ifconf_buf,
|
492
|
+
sigar->ifconf_len,
|
493
|
+
bytes,
|
494
|
+
NULL,
|
495
|
+
NULL);
|
496
|
+
}
|
497
|
+
|
498
|
+
static int get_iflist(sigar_t *sigar, DWORD *bytes)
|
499
|
+
{
|
500
|
+
SOCKET sock = INVALID_SOCKET;
|
501
|
+
int status, rc, limit;
|
502
|
+
|
503
|
+
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
504
|
+
|
505
|
+
if (sock == INVALID_SOCKET) {
|
506
|
+
return WSAGetLastError();
|
507
|
+
}
|
508
|
+
|
509
|
+
if (sigar->ifconf_len == 0) {
|
510
|
+
sigar->ifconf_len = 8192;
|
511
|
+
sigar->ifconf_buf = malloc(sigar->ifconf_len);
|
512
|
+
}
|
513
|
+
|
514
|
+
/*
|
515
|
+
* XXX We can't tell ahead of time what buffer size is required
|
516
|
+
* limit just incase.
|
517
|
+
*/
|
518
|
+
for (limit=0; limit<100; limit++) {
|
519
|
+
rc = sigar_ioctl_iflist(sigar, sock, bytes);
|
520
|
+
if (rc && (WSAGetLastError() == WSAEFAULT)) {
|
521
|
+
sigar->ifconf_len += (sizeof(INTERFACE_INFO) * 16);
|
522
|
+
sigar->ifconf_buf = malloc(sigar->ifconf_len);
|
523
|
+
}
|
524
|
+
}
|
525
|
+
|
526
|
+
status = rc ? WSAGetLastError() : SIGAR_OK;
|
527
|
+
|
528
|
+
closesocket(sock);
|
529
|
+
|
530
|
+
return status;
|
531
|
+
}
|
532
|
+
|
533
|
+
SIGAR_DECLARE(int)
|
534
|
+
sigar_net_interface_config_get(sigar_t *sigar,
|
535
|
+
const char *name,
|
536
|
+
sigar_net_interface_config_t *ifconfig)
|
537
|
+
{
|
538
|
+
DWORD i, num, bytes;
|
539
|
+
DWORD lo=0, eth=0;
|
540
|
+
int status, type, inst;
|
541
|
+
INTERFACE_INFO *if_info = NULL;
|
542
|
+
u_long flags;
|
543
|
+
|
544
|
+
if (!name) {
|
545
|
+
return sigar_net_interface_config_primary_get(sigar, ifconfig);
|
546
|
+
}
|
547
|
+
|
548
|
+
/* win32 lacks socket ioctls to query given interface.
|
549
|
+
* so we loop through the list to find our made up ifname.
|
550
|
+
*/
|
551
|
+
status = get_iflist(sigar, &bytes);
|
552
|
+
if (status != SIGAR_OK) {
|
553
|
+
return status;
|
554
|
+
}
|
555
|
+
|
556
|
+
num = bytes / sizeof(INTERFACE_INFO);
|
557
|
+
|
558
|
+
if ((status = sigar_get_iftype(name, &type, &inst)) != SIGAR_OK) {
|
559
|
+
return status;
|
560
|
+
}
|
561
|
+
|
562
|
+
for (i=0; i<num ; i++) {
|
563
|
+
if_info = ((INTERFACE_INFO *)sigar->ifconf_buf) + i;
|
564
|
+
|
565
|
+
if (if_info->iiFlags & IFF_LOOPBACK) {
|
566
|
+
if ((type == IFTYPE_LO) && (inst == lo)) {
|
567
|
+
break;
|
568
|
+
}
|
569
|
+
++lo;
|
570
|
+
}
|
571
|
+
else {
|
572
|
+
if ((type == IFTYPE_ETH) && (inst == eth)) {
|
573
|
+
break;
|
574
|
+
}
|
575
|
+
++eth;
|
576
|
+
}
|
577
|
+
|
578
|
+
if_info = NULL;
|
579
|
+
}
|
580
|
+
|
581
|
+
if (!if_info) {
|
582
|
+
return ENOENT;
|
583
|
+
}
|
584
|
+
|
585
|
+
SIGAR_ZERO(ifconfig);
|
586
|
+
|
587
|
+
SIGAR_SSTRCPY(ifconfig->name, name);
|
588
|
+
|
589
|
+
#define if_s_addr(a) \
|
590
|
+
((struct sockaddr_in *)&a)->sin_addr.s_addr
|
591
|
+
|
592
|
+
sigar_net_address_set(ifconfig->address,
|
593
|
+
if_s_addr(if_info->iiAddress));
|
594
|
+
sigar_net_address_set(ifconfig->broadcast,
|
595
|
+
if_s_addr(if_info->iiBroadcastAddress));
|
596
|
+
sigar_net_address_set(ifconfig->netmask,
|
597
|
+
if_s_addr(if_info->iiNetmask));
|
598
|
+
|
599
|
+
flags = if_info->iiFlags;
|
600
|
+
|
601
|
+
if (flags & IFF_UP) {
|
602
|
+
ifconfig->flags |= SIGAR_IFF_UP|SIGAR_IFF_RUNNING;
|
603
|
+
}
|
604
|
+
if (flags & IFF_BROADCAST) {
|
605
|
+
ifconfig->flags |= SIGAR_IFF_BROADCAST;
|
606
|
+
}
|
607
|
+
if (flags & IFF_LOOPBACK) {
|
608
|
+
ifconfig->flags |= SIGAR_IFF_LOOPBACK;
|
609
|
+
sigar_net_address_set(ifconfig->destination,
|
610
|
+
ifconfig->address.addr.in);
|
611
|
+
sigar_net_address_set(ifconfig->broadcast, 0);
|
612
|
+
SIGAR_SSTRCPY(ifconfig->type,
|
613
|
+
SIGAR_NIC_LOOPBACK);
|
614
|
+
}
|
615
|
+
else {
|
616
|
+
SIGAR_SSTRCPY(ifconfig->type,
|
617
|
+
SIGAR_NIC_ETHERNET);
|
618
|
+
}
|
619
|
+
|
620
|
+
/* should be overridden w/ better description
|
621
|
+
* using MIB_IFROW.bDescr when hwaddr is lookedup
|
622
|
+
*/
|
623
|
+
SIGAR_SSTRCPY(ifconfig->description,
|
624
|
+
ifconfig->name);
|
625
|
+
|
626
|
+
hwaddr_lookup(sigar, ifconfig, i);
|
627
|
+
|
628
|
+
if (flags & IFF_POINTTOPOINT) {
|
629
|
+
ifconfig->flags |= SIGAR_IFF_POINTOPOINT;
|
630
|
+
}
|
631
|
+
if (flags & IFF_MULTICAST) {
|
632
|
+
ifconfig->flags |= SIGAR_IFF_MULTICAST;
|
633
|
+
}
|
634
|
+
|
635
|
+
return SIGAR_OK;
|
636
|
+
}
|
637
|
+
|
638
|
+
/*
|
639
|
+
* win32 interface list does not include a name.
|
640
|
+
* and the name from GetIfList() is the name of card
|
641
|
+
* including vendor name, etc. so we use 'eth' for ethernet
|
642
|
+
* interfaces and 'lo' for loopback.
|
643
|
+
*/
|
644
|
+
|
645
|
+
#define ETH "eth"
|
646
|
+
#define LO "lo"
|
647
|
+
|
648
|
+
SIGAR_DECLARE(int)
|
649
|
+
sigar_net_interface_list_get(sigar_t *sigar,
|
650
|
+
sigar_net_interface_list_t *iflist)
|
651
|
+
{
|
652
|
+
char eth[56], lo[56];
|
653
|
+
int ethcnt=0, locnt=0;
|
654
|
+
DWORD i, num, bytes;
|
655
|
+
int status;
|
656
|
+
|
657
|
+
status = get_iflist(sigar, &bytes);
|
658
|
+
if (status != SIGAR_OK) {
|
659
|
+
return status;
|
660
|
+
}
|
661
|
+
|
662
|
+
num = bytes / sizeof(INTERFACE_INFO);
|
663
|
+
|
664
|
+
iflist->number = 0;
|
665
|
+
iflist->size = num;
|
666
|
+
iflist->data =
|
667
|
+
malloc(sizeof(*(iflist->data)) * iflist->size);
|
668
|
+
|
669
|
+
for (i=0; i<num ; i++) {
|
670
|
+
INTERFACE_INFO *if_info =
|
671
|
+
((INTERFACE_INFO *)sigar->ifconf_buf) + i;
|
672
|
+
char *name;
|
673
|
+
|
674
|
+
if (if_info->iiFlags & IFF_LOOPBACK) {
|
675
|
+
sprintf(lo, LO "%d", locnt++);
|
676
|
+
name = strdup(lo);
|
677
|
+
}
|
678
|
+
else {
|
679
|
+
/* XXX: assuming ethernet here */
|
680
|
+
sprintf(eth, ETH "%d", ethcnt++);
|
681
|
+
name = strdup(eth);
|
682
|
+
}
|
683
|
+
|
684
|
+
iflist->data[iflist->number++] = name;
|
685
|
+
}
|
686
|
+
|
687
|
+
return SIGAR_OK;
|
688
|
+
}
|
689
|
+
|
690
|
+
SIGAR_DECLARE(int)
|
691
|
+
sigar_tcp_get(sigar_t *sigar,
|
692
|
+
sigar_tcp_t *tcp)
|
693
|
+
{
|
694
|
+
return SIGAR_ENOTIMPL;
|
695
|
+
}
|
696
|
+
|
697
|
+
int sigar_nfs_client_v2_get(sigar_t *sigar,
|
698
|
+
sigar_nfs_client_v2_t *nfs)
|
699
|
+
{
|
700
|
+
return SIGAR_ENOTIMPL;
|
701
|
+
}
|
702
|
+
|
703
|
+
int sigar_nfs_server_v2_get(sigar_t *sigar,
|
704
|
+
sigar_nfs_server_v2_t *nfs)
|
705
|
+
{
|
706
|
+
return SIGAR_ENOTIMPL;
|
707
|
+
}
|
708
|
+
|
709
|
+
int sigar_nfs_client_v3_get(sigar_t *sigar,
|
710
|
+
sigar_nfs_client_v3_t *nfs)
|
711
|
+
{
|
712
|
+
return SIGAR_ENOTIMPL;
|
713
|
+
}
|
714
|
+
|
715
|
+
int sigar_nfs_server_v3_get(sigar_t *sigar,
|
716
|
+
sigar_nfs_server_v3_t *nfs)
|
717
|
+
{
|
718
|
+
return SIGAR_ENOTIMPL;
|
719
|
+
}
|