Hello again,
On the topic of getting the agent listening port number while processing a
SNMP equest, discussed in previous emails:
I am working on a proposal for a patch, and have this code already, as a
first possible partial solution to the above wish.
File: snmplib/transports/snmpTCPBaseDomain.c
Code:
// The port number of the agent to which the SNMP request was sent.
*static* uint16_t agent_tcp_port_number = 0;
*int* netsnmp_tcpbase_recv(netsnmp_transport *t, *void* *buf, *int* size,
*void* **opaque, *int* *olength) // Todo
{
*int* rc = -1;
*if* (t != *NULL* && t->sock >= 0) {
*while* (rc < 0) {
rc = recvfrom(t->sock, buf, size, 0, *NULL*, *NULL*);
*if* (rc < 0 && errno != EINTR) {
DEBUGMSGTL(("netsnmp_tcpbase", "recv fd %d err %d
(\"%s\")\n",
t->sock, errno, strerror(errno)));
*break*;
}
DEBUGMSGTL(("netsnmp_tcpbase", "recv fd %d got %d bytes\n",
t->sock, rc));
*struct* sockaddr_in sin;
socklen_t len = *sizeof*(sin);
*if* (getsockname(t->sock, (*struct* sockaddr *)&sin, &len) == -
1)
DEBUGMSGTL(("vms", "getsockname error %s\n",
strerror(errno)));
*else* {
agent_tcp_port_number = ntohs(sin.sin_port)
DEBUGMSGTL(("vms", "agent port number %d\n",
agent_tcp_port_number));
}
}
....
This is just a first attempt at getting this to work. The code above logs
the agent's port number, so that is now working.
Questions:
1. What do you think of this code?
2. What are the ideas to expose this agent_tcp_port_number via the API?
(Possibly I could add a function in the public API, that gets this variable
and exposes it as a call.) Ideas?
Met vriendelijke groeten,
With kind regards,
Teus Benschop
https://freesoftwareconsultants.nl
https://bibledit.org
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders