summaryrefslogtreecommitdiff
blob: 389cd2bfd8730ed7dd6e5668340251908ab5bca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Index: agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c,v
retrieving revision 1.5.2.1
diff -u -p -u -r1.5.2.1 tcpConn_linux.c
--- agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c	17 Aug 2006 08:52:15 -0000	1.5.2.1
+++ agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c	1 Sep 2006 17:15:23 -0000
@@ -169,11 +169,20 @@ _load4(netsnmp_container *container, u_i
             break;
         }
 
-        entry->loc_port = htons((unsigned short) local_port);
-        entry->rmt_port = htons((unsigned short) remote_port);
+        /** oddly enough, these appear to already be in network order */
+        entry->loc_port = (unsigned short) local_port;
+        entry->rmt_port = (unsigned short) remote_port;
         entry->tcpConnState = state;
+        
+        /** the addr string may need work */
         buf_len = strlen(local_addr);
-        netsnmp_assert(8 == buf_len);
+        if ((8 != buf_len) ||
+            (-1 == netsnmp_addrstr_hton(local_addr, 8))) {
+            DEBUGMSGT(("verbose:access:tcpconn:container",
+                       " error processing local address\n"));
+            netsnmp_access_tcpconn_entry_free(entry);
+            continue;
+        }
         offset = 0;
         tmp_ptr = entry->loc_addr;
         rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
@@ -188,8 +197,15 @@ _load4(netsnmp_container *container, u_i
             continue;
         }
 
-        buf_len = strlen(remote_addr);
-        netsnmp_assert(8 == buf_len);
+        /** the addr string may need work */
+        buf_len = strlen((char*)remote_addr);
+        if ((8 != buf_len) ||
+            (-1 == netsnmp_addrstr_hton(remote_addr, 8))) {
+            DEBUGMSGT(("verbose:access:tcpconn:container",
+                       " error processing remote address\n"));
+            netsnmp_access_tcpconn_entry_free(entry);
+            continue;
+        }
         offset = 0;
         tmp_ptr = entry->rmt_addr;
         rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
