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
|
Fix clientaddr functionality.
Previously, the clientaddr option in snmp.conf was parsed, but the actual
clientaddr was used to bind(), yet sendmsg() was still called with 0.0.0.0.
This patch alters:
- netsnmp_udp_fmtaddr: include both sides of addr_pair for debugging.
- netsnmp_udp_transport: Set addr_pair->local_addr in the remote && client_socket path.
- netsnmp_udp_transport: Print a debugging error on failure to bind()
- netsnmp_udp_transport: Print out the full client open addr_pair data.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Status: Merged in upstream r16654
Tracking-URL: https://sourceforge.net/tracker/?func=detail&atid=312694&aid=1775124&group_id=12694
diff -NuwbBar --exclude docs --exclude '*.o' --exclude 'config.*' --exclude perl --exclude '*~' net-snmp-5.4.old/snmplib/snmpUDPDomain.c net-snmp-5.4/snmplib/snmpUDPDomain.c
--- net-snmp-5.4.old/snmplib/snmpUDPDomain.c 2006-09-19 16:42:17.000000000 -0700
+++ net-snmp-5.4/snmplib/snmpUDPDomain.c 2007-08-15 19:17:27.000000000 -0700
@@ -100,12 +100,15 @@ netsnmp_udp_fmtaddr(netsnmp_transport *t
struct sockaddr_in *to = NULL;
char tmp[64];
to = (struct sockaddr_in *) &(addr_pair->remote_addr);
+ /* Using strdup on the output of inet_ntoa is important! */
if (to == NULL) {
- return strdup("UDP: unknown");
+ sprintf(tmp, "UDP: [%s]->unknown",
+ strdup(inet_ntoa(addr_pair->local_addr)));
+ } else {
+ sprintf(tmp, "UDP: [%s]->[%s]:%hu",
+ strdup(inet_ntoa(addr_pair->local_addr)),
+ strdup(inet_ntoa(to->sin_addr)), ntohs(to->sin_port));
}
-
- sprintf(tmp, "UDP: [%s]:%hu",
- inet_ntoa(to->sin_addr), ntohs(to->sin_port));
return strdup(tmp);
}
}
@@ -670,11 +673,23 @@ netsnmp_udp_transport(struct sockaddr_in
NETSNMP_DS_LIB_CLIENT_ADDR);
if (client_socket) {
struct sockaddr_in client_addr;
+ int ret;
netsnmp_sockaddr_in2(&client_addr, client_socket, NULL);
+ addr_pair.local_addr = client_addr.sin_addr;
client_addr.sin_port = 0;
- bind(t->sock, (struct sockaddr *)&client_addr,
+ ret = bind(t->sock, (struct sockaddr *)&client_addr,
sizeof(struct sockaddr));
+ if(ret)
+ DEBUGMSGTL(("netsnmp_udp", "failed to bind for clientaddr: %d %s\n",
+ errno,strerror(errno)));
+ /* TODO: should we exit here? */
}
+
+ str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
+ sizeof(netsnmp_udp_addr_pair));
+ DEBUGMSGTL(("netsnmp_udp", "client open %s\n", str));
+ free(str);
+
/*
* Save the (remote) address in the
* transport-specific data pointer for later use by netsnmp_udp_send.
|