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

Reply via email to