Using standard UDP port 161 with Agent ++ does not work on my Linux computer

Jochen Katz katz____agentpp.com
Wed Mar 21 20:57:31 CET 2001


Hi,

> I tried to run an agent with the standard SNMP port UDP 161 on my SUSE 6.3 Linux computer and the agent canceled with the following error message.
> 
> usr1 at Stillwater:~/agent++/examples/atm_mib/src > agent 161
> 20010315.17:01:41: 01165: (0)ERROR  : main: SNMP port init failed: (-22).
> Terminated
> 
> With UDP port 4700 the agent runs just fine.

you have to start the agent with root permissions, as ports below 1024
are protected from normal users.
 
> I have a, what I think, similar problem with the trap receiver example that comes with SNMP++. When I start the trap receiver it cancels with the error message "Transport in use"

The receive_trap example didn't do what it printed out (listening on
port 10162). In fact it wanted to bind to port 162. With the attached
patch the Snmp-session will use any free port and the first command line
argument is used as the port to listen for traps (default is 10162 if
none is specified). Please try again and report if you're still having
problems.

Best regards,
  Jochen
-------------- next part --------------
--- receive_trap.cpp.orig	Wed Mar 21 20:32:28 2001
+++ receive_trap.cpp	Wed Mar 21 20:41:33 2001
@@ -74,11 +74,17 @@
   cout << endl;
 }
 
-int main()
+int main(int argc, char **argv)
 {
+  int trap_port;
+  if (argc < 2)
+    trap_port = 10162; // no need to be root
+  else
+    trap_port = atoi(argv[1]);
+
    //----------[ create a SNMP++ session ]-----------------------------------
    int status; 
-   Snmp snmp( status, 10161);                // check construction status
+   Snmp snmp( status, 0);                // check construction status
    if ( status != SNMP_CLASS_SUCCESS) {
       cout << "SNMP++ Session Create Fail, " << snmp.error_msg(status) << "\n";
       return 1;
@@ -170,8 +176,8 @@
 #endif
    OidCollection oidc;
    TargetCollection targetc;
-   cout << "Listening for traps on port 10162" << endl;
-   CNotifyEventQueue::set_listen_port(162);
+   cout << "Trying to register for traps on port " << trap_port << "." << endl;
+   CNotifyEventQueue::set_listen_port(trap_port);
    status = snmp.notify_register(oidc, targetc, callback, NULL);
    if (status != SNMP_CLASS_SUCCESS)
    {
@@ -180,7 +186,7 @@
      exit(1);
    }
    else
-     cout << "Waiting for traps/informs on port 10162..." << endl;
+     cout << "Waiting for traps/informs..." << endl;
 
    while (1)
      SNMPProcessEvents();


More information about the AGENTPP mailing list