90
128
while (fgets(line, sizeof(line), in)) {
91
129
netsnmp_tcpconn_entry *entry;
92
static int linux_states[12] =
93
{ 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 };
94
int state, rc, local_port, remote_port;
98
entry = netsnmp_access_tcpconn_entry_create();
104
if (5 != (rc = sscanf(line, "%*d: %x:%x %x:%x %x",
105
&entry->indexes[NETSNMP_TCPCONN_IDX_LOCAL_ADDR],
107
&entry->indexes[NETSNMP_TCPCONN_IDX_REMOTE_ADDR],
108
&remote_port, &state))) {
109
DEBUGMSGT(("access:tcpconn:container",
110
"error parsing line (%d != 5)\n", rc));
111
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
112
netsnmp_access_tcpconn_entry_free(entry);
115
DEBUGMSGT(("verbose:access:tcpconn:container"," line '%s'\n", line));
116
entry->indexes[NETSNMP_TCPCONN_IDX_LOCAL_PORT] =
117
htons((unsigned short) local_port);
118
entry->indexes[NETSNMP_TCPCONN_IDX_REMOTE_PORT] =
119
htons((unsigned short) remote_port);
120
entry->tcpConnState = (state & 0xf) < 12 ? linux_states[state & 0xf] : 2;
123
* add entry to container
125
CONTAINER_INSERT(container, entry);
130
int state, rc, local_port, remote_port, buf_len, offset, tmp_state;
131
u_char local_addr[10], remote_addr[10];
134
if (5 != (rc = sscanf(line, "%*d: %8[0-9A-Z]:%x %8[0-9A-Z]:%x %x",
135
local_addr, &local_port,
136
remote_addr, &remote_port, &tmp_state))) {
137
DEBUGMSGT(("access:tcpconn:container",
138
"error parsing line (%d != 5)\n", rc));
139
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
142
DEBUGMSGT(("verbose:access:tcpconn:container"," line '%s'\n", line));
145
* check if we care about listen state
147
state = (tmp_state & 0xf) < 12 ? linux_states[tmp_state & 0xf] : 2;
149
if (TCPCONNECTIONSTATE_LISTEN == state) {
150
if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN) {
151
DEBUGMSGT(("verbose:access:tcpconn:container",
152
" skipping listen\n"));
156
else if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN) {
157
DEBUGMSGT(("verbose:access:tcpconn:container",
158
" skipping non-listen\n"));
165
entry = netsnmp_access_tcpconn_entry_create();
171
entry->loc_port = htons((unsigned short) local_port);
172
entry->rmt_port = htons((unsigned short) remote_port);
173
entry->tcpConnState = state;
174
buf_len = strlen(local_addr);
175
netsnmp_assert(8 == buf_len);
177
tmp_ptr = entry->loc_addr;
178
rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
179
&offset, 0, local_addr, NULL);
180
entry->loc_addr_len = offset;
181
if ( 4 != entry->loc_addr_len ) {
182
DEBUGMSGT(("access:tcpconn:container",
183
"error parsing local addr (%d != 4)\n",
184
entry->loc_addr_len));
185
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
186
netsnmp_access_tcpconn_entry_free(entry);
190
buf_len = strlen(remote_addr);
191
netsnmp_assert(8 == buf_len);
193
tmp_ptr = entry->rmt_addr;
194
rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
195
&offset, 0, remote_addr, NULL);
196
entry->rmt_addr_len = offset;
197
if ( 4 != entry->rmt_addr_len ) {
198
DEBUGMSGT(("access:tcpconn:container",
199
"error parsing remote addr (%d != 4)\n",
200
entry->rmt_addr_len));
201
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
202
netsnmp_access_tcpconn_entry_free(entry);
207
* add entry to container
209
entry->arbitrary_index = CONTAINER_SIZE(container) + 1;
210
CONTAINER_INSERT(container, entry);
224
* @retval 0 no errors
228
_load6(netsnmp_container *container, u_int load_flags)
234
netsnmp_assert(NULL != container);
237
#define PROCFILE "/proc/net/tcp6"
238
if (!(in = fopen(PROCFILE, "r"))) {
239
snmp_log(LOG_ERR,"could not open " PROCFILE "\n");
243
fgets(line, sizeof(line), in); /* skip header */
246
* sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
247
* 0: 00000000000000000000000000000001:1466 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 500 0 326699 1 efb81580 3000 0 0 2 -1
249
while (fgets(line, sizeof(line), in)) {
250
netsnmp_tcpconn_entry *entry;
251
int state, rc, local_port, remote_port, buf_len, offset,
253
u_char local_addr[48], remote_addr[48];
256
if (5 != (rc = sscanf(line, "%*d: %47[0-9A-Z]:%x %47[0-9A-Z]:%x %x",
257
local_addr, &local_port,
258
remote_addr, &remote_port, &tmp_state))) {
259
DEBUGMSGT(("access:tcpconn:container",
260
"error parsing line (%d != 5)\n", rc));
261
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
264
DEBUGMSGT(("verbose:access:tcpconn:container"," line '%s'\n", line));
267
* check if we care about listen state
269
state = (tmp_state & 0xf) < 12 ? linux_states[tmp_state & 0xf] : 2;
271
if (TCPCONNECTIONSTATE_LISTEN == state) {
272
if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN) {
273
DEBUGMSGT(("verbose:access:tcpconn:container",
274
" skipping listen\n"));
278
else if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN) {
279
DEBUGMSGT(("verbose:access:tcpconn:container",
280
" skipping non-listen\n"));
287
entry = netsnmp_access_tcpconn_entry_create();
293
entry->loc_port = htons((unsigned short) local_port);
294
entry->rmt_port = htons((unsigned short) remote_port);
295
entry->tcpConnState = state;
297
buf_len = strlen(local_addr);
299
tmp_ptr = entry->loc_addr;
300
rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
301
&offset, 0, local_addr, NULL);
302
entry->loc_addr_len = offset;
303
if (( 16 != entry->loc_addr_len ) && ( 20 != entry->loc_addr_len )) {
304
DEBUGMSGT(("access:tcpconn:container",
305
"error parsing local addr (%d != 16|20)\n",
306
entry->loc_addr_len));
307
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
308
netsnmp_access_tcpconn_entry_free(entry);
312
buf_len = strlen(remote_addr);
314
tmp_ptr = entry->rmt_addr;
315
rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
316
&offset, 0, remote_addr, NULL);
317
entry->rmt_addr_len = offset;
318
if (( 16 != entry->rmt_addr_len ) && ( 20 != entry->rmt_addr_len )) {
319
DEBUGMSGT(("access:tcpconn:container",
320
"error parsing remote addr (%d != 16|20)\n",
321
entry->rmt_addr_len));
322
DEBUGMSGT(("access:tcpconn:container"," line '%s'\n", line));
323
netsnmp_access_tcpconn_entry_free(entry);
329
* add entry to container
331
entry->arbitrary_index = CONTAINER_SIZE(container) + 1;
332
CONTAINER_INSERT(container, entry);