That works for me. I would much rather see wrapper functions than continue adding to the #ifdef hell in application code. Very nice!

Andy

Alex Burger wrote:

Attached is a patch that allows you to use the registry to store variables that are normally defined as environment variables.


A new function called netsnmp_getenv has been created in tools.c. For *nix it simply returns what getenv() would return.

For Windows it:

-returns a pointer to the environment variable if it is defined

-otherwise looks up the variable in HKCU\Software\Net-SNMP. If it is defined, it copies it to the environment variable and then returns a pointer to the environment variable

-otherwise looks up the variable in HKLM\Software\Net-SNMP. If it is defined, it copies it to the environment variable and then returns a pointer to the environment variable

-otherwise returns a NULL

The real environment variables are looked at first because when specifying MIBDIRS on the command line, it actually stores the passed values in the environment variable which is then used when reading the MIB files during initialization. This means if you have the env vars defined, the registry values will be ignored.

The following variables can be defined in the registry under either HKCU\Software\Net-SNMP or HKLM\Software\Net-SNMP:

-MIBDIRS
-MIBFILES
-MIBS
-PREFIX
-SNMP_PERSISTENT_FILE
-SNMPCONFPATH
-HOME

For example:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Net-SNMP]
"SNMPCONFPATH"="d:/Program Files/Net-SNMP/etc/snmp"
"SNMP_PERSISTENT_FILE"="c:/temp/persist/snmpd.conf"
"MIBDIRS"="$HOME;c:/usr/share/snmp/mibs"
"HOME"="c:/mymibs"

(HOME would not normally be used, but I used the above as a test and it worked. Use -Dfixup_mib_directory to see it. Use -Dread_config and -Dinit_mib to see the others).

By using this patch and modifying the NSIS installer script, the problem of having to reboot the machine after registering the snmpd and snmptrapd service will go away (tested).

I think this is the simplest way to implement registry access for Windows. It will work with any environment variable as long as netsnmp_getenv is used instead of getenv so if any are added in the future, we don't have to worry about porting it to the registry.

What does everyone think?

Alex



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Net-snmp-coders mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to