PKG_NAME:=mini_snmpd
PKG_VERSION:=1.2b
-PKG_RELEASE:=3
+PKG_RELEASE:=6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://members.aon.at/linuxfreak/linux/
PKG_MD5SUM:=9e432c50ba8216d7fab0983b11b7112a
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)/$(PKG_NAME)
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
-define Package/mini-snmpd/Default
- TITLE:=SNMP server for embedded systems
- URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
-endef
-
define Package/mini-snmpd
-$(call Package/mini-snmpd/Default)
SECTION:=net
CATEGORY:=Network
- TITLE+= Mini Snmpd
+ TITLE:=SNMP server for embedded systems
+ URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
endef
-PKG_OFLAGS:=$(TARGET_CFLAGS) -DSYSLOG
-
-ifeq ($(CONFIG_IPV6),y)
- PKG_OFLAGS+= -D__IPV6__
+ifneq ($(CONFIG_IPV6),)
+ TARGET_CFLAGS+= -D__IPV6__
else
- PKG_OFLAGS+= -D__IPV4__
+ TARGET_CFLAGS+= -D__IPV4__
endif
+TARGET_CFLAGS+= -DSYSLOG
+
MAKE_FLAGS+= \
- OFLAGS="$(PKG_OFLAGS)" \
+ OFLAGS="$(TARGET_CFLAGS)" \
STRIP="/bin/true" \
INSTALL_ROOT="$(PKG_INSTALL_DIR)"
$(INSTALL_BIN) ./files/mini_snmpd.init $(1)/etc/init.d/mini_snmpd
endef
-Package/mini-snmpd6/install=$(Package/mini-snmpd/install)
+define Package/mini-snmpd/conffiles
+/etc/config/mini_snmpd
+endef
$(eval $(call BuildPackage,mini-snmpd))
#!/bin/sh /etc/rc.common
-# Copyright (C) 2009 OpenWrt.org
+# Copyright (C) 2009-2011 OpenWrt.org
-NAME=mini_snmpd
-PROG=/usr/bin/$NAME
START=50
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+append_disk() {
+ local disk="$1"
+ append disks "$disk" ','
+}
+
+append_interface() {
+ local name="$1"
+ local interface
+ config_get interface "$name" 'ifname' "$name"
+ append interfaces "$interface" ','
+}
+
append_string() {
local section="$1"
local option="$2"
[ -n "$_val" ] && append args "$3 $_val"
}
-mini_snmpd_config() {
+start_instance() {
local cfg="$1"
- args=""
+ local args=""
+ local disks=""
+ local interfaces=""
+ local ipv6
append_string "$cfg" community "-c"
append_string "$cfg" location "-L"
append_string "$cfg" contact "-C"
- append_string "$cfg" disks "-d"
- append_string "$cfg" interfaces "-i"
config_get_bool ipv6 "$cfg" "ipv6" '0'
[ "$ipv6" -gt 0 ] && append args "-6"
config_get_bool enabled "$cfg" "enabled" '1'
- [ "$enabled" -gt 0 ] && $PROG $args &
+ [ "$enabled" -gt 0 ] || return 1
+
+ config_list_foreach "$section" 'disks' append_disk
+ args="${args}${disks:+ -d $disks}"
+
+ config_list_foreach "$section" 'interfaces' append_interface
+ args="${args}${interfaces:+ -i $interfaces}"
+
+ service_start /usr/bin/mini_snmpd $args
}
start() {
- config_load mini_snmpd
- config_foreach mini_snmpd_config mini_snmpd
+ include /lib/network
+ scan_interfaces
+ config_load 'mini_snmpd'
+ config_foreach start_instance 'mini_snmpd'
}
stop() {
- killall mini_snmpd
+ service_stop /usr/bin/mini_snmpd
}
--- a/globals.c
+++ b/globals.c
-@@ -31,6 +31,8 @@
- const struct in_addr inaddr_any = { INADDR_ANY };
- #endif
+@@ -27,9 +27,9 @@
+ * Global variables
+ */
-+int g_family = AF_INET;
+-#ifdef __IPV4__
+ const struct in_addr inaddr_any = { INADDR_ANY };
+-#endif
+
++int g_family = AF_INET;
+
in_port_t g_udp_port = 161;
in_port_t g_tcp_port = 161;
- int g_timeout = 100;
--- a/mini_snmpd.c
+++ b/mini_snmpd.c
@@ -54,6 +54,10 @@ static void print_help(void)
{ "timeout", 1, 0, 't' },
{ "traps", 1, 0, 'T' },
{ "auth", 0, 0, 'a' },
-@@ -396,6 +408,14 @@ int main(int argc, char *argv[])
+@@ -327,7 +339,12 @@ int main(int argc, char *argv[])
+ int option_index = 1;
+ int c;
+
+- struct my_sockaddr_t sockaddr;
++ union {
++ struct sockaddr_in sa;
++#ifdef __IPV6__
++ struct sockaddr_in6 sa6;
++#endif
++ } sockaddr;
+ my_socklen_t socklen;
+ struct timeval tv_last;
+ struct timeval tv_now;
+@@ -396,6 +413,14 @@ int main(int argc, char *argv[])
case 'v':
g_verbose = 1;
break;
case 'l':
print_version();
exit(EXIT_ARGS);
-@@ -435,12 +455,12 @@ int main(int argc, char *argv[])
+@@ -435,15 +460,24 @@ int main(int argc, char *argv[])
#endif
/* Open the server's UDP port and prepare it for listening */
exit(EXIT_SYSCALL);
}
- sockaddr.my_sin_family = my_af_inet;
-+ sockaddr.my_sin_family = g_family;
- sockaddr.my_sin_port = htons(g_udp_port);
- sockaddr.my_sin_addr = my_inaddr_any;
- socklen = sizeof (sockaddr);
-@@ -457,7 +477,7 @@ int main(int argc, char *argv[])
+- sockaddr.my_sin_port = htons(g_udp_port);
+- sockaddr.my_sin_addr = my_inaddr_any;
+- socklen = sizeof (sockaddr);
++ if (g_family == AF_INET) {
++ sockaddr.sa.sin_family = g_family;
++ sockaddr.sa.sin_port = htons(g_udp_port);
++ sockaddr.sa.sin_addr = inaddr_any;
++ socklen = sizeof(sockaddr.sa);
++#ifdef __IPV6__
++ } else {
++ sockaddr.sa6.sin6_family = g_family;
++ sockaddr.sa6.sin6_port = htons(g_udp_port);
++ sockaddr.sa6.sin6_addr = in6addr_any;
++ socklen = sizeof(sockaddr.sa6);
++#endif
++ }
+ if (bind(g_udp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
+ lprintf(LOG_ERR, "could not bind UDP socket to port %d: %m\n", g_udp_port);
+ exit(EXIT_SYSCALL);
+@@ -457,7 +491,7 @@ int main(int argc, char *argv[])
}
/* Open the server's TCP port and prepare it for listening */
if (g_tcp_sockfd == -1) {
lprintf(LOG_ERR, "could not create TCP socket: %m\n");
exit(EXIT_SYSCALL);
-@@ -474,7 +494,7 @@ int main(int argc, char *argv[])
+@@ -474,10 +508,19 @@ int main(int argc, char *argv[])
lprintf(LOG_WARNING, "could not set SO_REUSEADDR on TCP socket: %m\n");
exit(EXIT_SYSCALL);
}
- sockaddr.my_sin_family = my_af_inet;
-+ sockaddr.my_sin_family = g_family;
- sockaddr.my_sin_port = htons(g_tcp_port);
- sockaddr.my_sin_addr = my_inaddr_any;
- socklen = sizeof (sockaddr);
+- sockaddr.my_sin_port = htons(g_tcp_port);
+- sockaddr.my_sin_addr = my_inaddr_any;
+- socklen = sizeof (sockaddr);
++ if (g_family == AF_INET) {
++ sockaddr.sa.sin_family = g_family;
++ sockaddr.sa.sin_port = htons(g_udp_port);
++ sockaddr.sa.sin_addr = inaddr_any;
++ socklen = sizeof(sockaddr.sa);
++#ifdef __IPV6__
++ } else {
++ sockaddr.sa6.sin6_family = g_family;
++ sockaddr.sa6.sin6_port = htons(g_udp_port);
++ sockaddr.sa6.sin6_addr = in6addr_any;
++ socklen = sizeof(sockaddr.sa6);
++#endif
++ }
+ if (bind(g_tcp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
+ lprintf(LOG_ERR, "could not bind TCP socket to port %d: %m\n", g_tcp_port);
+ exit(EXIT_SYSCALL);
--- a/mini_snmpd.h
+++ b/mini_snmpd.h
@@ -255,6 +255,7 @@ typedef struct demoinfo_s {
extern int g_timeout;
extern int g_auth;
extern int g_verbose;
+@@ -265,9 +266,9 @@ extern char *g_vendor;
+ extern char *g_location;
+ extern char *g_contact;
+ extern char *g_bind_to_device;
+-#ifdef __IPV4__
++
+ extern const struct in_addr inaddr_any;
+-#endif
++
+
+ extern char *g_disk_list[MAX_NR_DISKS];
+ extern int g_disk_list_length;