Craig, Would you mind sharing some more details? You mentioned that you use an [asyncapp] stanza in your snmp.conf that limits configuration to just your app - I can't seem to make this work. I've learned that if I init_snmp("my_app") that the API will scan ~/.snmp/my_app.conf, but I can't seem to insert "clientaddr" and "clientaddrUsesPort" tokens into this file - a (non-fatal) diagnostic is generated when I call init_snmp(), and the behavior reverts to "random SRC PORT for each session".
Perhaps if you could cut and paste the relevant lines from your snmp.conf I would see something obvious I'm missing. As mentioned, I am able to force all sessions to use the same SRC PORT by simply appending the clientaddr and clientaddrUsesPort tokens to the end of ~/.snmp/snmp.conf, but this change affects *all* net-snmp apps. It would be helpful/instructive to set the SRC PORT on an app-by-app basis (e.g. my_app, my_app_2, my_app_3 all configured to use a different SRC PORT). On Mon, Jan 11, 2021 at 5:26 PM Ed Fair <quacksp...@gmail.com> wrote: > Craig - > > You are exactly right - the config file allows me to control this - thank > you so much! I couldn't use the [application name] syntax, but simply > adding these two lines to the end of the config file had the desired effect > of causing all outbound SNMP from SRC PORT 30000: > > clientaddr :30000 > clientaddrUsesPort yes > > I'll work to understand how to use the [program name] approach next. I'm > guessing the init_snmp() call sets the program name used. > > ed > > On Sun, Jan 10, 2021 at 6:48 PM Craig Small <csm...@dropbear.xyz> wrote: > >> Actually the snmplibrary already has a way of binding the ports. >> >> In my $HOME/.snmp/snmp.conf I just add this: >> >> [asyncapp] >> #doDebugging 1 >> clientaddr 10.0.0.1:12345 >> clientaddrUsesPort yes >> >> asyncapp is the name of my program. I have bound outbound connections >> with a source port of 12345 on interface 127.0.0.1 (for testing) >> 10.0.0.1 is the local IP address of the computer that's sending the >> request. >> >> Wireshark shows this: >> User Datagram Protocol, Src Port: 12345, Dst Port: 161 >> >> >> >> >> >> >> >> On Thu, 7 Jan 2021 at 15:03, Ed Fair <quacksp...@gmail.com> wrote: >> >>> Craig, >>> >>> The tutorials don't mention subsessions or traditional vs single session >>> use, but the header/c files do (and that's all they do - mention them). >>> I'm just curious what these abstractions are for since they seem, on the >>> surface, related to my needs. >>> >>> As an exercise, I've tried but so far been unable to create a >>> session/socket which uses a specific port - no errors, but no pdus/packets >>> transmitted. And anyway, I don't care if the port selected is random, my >>> goal is to use *the same* port to query multiple agents. I don't care how >>> it's done, as long as the end result is "all outbound UDP use same SRC >>> port". >>> >>> >>> On Wed, Jan 6, 2021, 5:28 AM Craig Small <csm...@dropbear.xyz> wrote: >>> >>>> On Wed, 6 Jan 2021 at 10:01, Ed Fair <quacksp...@gmail.com> wrote: >>>> >>>>> Thanks for the reply. The Simple_Async_Application in your link uses >>>>> one session/socket/SRC port per agent. I've compiled and run this sample >>>>> successfully, but I haven't been able to modify it to use a single >>>>> session/socket/SRC port. >>>>> >>>> It might need to be something more low-level as reusing sockets >>>> (therefore the ports) is generally a bad idea. >>>> >>>> The netsnmp_session has an attribute of local_port. If this is set to >>>> zero (the default) then it picks it randomly. I'd try setting that and see >>>> what happens. A quick look in the snmplib source code shows it is used for >>>> creating the transport. >>>> >>>> I understand "don't hammer agents" but I don't understand your "one >>>>> query per agent" limit - is this a limitation of the API? >>>>> >>>> Not at all, a lot of agents are terrible and do stupid things like have >>>> exclusive locks on important components of the system. I've killed many >>>> devices (the remote agents, not my code) by being too enthusiastic about >>>> querying them. >>>> >>>> >>>>> I'm new to this API, I might be missing key concepts... but I am >>>>> confused by the "traditional vs single" distinction, and I'm curious what >>>>> "subsessions" are. >>>>> >>>> Are either of those mentioned in the tutorial? They could mean multiple >>>> things but was trying to find the context of what you are asking here. >>>> >>>> - Craig >>>> >>>
_______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders