[packages] mini_snmpd: Merge mini_snmpd_ipv6 with mini_snmpd
- add ipv6 module dependency if IPV6 support is selected - update ipv6 patch to compile IPv6 support conditionally - cleanup Makefile - refresh patches git-svn-id: svn://svn.openwrt.org/openwrt/packages@20955 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
4df8439004
commit
6827adf5ab
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2009 OpenWrt.orgv
|
# Copyright (C) 2010 OpenWrt.org
|
||||||
#
|
#
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=mini_snmpd
|
PKG_NAME:=mini_snmpd
|
||||||
PKG_VERSION:=1.0
|
PKG_VERSION:=1.0
|
||||||
PKG_RELEASE:=5
|
PKG_RELEASE:=6
|
||||||
|
|
||||||
PKG_SOURCE:=mini_snmpd.tar.gz
|
PKG_SOURCE:=mini_snmpd.tar.gz
|
||||||
PKG_SOURCE_URL:=http://members.aon.at/linuxfreak/linux/
|
PKG_SOURCE_URL:=http://members.aon.at/linuxfreak/linux/
|
||||||
@ -24,17 +24,20 @@ define Package/mini-snmpd
|
|||||||
CATEGORY:=Network
|
CATEGORY:=Network
|
||||||
TITLE:=SNMP server for embedded systems
|
TITLE:=SNMP server for embedded systems
|
||||||
URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
|
URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
|
||||||
|
DEPENDS:=+IPV6:kmod-ipv6
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
||||||
define Build/Compile
|
MAKE_FLAGS+= \
|
||||||
$(MAKE) -C $(PKG_BUILD_DIR) \
|
|
||||||
CC="$(TARGET_CC)" \
|
|
||||||
OFLAGS="$(TARGET_CFLAGS) -DSYSLOG" \
|
|
||||||
STRIP="/bin/true" \
|
STRIP="/bin/true" \
|
||||||
INSTALL_ROOT="$(PKG_INSTALL_DIR)" \
|
INSTALL_ROOT="$(PKG_INSTALL_DIR)" \
|
||||||
mini_snmpd install
|
mini_snmpd install
|
||||||
endef
|
|
||||||
|
ifeq ($(CONFIG_IPV6),y)
|
||||||
|
MAKE_FLAGS+= OFLAGS="$(TARGET_CFLAGS) -DSYSLOG -DIPV6"
|
||||||
|
else
|
||||||
|
MAKE_FLAGS+= OFLAGS="$(TARGET_CFLAGS) -DSYSLOG"
|
||||||
|
endif
|
||||||
|
|
||||||
define Package/mini-snmpd/install
|
define Package/mini-snmpd/install
|
||||||
$(INSTALL_DIR) $(1)/usr/bin
|
$(INSTALL_DIR) $(1)/usr/bin
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--- a/mini_snmpd.c
|
--- a/mini_snmpd.c
|
||||||
+++ b/mini_snmpd.c
|
+++ b/mini_snmpd.c
|
||||||
@@ -134,7 +134,7 @@
|
@@ -134,7 +134,7 @@ static void handle_udp_client(void)
|
||||||
} else if (rv != g_udp_client.size) {
|
} else if (rv != g_udp_client.size) {
|
||||||
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: "
|
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: "
|
||||||
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
||||||
@ -9,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
dump_packet(&g_udp_client);
|
dump_packet(&g_udp_client);
|
||||||
@@ -211,7 +211,7 @@
|
@@ -211,7 +211,7 @@ static void handle_tcp_client_write(clie
|
||||||
} else if (rv != client->size) {
|
} else if (rv != client->size) {
|
||||||
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: "
|
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: "
|
||||||
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
||||||
@ -20,7 +20,7 @@
|
|||||||
return;
|
return;
|
||||||
--- a/utils.c
|
--- a/utils.c
|
||||||
+++ b/utils.c
|
+++ b/utils.c
|
||||||
@@ -106,7 +106,7 @@
|
@@ -106,7 +106,7 @@ void dump_packet(const client_t *client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lprintf(LOG_DEBUG, "%s %u bytes %s %s:%d (%s)\n",
|
lprintf(LOG_DEBUG, "%s %u bytes %s %s:%d (%s)\n",
|
||||||
|
@ -1,107 +1,116 @@
|
|||||||
|
--- a/globals.c
|
||||||
|
+++ b/globals.c
|
||||||
|
@@ -27,6 +27,9 @@
|
||||||
|
* Global variables
|
||||||
|
*/
|
||||||
|
|
||||||
|
+#ifndef IPV6
|
||||||
|
+const struct in_addr inaddr_any = { INADDR_ANY };
|
||||||
|
+#endif
|
||||||
|
in_port_t g_udp_port = 161;
|
||||||
|
in_port_t g_tcp_port = 161;
|
||||||
|
int g_timeout = 1;
|
||||||
--- a/mini_snmpd.c
|
--- a/mini_snmpd.c
|
||||||
+++ b/mini_snmpd.c
|
+++ b/mini_snmpd.c
|
||||||
@@ -90,9 +90,10 @@
|
@@ -90,9 +90,10 @@ static void handle_signal(int signo)
|
||||||
|
|
||||||
static void handle_udp_client(void)
|
static void handle_udp_client(void)
|
||||||
{
|
{
|
||||||
- struct sockaddr_in sockaddr;
|
- struct sockaddr_in sockaddr;
|
||||||
+ struct sockaddr_in6 sockaddr;
|
+ struct my_sockaddr_t sockaddr;
|
||||||
socklen_t socklen;
|
socklen_t socklen;
|
||||||
int rv;
|
int rv;
|
||||||
+ char straddr[INET6_ADDRSTRLEN];
|
+ char straddr[my_inet_addrstrlen];
|
||||||
|
|
||||||
/* Read the whole UDP packet from the socket at once */
|
/* Read the whole UDP packet from the socket at once */
|
||||||
socklen = sizeof (sockaddr);
|
socklen = sizeof (sockaddr);
|
||||||
@@ -105,8 +106,8 @@
|
@@ -105,22 +106,23 @@ static void handle_udp_client(void)
|
||||||
}
|
}
|
||||||
g_udp_client.timestamp = time(NULL);
|
g_udp_client.timestamp = time(NULL);
|
||||||
g_udp_client.sockfd = g_udp_sockfd;
|
g_udp_client.sockfd = g_udp_sockfd;
|
||||||
- g_udp_client.addr = sockaddr.sin_addr.s_addr;
|
- g_udp_client.addr = sockaddr.sin_addr.s_addr;
|
||||||
- g_udp_client.port = sockaddr.sin_port;
|
- g_udp_client.port = sockaddr.sin_port;
|
||||||
+ g_udp_client.addr = sockaddr.sin6_addr;
|
+ g_udp_client.addr = sockaddr.my_sin_addr;
|
||||||
+ g_udp_client.port = sockaddr.sin6_port;
|
+ g_udp_client.port = sockaddr.my_sin_port;
|
||||||
g_udp_client.size = rv;
|
g_udp_client.size = rv;
|
||||||
g_udp_client.outgoing = 0;
|
g_udp_client.outgoing = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -114,13 +115,14 @@
|
dump_packet(&g_udp_client);
|
||||||
#endif
|
#endif
|
||||||
|
+ inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
|
||||||
|
|
||||||
/* Call the protocol handler which will prepare the response packet */
|
/* Call the protocol handler which will prepare the response packet */
|
||||||
+ inet_ntop(AF_INET6, &sockaddr.sin6_addr, straddr, sizeof(straddr));
|
|
||||||
if (snmp(&g_udp_client) == -1) {
|
if (snmp(&g_udp_client) == -1) {
|
||||||
lprintf(LOG_WARNING, "could not handle packet from UDP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not handle packet from UDP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
return;
|
return;
|
||||||
} else if (g_udp_client.size == 0) {
|
} else if (g_udp_client.size == 0) {
|
||||||
lprintf(LOG_WARNING, "could not handle packet from UDP client %s:%d: ignored\n",
|
lprintf(LOG_WARNING, "could not handle packet from UDP client %s:%d: ignored\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_udp_client.outgoing = 1;
|
g_udp_client.outgoing = 1;
|
||||||
@@ -128,13 +130,14 @@
|
@@ -130,11 +132,11 @@ static void handle_udp_client(void)
|
||||||
/* Send the whole UDP packet to the socket at once */
|
|
||||||
rv = sendto(g_udp_sockfd, g_udp_client.packet, g_udp_client.size,
|
|
||||||
MSG_DONTWAIT, (struct sockaddr *)&sockaddr, socklen);
|
MSG_DONTWAIT, (struct sockaddr *)&sockaddr, socklen);
|
||||||
+ inet_ntop(AF_INET6, &sockaddr.sin6_addr, straddr, sizeof(straddr));
|
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
} else if (rv != g_udp_client.size) {
|
} else if (rv != g_udp_client.size) {
|
||||||
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: "
|
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: "
|
||||||
- "only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
- "only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
||||||
- sockaddr.sin_port, rv, (int) g_udp_client.size);
|
- sockaddr.sin_port, rv, (int) g_udp_client.size);
|
||||||
+ "only %d of %d bytes written\n", straddr,
|
+ "only %d of %d bytes written\n", straddr,
|
||||||
+ sockaddr.sin6_port, rv, (int) g_udp_client.size);
|
+ sockaddr.my_sin_port, rv, (int) g_udp_client.size);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
dump_packet(&g_udp_client);
|
dump_packet(&g_udp_client);
|
||||||
@@ -143,11 +146,12 @@
|
@@ -143,11 +145,12 @@ static void handle_udp_client(void)
|
||||||
|
|
||||||
static void handle_tcp_connect(void)
|
static void handle_tcp_connect(void)
|
||||||
{
|
{
|
||||||
- struct sockaddr_in tmp_sockaddr;
|
- struct sockaddr_in tmp_sockaddr;
|
||||||
- struct sockaddr_in sockaddr;
|
- struct sockaddr_in sockaddr;
|
||||||
+ struct sockaddr_in6 tmp_sockaddr;
|
+ struct my_sockaddr_t tmp_sockaddr;
|
||||||
+ struct sockaddr_in6 sockaddr;
|
+ struct my_sockaddr_t sockaddr;
|
||||||
socklen_t socklen;
|
socklen_t socklen;
|
||||||
client_t *client;
|
client_t *client;
|
||||||
int rv;
|
int rv;
|
||||||
+ char straddr[INET6_ADDRSTRLEN];
|
+ char straddr[my_inet_addrstrlen];
|
||||||
|
|
||||||
/* Accept the new connection (remember the client's IP address and port) */
|
/* Accept the new connection (remember the client's IP address and port) */
|
||||||
socklen = sizeof (sockaddr);
|
socklen = sizeof (sockaddr);
|
||||||
@@ -168,10 +172,11 @@
|
@@ -168,10 +171,11 @@ static void handle_tcp_connect(void)
|
||||||
lprintf(LOG_ERR, "could not accept TCP connection: internal error");
|
lprintf(LOG_ERR, "could not accept TCP connection: internal error");
|
||||||
exit(EXIT_SYSCALL);
|
exit(EXIT_SYSCALL);
|
||||||
}
|
}
|
||||||
- tmp_sockaddr.sin_addr.s_addr = client->addr;
|
- tmp_sockaddr.sin_addr.s_addr = client->addr;
|
||||||
- tmp_sockaddr.sin_port = client->port;
|
- tmp_sockaddr.sin_port = client->port;
|
||||||
+ tmp_sockaddr.sin6_addr = client->addr;
|
+ tmp_sockaddr.my_sin_addr = client->addr;
|
||||||
+ tmp_sockaddr.sin6_port = client->port;
|
+ tmp_sockaddr.my_sin_port = client->port;
|
||||||
+ inet_ntop(AF_INET6, &tmp_sockaddr.sin6_addr, straddr, sizeof(straddr));
|
+ inet_ntop(my_af_inet, &tmp_sockaddr.my_sin_addr, straddr, sizeof(straddr));
|
||||||
lprintf(LOG_WARNING, "maximum number of %d clients reached, kicking out %s:%d\n",
|
lprintf(LOG_WARNING, "maximum number of %d clients reached, kicking out %s:%d\n",
|
||||||
- MAX_NR_CLIENTS, inet_ntoa(tmp_sockaddr.sin_addr), tmp_sockaddr.sin_port);
|
- MAX_NR_CLIENTS, inet_ntoa(tmp_sockaddr.sin_addr), tmp_sockaddr.sin_port);
|
||||||
+ MAX_NR_CLIENTS, straddr, tmp_sockaddr.sin6_port);
|
+ MAX_NR_CLIENTS, straddr, tmp_sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
} else {
|
} else {
|
||||||
client = malloc(sizeof (client_t));
|
client = malloc(sizeof (client_t));
|
||||||
@@ -183,35 +188,38 @@
|
@@ -183,35 +187,38 @@ static void handle_tcp_connect(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now fill out the client control structure values */
|
/* Now fill out the client control structure values */
|
||||||
+ inet_ntop(AF_INET6, &sockaddr.sin6_addr, straddr, sizeof(straddr));
|
+ inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
|
||||||
lprintf(LOG_DEBUG, "connected TCP client %s:%d\n",
|
lprintf(LOG_DEBUG, "connected TCP client %s:%d\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
client->timestamp = time(NULL);
|
client->timestamp = time(NULL);
|
||||||
client->sockfd = rv;
|
client->sockfd = rv;
|
||||||
- client->addr = sockaddr.sin_addr.s_addr;
|
- client->addr = sockaddr.sin_addr.s_addr;
|
||||||
- client->port = sockaddr.sin_port;
|
- client->port = sockaddr.sin_port;
|
||||||
+ client->addr = sockaddr.sin6_addr;
|
+ client->addr = sockaddr.my_sin_addr;
|
||||||
+ client->port = sockaddr.sin6_port;
|
+ client->port = sockaddr.my_sin_port;
|
||||||
client->size = 0;
|
client->size = 0;
|
||||||
client->outgoing = 0;
|
client->outgoing = 0;
|
||||||
}
|
}
|
||||||
@ -109,21 +118,21 @@
|
|||||||
static void handle_tcp_client_write(client_t *client)
|
static void handle_tcp_client_write(client_t *client)
|
||||||
{
|
{
|
||||||
- struct sockaddr_in sockaddr;
|
- struct sockaddr_in sockaddr;
|
||||||
+ struct sockaddr_in6 sockaddr;
|
+ struct my_sockaddr_t sockaddr;
|
||||||
int rv;
|
int rv;
|
||||||
+ char straddr[INET6_ADDRSTRLEN];
|
+ char straddr[my_inet_addrstrlen];
|
||||||
|
|
||||||
/* Send the packet atomically and close socket if that did not work */
|
/* Send the packet atomically and close socket if that did not work */
|
||||||
- sockaddr.sin_addr.s_addr = client->addr;
|
- sockaddr.sin_addr.s_addr = client->addr;
|
||||||
- sockaddr.sin_port = client->port;
|
- sockaddr.sin_port = client->port;
|
||||||
+ sockaddr.sin6_addr = client->addr;
|
+ sockaddr.my_sin_addr = client->addr;
|
||||||
+ sockaddr.sin6_port = client->port;
|
+ sockaddr.my_sin_port = client->port;
|
||||||
rv = send(client->sockfd, client->packet, client->size, 0);
|
rv = send(client->sockfd, client->packet, client->size, 0);
|
||||||
+ inet_ntop(AF_INET6, &sockaddr.sin6_addr, straddr, sizeof(straddr));
|
+ inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
@ -132,81 +141,81 @@
|
|||||||
- "only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
- "only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
||||||
- sockaddr.sin_port, rv, (int) client->size);
|
- sockaddr.sin_port, rv, (int) client->size);
|
||||||
+ "only %d of %d bytes written\n", straddr,
|
+ "only %d of %d bytes written\n", straddr,
|
||||||
+ sockaddr.sin6_port, rv, (int) client->size);
|
+ sockaddr.my_sin_port, rv, (int) client->size);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
@@ -227,23 +235,25 @@
|
@@ -227,23 +234,25 @@ static void handle_tcp_client_write(clie
|
||||||
|
|
||||||
static void handle_tcp_client_read(client_t *client)
|
static void handle_tcp_client_read(client_t *client)
|
||||||
{
|
{
|
||||||
- struct sockaddr_in sockaddr;
|
- struct sockaddr_in sockaddr;
|
||||||
+ struct sockaddr_in6 sockaddr;
|
+ struct my_sockaddr_t sockaddr;
|
||||||
int rv;
|
int rv;
|
||||||
+ char straddr[INET6_ADDRSTRLEN];
|
+ char straddr[my_inet_addrstrlen];
|
||||||
|
|
||||||
/* Read from the socket what arrived and put it into the buffer */
|
/* Read from the socket what arrived and put it into the buffer */
|
||||||
- sockaddr.sin_addr.s_addr = client->addr;
|
- sockaddr.sin_addr.s_addr = client->addr;
|
||||||
- sockaddr.sin_port = client->port;
|
- sockaddr.sin_port = client->port;
|
||||||
+ sockaddr.sin6_addr = client->addr;
|
+ sockaddr.my_sin_addr = client->addr;
|
||||||
+ sockaddr.sin6_port = client->port;
|
+ sockaddr.my_sin_port = client->port;
|
||||||
rv = read(client->sockfd, client->packet + client->size,
|
rv = read(client->sockfd, client->packet + client->size,
|
||||||
sizeof (client->packet) - client->size);
|
sizeof (client->packet) - client->size);
|
||||||
+ inet_ntop(AF_INET6, &sockaddr.sin6_addr, straddr, sizeof(straddr));
|
+ inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
lprintf(LOG_WARNING, "could not read packet from TCP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not read packet from TCP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
} else if (rv == 0) {
|
} else if (rv == 0) {
|
||||||
lprintf(LOG_DEBUG, "disconnected TCP client %s:%d\n",
|
lprintf(LOG_DEBUG, "disconnected TCP client %s:%d\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
@@ -255,7 +265,7 @@
|
@@ -255,7 +264,7 @@ static void handle_tcp_client_read(clien
|
||||||
rv = snmp_packet_complete(client);
|
rv = snmp_packet_complete(client);
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
@@ -270,13 +280,13 @@
|
@@ -270,13 +279,13 @@ static void handle_tcp_client_read(clien
|
||||||
/* Call the protocol handler which will prepare the response packet */
|
/* Call the protocol handler which will prepare the response packet */
|
||||||
if (snmp(client) == -1) {
|
if (snmp(client) == -1) {
|
||||||
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: %m\n",
|
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: %m\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
} else if (client->size == 0) {
|
} else if (client->size == 0) {
|
||||||
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: ignored\n",
|
lprintf(LOG_WARNING, "could not handle packet from TCP client %s:%d: ignored\n",
|
||||||
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
- inet_ntoa(sockaddr.sin_addr), sockaddr.sin_port);
|
||||||
+ straddr, sockaddr.sin6_port);
|
+ straddr, sockaddr.my_sin_port);
|
||||||
close(client->sockfd);
|
close(client->sockfd);
|
||||||
client->sockfd = -1;
|
client->sockfd = -1;
|
||||||
return;
|
return;
|
||||||
@@ -313,7 +323,7 @@
|
@@ -313,7 +322,7 @@ int main(int argc, char *argv[])
|
||||||
int option_index = 1;
|
int option_index = 1;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
- struct sockaddr_in sockaddr;
|
- struct sockaddr_in sockaddr;
|
||||||
+ struct sockaddr_in6 sockaddr;
|
+ struct my_sockaddr_t sockaddr;
|
||||||
socklen_t socklen;
|
socklen_t socklen;
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
@@ -399,14 +409,14 @@
|
@@ -399,14 +408,14 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Open the server's UDP port and prepare it for listening */
|
/* Open the server's UDP port and prepare it for listening */
|
||||||
- g_udp_sockfd = socket(PF_INET, SOCK_DGRAM, 0);
|
- g_udp_sockfd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
+ g_udp_sockfd = socket(PF_INET6, SOCK_DGRAM, 0);
|
+ g_udp_sockfd = socket(my_pf_inet, SOCK_DGRAM, 0);
|
||||||
if (g_udp_sockfd == -1) {
|
if (g_udp_sockfd == -1) {
|
||||||
lprintf(LOG_ERR, "could not create UDP socket: %m\n");
|
lprintf(LOG_ERR, "could not create UDP socket: %m\n");
|
||||||
exit(EXIT_SYSCALL);
|
exit(EXIT_SYSCALL);
|
||||||
@ -214,54 +223,92 @@
|
|||||||
- sockaddr.sin_family = AF_INET;
|
- sockaddr.sin_family = AF_INET;
|
||||||
- sockaddr.sin_port = htons(g_udp_port);
|
- sockaddr.sin_port = htons(g_udp_port);
|
||||||
- sockaddr.sin_addr.s_addr = INADDR_ANY;
|
- sockaddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
+ sockaddr.sin6_family = AF_INET6;
|
+ sockaddr.my_sin_family = my_af_inet;
|
||||||
+ sockaddr.sin6_port = htons(g_udp_port);
|
+ sockaddr.my_sin_port = htons(g_udp_port);
|
||||||
+ sockaddr.sin6_addr = in6addr_any;
|
+ sockaddr.my_sin_addr = my_inaddr_any;
|
||||||
socklen = sizeof (sockaddr);
|
socklen = sizeof (sockaddr);
|
||||||
if (bind(g_udp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
|
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);
|
lprintf(LOG_ERR, "could not bind UDP socket to port %d: %m\n", g_udp_port);
|
||||||
@@ -414,7 +424,7 @@
|
@@ -414,7 +423,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the server's TCP port and prepare it for listening */
|
/* Open the server's TCP port and prepare it for listening */
|
||||||
- g_tcp_sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
- g_tcp_sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
+ g_tcp_sockfd = socket(PF_INET6, SOCK_STREAM, 0);
|
+ g_tcp_sockfd = socket(my_pf_inet, SOCK_STREAM, 0);
|
||||||
if (g_tcp_sockfd == -1) {
|
if (g_tcp_sockfd == -1) {
|
||||||
lprintf(LOG_ERR, "could not create TCP socket: %m\n");
|
lprintf(LOG_ERR, "could not create TCP socket: %m\n");
|
||||||
exit(EXIT_SYSCALL);
|
exit(EXIT_SYSCALL);
|
||||||
@@ -424,9 +434,9 @@
|
@@ -424,9 +433,9 @@ int main(int argc, char *argv[])
|
||||||
lprintf(LOG_WARNING, "could not set SO_REUSEADDR on TCP socket: %m\n");
|
lprintf(LOG_WARNING, "could not set SO_REUSEADDR on TCP socket: %m\n");
|
||||||
exit(EXIT_SYSCALL);
|
exit(EXIT_SYSCALL);
|
||||||
}
|
}
|
||||||
- sockaddr.sin_family = AF_INET;
|
- sockaddr.sin_family = AF_INET;
|
||||||
- sockaddr.sin_port = htons(g_tcp_port);
|
- sockaddr.sin_port = htons(g_tcp_port);
|
||||||
- sockaddr.sin_addr.s_addr = INADDR_ANY;
|
- sockaddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
+ sockaddr.sin6_family = AF_INET6;
|
+ sockaddr.my_sin_family = my_af_inet;
|
||||||
+ sockaddr.sin6_port = htons(g_tcp_port);
|
+ sockaddr.my_sin_port = htons(g_tcp_port);
|
||||||
+ sockaddr.sin6_addr = in6addr_any;
|
+ sockaddr.my_sin_addr = my_inaddr_any;
|
||||||
socklen = sizeof (sockaddr);
|
socklen = sizeof (sockaddr);
|
||||||
if (bind(g_tcp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
|
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);
|
lprintf(LOG_ERR, "could not bind TCP socket to port %d: %m\n", g_tcp_port);
|
||||||
--- a/mini_snmpd.h
|
--- a/mini_snmpd.h
|
||||||
+++ b/mini_snmpd.h
|
+++ b/mini_snmpd.h
|
||||||
@@ -129,7 +129,7 @@
|
@@ -120,6 +120,27 @@
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+#ifdef IPV6
|
||||||
|
+#define my_sockaddr_t sockaddr_in6
|
||||||
|
+#define my_sin_addr sin6_addr
|
||||||
|
+#define my_sin_port sin6_port
|
||||||
|
+#define my_sin_family sin6_family
|
||||||
|
+#define my_af_inet AF_INET6
|
||||||
|
+#define my_pf_inet PF_INET6
|
||||||
|
+#define my_in_addr_t in6_addr
|
||||||
|
+#define my_inaddr_any in6addr_any
|
||||||
|
+#define my_inet_addrstrlen INET6_ADDRSTRLEN
|
||||||
|
+#else
|
||||||
|
+#define my_sockaddr_t sockaddr_in
|
||||||
|
+#define my_sin_addr sin_addr
|
||||||
|
+#define my_sin_port sin_port
|
||||||
|
+#define my_sin_family sin_family
|
||||||
|
+#define my_af_inet AF_INET
|
||||||
|
+#define my_pf_inet PF_INET
|
||||||
|
+#define my_in_addr_t in_addr
|
||||||
|
+#define my_inaddr_any inaddr_any
|
||||||
|
+#define my_inet_addrstrlen INET_ADDRSTRLEN
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
@@ -129,7 +150,7 @@
|
||||||
typedef struct client_s {
|
typedef struct client_s {
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
- in_addr_t addr;
|
- in_addr_t addr;
|
||||||
+ struct in6_addr addr;
|
+ struct my_in_addr_t addr;
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
unsigned char packet[MAX_PACKET_SIZE];
|
unsigned char packet[MAX_PACKET_SIZE];
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@@ -236,6 +257,9 @@ extern char *g_description;
|
||||||
|
extern char *g_vendor;
|
||||||
|
extern char *g_location;
|
||||||
|
extern char *g_contact;
|
||||||
|
+#ifndef IPV6
|
||||||
|
+extern const struct in_addr inaddr_any;
|
||||||
|
+#endif
|
||||||
|
extern char *g_disk_list[MAX_NR_DISKS];
|
||||||
|
extern int g_disk_list_length;
|
||||||
|
extern char *g_interface_list[MAX_NR_INTERFACES];
|
||||||
--- a/utils.c
|
--- a/utils.c
|
||||||
+++ b/utils.c
|
+++ b/utils.c
|
||||||
@@ -91,12 +91,13 @@
|
@@ -91,12 +91,13 @@ void read_values(const char *buffer, con
|
||||||
|
|
||||||
void dump_packet(const client_t *client)
|
void dump_packet(const client_t *client)
|
||||||
{
|
{
|
||||||
- struct in_addr client_addr;
|
- struct in_addr client_addr;
|
||||||
+ struct in6_addr client_addr;
|
+ struct my_in_addr_t client_addr;
|
||||||
+ char straddr[INET6_ADDRSTRLEN];
|
+ char straddr[my_inet_addrstrlen];
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
@ -271,11 +318,11 @@
|
|||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < client->size; i++) {
|
for (i = 0; i < client->size; i++) {
|
||||||
len += snprintf(buffer + len, sizeof (buffer) - len,
|
len += snprintf(buffer + len, sizeof (buffer) - len,
|
||||||
@@ -105,9 +106,10 @@
|
@@ -105,9 +106,10 @@ void dump_packet(const client_t *client)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+ inet_ntop(AF_INET6, &client_addr, straddr, sizeof(straddr));
|
+ inet_ntop(my_af_inet, &client_addr, straddr, sizeof(straddr));
|
||||||
lprintf(LOG_DEBUG, "%s %u bytes %s %s:%d (%s)\n",
|
lprintf(LOG_DEBUG, "%s %u bytes %s %s:%d (%s)\n",
|
||||||
client->outgoing ? "transmitted" : "received", (int) client->size,
|
client->outgoing ? "transmitted" : "received", (int) client->size,
|
||||||
- client->outgoing ? "to" : "from", inet_ntoa(client_addr),
|
- client->outgoing ? "to" : "from", inet_ntoa(client_addr),
|
@ -1,48 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2009 OpenWrt.orgv
|
|
||||||
#
|
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
|
||||||
# See /LICENSE for more information.
|
|
||||||
#
|
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
|
||||||
|
|
||||||
PKG_NAME:=mini_snmpd
|
|
||||||
PKG_VERSION:=1.0
|
|
||||||
PKG_RELEASE:=5
|
|
||||||
|
|
||||||
PKG_SOURCE:=mini_snmpd.tar.gz
|
|
||||||
PKG_SOURCE_URL:=http://members.aon.at/linuxfreak/linux/
|
|
||||||
PKG_MD5SUM:=13f2202ff01ff6b6463989f34f453063
|
|
||||||
|
|
||||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
|
||||||
|
|
||||||
define Package/mini-snmpd
|
|
||||||
SECTION:=net
|
|
||||||
CATEGORY:=Network
|
|
||||||
TITLE:=SNMP server for embedded systems
|
|
||||||
URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
|
|
||||||
endef
|
|
||||||
|
|
||||||
|
|
||||||
define Build/Compile
|
|
||||||
$(MAKE) -C $(PKG_BUILD_DIR) \
|
|
||||||
CC="$(TARGET_CC)" \
|
|
||||||
OFLAGS="$(TARGET_CFLAGS) -DSYSLOG" \
|
|
||||||
STRIP="/bin/true" \
|
|
||||||
INSTALL_ROOT="$(PKG_INSTALL_DIR)" \
|
|
||||||
mini_snmpd install
|
|
||||||
endef
|
|
||||||
|
|
||||||
define Package/mini-snmpd/install
|
|
||||||
$(INSTALL_DIR) $(1)/usr/bin
|
|
||||||
$(CP) $(PKG_INSTALL_DIR)/sbin/mini_snmpd $(1)/usr/bin/
|
|
||||||
$(INSTALL_DIR) $(1)/etc/config
|
|
||||||
$(INSTALL_CONF) ./files/mini_snmpd.config $(1)/etc/config/mini_snmpd
|
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
|
||||||
$(INSTALL_BIN) ./files/mini_snmpd.init $(1)/etc/init.d/mini_snmpd
|
|
||||||
endef
|
|
||||||
|
|
||||||
$(eval $(call BuildPackage,mini-snmpd))
|
|
@ -1,7 +0,0 @@
|
|||||||
config mini_snmpd
|
|
||||||
option enabled 1
|
|
||||||
option community public
|
|
||||||
option location ''
|
|
||||||
option contact ''
|
|
||||||
option disks '/tmp,/jffs'
|
|
||||||
option interfaces 'lo,br-lan,eth0.1,eth1' # Max 4
|
|
@ -1,38 +0,0 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
|
||||||
# Copyright (C) 2009 OpenWrt.org
|
|
||||||
|
|
||||||
NAME=mini_snmpd
|
|
||||||
PROG=/usr/bin/$NAME
|
|
||||||
START=50
|
|
||||||
|
|
||||||
append_string() {
|
|
||||||
local section="$1"
|
|
||||||
local option="$2"
|
|
||||||
local value="$3"
|
|
||||||
local _val
|
|
||||||
config_get _val "$section" "$option"
|
|
||||||
[ -n "$_val" ] && append args "$3 $_val"
|
|
||||||
}
|
|
||||||
|
|
||||||
mini_snmpd_config() {
|
|
||||||
local cfg="$1"
|
|
||||||
args=""
|
|
||||||
|
|
||||||
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 enabled "$cfg" "enabled" '1'c
|
|
||||||
[ "$enabled" -gt 0 ] && $PROG $args &
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
config_load mini_snmpd
|
|
||||||
config_foreach mini_snmpd_config mini_snmpd
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
killall mini_snmpd
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
--- a/Makefile
|
|
||||||
+++ b/Makefile
|
|
||||||
@@ -30,8 +30,9 @@ HEADERS = mini_snmpd.h
|
|
||||||
SOURCES = mini_snmpd.c protocol.c mib.c globals.c utils.c linux.c freebsd.c
|
|
||||||
VERSION = 1.0
|
|
||||||
VENDOR = .1.3.6.1.4.1
|
|
||||||
+OFLAGS = -O2 -DDEBUG
|
|
||||||
CFLAGS = -Wall -Werror -DVERSION="\"$(VERSION)\"" -DVENDOR="\"$(VENDOR)\"" \
|
|
||||||
- -O2 -DDEBUG -D__LINUX__ -D__DEMO__
|
|
||||||
+ $(OFLAGS) -D__LINUX__ -D__DEMO__
|
|
||||||
TARGET = mini_snmpd
|
|
||||||
MAN = mini_snmpd.8
|
|
||||||
DOC = CHANGELOG COPYING README TODO
|
|
@ -1,31 +0,0 @@
|
|||||||
--- a/mini_snmpd.c
|
|
||||||
+++ b/mini_snmpd.c
|
|
||||||
@@ -134,7 +134,7 @@
|
|
||||||
} else if (rv != g_udp_client.size) {
|
|
||||||
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: "
|
|
||||||
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
|
||||||
- sockaddr.sin_port, rv, g_udp_client.size);
|
|
||||||
+ sockaddr.sin_port, rv, (int) g_udp_client.size);
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
|
||||||
dump_packet(&g_udp_client);
|
|
||||||
@@ -211,7 +211,7 @@
|
|
||||||
} else if (rv != client->size) {
|
|
||||||
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: "
|
|
||||||
"only %d of %d bytes written\n", inet_ntoa(sockaddr.sin_addr),
|
|
||||||
- sockaddr.sin_port, rv, client->size);
|
|
||||||
+ sockaddr.sin_port, rv, (int) client->size);
|
|
||||||
close(client->sockfd);
|
|
||||||
client->sockfd = -1;
|
|
||||||
return;
|
|
||||||
--- a/utils.c
|
|
||||||
+++ b/utils.c
|
|
||||||
@@ -106,7 +106,7 @@
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lprintf(LOG_DEBUG, "%s %u bytes %s %s:%d (%s)\n",
|
|
||||||
- client->outgoing ? "transmitted" : "received", client->size,
|
|
||||||
+ client->outgoing ? "transmitted" : "received", (int) client->size,
|
|
||||||
client->outgoing ? "to" : "from", inet_ntoa(client_addr),
|
|
||||||
ntohs(client->port), buffer);
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
--- a/mib.c
|
|
||||||
+++ b/mib.c
|
|
||||||
@@ -120,6 +120,9 @@ static int encode_snmp_element_oid(value
|
|
||||||
int length;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
+ if (oid_value == NULL) {
|
|
||||||
+ return -1;
|
|
||||||
+ }
|
|
||||||
buffer = value->data.buffer;
|
|
||||||
length = 1;
|
|
||||||
for (i = 2; i < oid_value->subid_list_length; i++) {
|
|
||||||
@@ -293,6 +296,8 @@ static int mib_build_entry(const oid_t *
|
|
||||||
value->data.encoded_length = 0;
|
|
||||||
value->data.buffer = malloc(value->data.max_length);
|
|
||||||
if (encode_snmp_element_oid(value, oid_aton((const char *)default_value)) == -1) {
|
|
||||||
+ lprintf(LOG_ERR, "could not create MIB entry '%s.%d.%d': invalid oid '%s'\n",
|
|
||||||
+ oid_ntoa(prefix), column, row, (char *)default_value);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
Loading…
x
Reference in New Issue
Block a user