From 6bf1e3ec9ade03af80df22e9007c4c014e4748e5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 9 Jun 2022 11:57:17 +0000 Subject: [PATCH] tools/nut-scanner: adjust ltdl names or contents to WIN32 builds --- tools/nut-scanner/scan_nut.c | 5 +++++ tools/nut-scanner/scan_snmp.c | 38 +++++++++++++++++++++++++++++++++++ tools/nut-scanner/scan_usb.c | 5 +++++ 3 files changed, 48 insertions(+) diff --git a/tools/nut-scanner/scan_nut.c b/tools/nut-scanner/scan_nut.c index a2b26054e3..9420e304ce 100644 --- a/tools/nut-scanner/scan_nut.c +++ b/tools/nut-scanner/scan_nut.c @@ -26,7 +26,12 @@ #include /* dynamic link library stuff */ +#ifndef WIN32 static char * libname = "libupsclient"; +#else +/* TODO: Detect DLL name at build time */ +static char * libname = "libupsclient-3"; +#endif static lt_dlhandle dl_handle = NULL; static const char *dl_error = NULL; diff --git a/tools/nut-scanner/scan_snmp.c b/tools/nut-scanner/scan_snmp.c index 3c432529ec..f72ff87d39 100644 --- a/tools/nut-scanner/scan_snmp.c +++ b/tools/nut-scanner/scan_snmp.c @@ -110,6 +110,43 @@ static oid * (*nut_usmDESPrivProtocol); /* return 0 on error */ int nutscan_load_snmp_library() { +#ifdef WIN32 + /* With MinGW, the netsnmp library may be linked statically (no dll) */ + /* Assignments were parsed from code below with: + * grep -A1 dlsym tools/nut-scanner/scan_snmp.c | egrep 'dlsym|")' | sed -e 's| *lt_dlsym(dl_handle, *| |' -e 's,");,;,' -e 's,",,' -e 's,= *$,=,' + */ + *(void **) (&nut_init_snmp) = init_snmp; + *(void **) (&nut_snmp_sess_init) = + snmp_sess_init; + *(void **) (&nut_snmp_sess_open) = + snmp_sess_open; + *(void **) (&nut_snmp_sess_close) = + snmp_sess_close; + *(void **) (&nut_snmp_sess_session) = + snmp_sess_session; + *(void **) (&nut_snmp_parse_oid) = + snmp_parse_oid; + *(void **) (&nut_snmp_pdu_create) = + snmp_pdu_create; + *(void **) (&nut_snmp_add_null_var) = + snmp_add_null_var; + *(void **) (&nut_snmp_sess_synch_response) = + snmp_sess_synch_response; + *(void **) (&nut_snmp_oid_compare) = + snmp_oid_compare; + *(void **) (&nut_snmp_free_pdu) = snmp_free_pdu; + *(void **) (&nut_generate_Ku) = generate_Ku; + *(void **) (&nut_snmp_api_errstring) = + snmp_api_errstring; + *(void **) (&nut_snmp_errno) = snmp_errno; + *(void **) (&nut_usmAESPrivProtocol) = + *(void **) (&nut_usmHMACMD5AuthProtocol) = + usmHMACMD5AuthProtocol; + *(void **) (&nut_usmHMACSHA1AuthProtocol) = + usmHMACSHA1AuthProtocol; + *(void **) (&nut_usmDESPrivProtocol) = + usmDESPrivProtocol; +#else if( dl_handle != NULL ) { /* if previous init failed */ if( dl_handle == (void *)1 ) { @@ -234,6 +271,7 @@ int nutscan_load_snmp_library() if ((dl_error = lt_dlerror()) != NULL) { goto err; } +#endif /* WIN32 */ return 1; err: diff --git a/tools/nut-scanner/scan_usb.c b/tools/nut-scanner/scan_usb.c index 065e67a587..e141067768 100644 --- a/tools/nut-scanner/scan_usb.c +++ b/tools/nut-scanner/scan_usb.c @@ -28,7 +28,12 @@ #include /* dynamic link library stuff */ +#ifndef WIN32 static char * libname = "libusb"; +#else +/* TODO: Detect DLL name at build time */ +static char * libname = "libusb-0-1-4"; +#endif static lt_dlhandle dl_handle = NULL; static const char *dl_error = NULL; static int (*nut_usb_close)(usb_dev_handle *dev);