@@ -244,6 +260,8 @@ _load6(netsnmp_container *container, u_i
     fgets(line, sizeof(line), in); /* skip header */
 
     /*
+     * Note: PPC (big endian)
+     *
      *   sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
      *  0: 00000000000000000000000000000001:1466 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000   500        0 326699 1 efb81580 3000 0 0 2 -1
      */
@@ -291,11 +309,20 @@ _load6(netsnmp_container *container, u_i
             break;
         }
 
-        entry->loc_port = htons((unsigned short) local_port);
-        entry->rmt_port = htons((unsigned short) remote_port);
+        /** oddly enough, these appear to already be in network order */
+        entry->loc_port = (unsigned short) local_port;
+        entry->rmt_port = (unsigned short) remote_port;
         entry->tcpConnState = state;
 
-        buf_len = strlen(local_addr);
+        /** the addr string may need work */
+        buf_len = strlen((char*)local_addr);
+        if ((32 != buf_len) ||
+            (-1 == netsnmp_addrstr_hton(local_addr, 32))) {
+            DEBUGMSGT(("verbose:access:tcpconn:container",
+                       " error processing local address\n"));
+            netsnmp_access_tcpconn_entry_free(entry);
+            continue;
+        }
         offset = 0;
         tmp_ptr = entry->loc_addr;
         rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
@@ -310,7 +337,14 @@ _load6(netsnmp_container *container, u_i
             continue;
         }
 
-        buf_len = strlen(remote_addr);
+        buf_len = strlen((char*)remote_addr);
+        if ((32 != buf_len) ||
+            (-1 == netsnmp_addrstr_hton(remote_addr, 32))) {
+            DEBUGMSGT(("verbose:access:tcpconn:container",
+                       " error processing remote address\n"));
+            netsnmp_access_tcpconn_entry_free(entry);
+            continue;
+        }
         offset = 0;
         tmp_ptr = entry->rmt_addr;
         rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
Index: agent/mibgroup/udp-mib/data_access/udp_endpoint_linux.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/agent/mibgroup/udp-mib/data_access/udp_endpoint_linux.c,v
retrieving revision 1.2.2.1
diff -u -p -u -r1.2.2.1 udp_endpoint_linux.c
--- agent/mibgroup/udp-mib/data_access/udp_endpoint_linux.c	25 Jan 2006 16:27:40 -0000	1.2.2.1
+++ agent/mibgroup/udp-mib/data_access/udp_endpoint_linux.c	1 Sep 2006 17:15:23 -0000
@@ -112,9 +112,9 @@ _process_line_udp_ep(netsnmp_line_info *
                      struct netsnmp_line_process_info_s* lpi)
 {
     netsnmp_udp_endpoint_entry *ep = (netsnmp_udp_endpoint_entry *)mem;
-    char                 *ptr;
+    char                 *ptr, *sep;
     u_char               *u_ptr;
-    size_t                u_ptr_len, offset;
+    size_t                u_ptr_len, offset, len;
 
     /*
      * skip 'sl'
@@ -135,10 +135,22 @@ _process_line_udp_ep(netsnmp_line_info *
     /*
      * get local address. ignore error on hex conversion, since that
      * function doesn't like the ':' between address and port. check the
-     * offset to see if it worked.
+     * offset to see if it worked. May need to flip string too.
      */
     u_ptr = ep->loc_addr;
     u_ptr_len = sizeof(ep->loc_addr);
+    sep = strchr(ptr, ':');
+    if (NULL == sep) {
+        DEBUGMSGTL(("text:util:tvi", "no ':' '%s'\n",
+                    line_info->start));
+        return PMLP_RC_MEMORY_UNUSED;
+    }
+    len = (sep - ptr);
+    if (-1 == netsnmp_addrstr_hton(ptr, len)) {
+        DEBUGMSGTL(("text:util:tvi", "bad length %d for loc addr '%s'\n",
+                    u_ptr_len, line_info->start));
+        return PMLP_RC_MEMORY_UNUSED;
+    }
     offset = 0;
     netsnmp_hex_to_binary(&u_ptr, &u_ptr_len, &offset, 0, ptr, NULL);
     if ((4 != offset) && (16 != offset)) {
@@ -159,14 +171,26 @@ _process_line_udp_ep(netsnmp_line_info *
     /*
      * get remote address. ignore error on hex conversion, since that
      * function doesn't like the ':' between address and port. check the
-     * offset to see if it worked.
+     * offset to see if it worked. May need to flip string too.
      */
     u_ptr = ep->rmt_addr;
     u_ptr_len = sizeof(ep->rmt_addr);
+    sep = strchr(ptr, ':');
+    if (NULL == sep) {
+        DEBUGMSGTL(("text:util:tvi", "no ':' '%s'\n",
+                    line_info->start));
+        return PMLP_RC_MEMORY_UNUSED;
+    }
+    len = (sep - ptr);
+    if (-1 == netsnmp_addrstr_hton(ptr, len)) {
+        DEBUGMSGTL(("text:util:tvi", "bad length %d for rmt addr '%s'\n",
+                    u_ptr_len, line_info->start));
+        return PMLP_RC_MEMORY_UNUSED;
+    }
     offset = 0;
     netsnmp_hex_to_binary(&u_ptr, &u_ptr_len, &offset, 0, ptr, NULL);
     if ((4 != offset) && (16 != offset)) {
-        DEBUGMSGTL(("text:util:tvi", "bad offset %d for loc addr '%s'\n",
+        DEBUGMSGTL(("text:util:tvi", "bad offset %d for rmt addr '%s'\n",
                     offset, line_info->start));
         return PMLP_RC_MEMORY_UNUSED;
     }
Index: include/net-snmp/library/tools.h
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/include/net-snmp/library/tools.h,v
retrieving revision 5.8.2.2
diff -u -p -u -r5.8.2.2 tools.h
--- include/net-snmp/library/tools.h	13 Jun 2006 12:50:36 -0000	5.8.2.2
+++ include/net-snmp/library/tools.h	1 Sep 2006 17:15:24 -0000
@@ -198,7 +198,9 @@ extern          "C" {
     int             marker_tticks(marker_t pm);
     int             timeval_tticks(struct timeval *tv);
     char            *netsnmp_getenv(const char *name);
-    
+
+    int             netsnmp_addrstr_hton(char *ptr, size_t len);
+
 #ifdef __cplusplus
 }
 #endif
Index: snmplib/tools.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/snmplib/tools.c,v
retrieving revision 5.10.2.2
diff -u -p -u -r5.10.2.2 tools.c
--- snmplib/tools.c	25 Jul 2006 08:04:35 -0000	5.10.2.2
+++ snmplib/tools.c	1 Sep 2006 17:15:26 -0000
@@ -1042,3 +1042,35 @@ char *netsnmp_getenv(const char *name)
 #endif
 }
 
+/*
+ * swap the order of an inet addr string
+ */
+int
+netsnmp_addrstr_hton(char *ptr, size_t len)
+{
+#ifndef WORDS_BIGENDIAN
+    char tmp[8];
+    
+    if (8 == len) {
+        tmp[0] = ptr[6];
+        tmp[1] = ptr[7];
+        tmp[2] = ptr[4];
+        tmp[3] = ptr[5];
+        tmp[4] = ptr[2];
+        tmp[5] = ptr[3];
+        tmp[6] = ptr[0];
+        tmp[7] = ptr[1];
+        memcpy (ptr, &tmp, 8);
+    }
+    else if (32 == len) {
+        netsnmp_addrstr_hton(ptr   , 8);
+        netsnmp_addrstr_hton(ptr+8 , 8);
+        netsnmp_addrstr_hton(ptr+16, 8);
+        netsnmp_addrstr_hton(ptr+24, 8);
+    }
+    else
+        return -1;
+#endif
+
+    return 0;
+}