ReactOS 0.4.16-dev-1170-ge326b06
snmp_netconn.c
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * Author: Dirk Ziegelmeier <dziegel@gmx.de>
33 */
34
35#include "lwip/apps/snmp_opts.h"
36
37#if LWIP_SNMP && SNMP_USE_NETCONN
38
39#include <string.h>
40#include "lwip/api.h"
41#include "lwip/ip.h"
42#include "lwip/udp.h"
43#include "snmp_msg.h"
44#include "lwip/sys.h"
45#include "lwip/prot/iana.h"
46
48static void
49snmp_netconn_thread(void *arg)
50{
51 struct netconn *conn;
52 struct netbuf *buf;
53 err_t err;
55
56 /* Bind to SNMP port with default IP address */
57#if LWIP_IPV6
58 conn = netconn_new(NETCONN_UDP_IPV6);
59 netconn_bind(conn, IP6_ADDR_ANY, LWIP_IANA_PORT_SNMP);
60#else /* LWIP_IPV6 */
61 conn = netconn_new(NETCONN_UDP);
62 netconn_bind(conn, IP4_ADDR_ANY, LWIP_IANA_PORT_SNMP);
63#endif /* LWIP_IPV6 */
64 LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;);
65
66 snmp_traps_handle = conn;
67
68 do {
69 err = netconn_recv(conn, &buf);
70
71 if (err == ERR_OK) {
72 snmp_receive(conn, buf->p, &buf->addr, buf->port);
73 }
74
75 if (buf != NULL) {
76 netbuf_delete(buf);
77 }
78 } while (1);
79}
80
82snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
83{
85 struct netbuf buf;
86
87 memset(&buf, 0, sizeof(buf));
88 buf.p = p;
89 result = netconn_sendto((struct netconn *)handle, &buf, dst, port);
90
91 return result;
92}
93
94u8_t
95snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
96{
97 struct netconn *conn = (struct netconn *)handle;
98 struct netif *dst_if;
99 const ip_addr_t *dst_ip;
100
101 LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */
102
103 ip_route_get_local_ip(&conn->pcb.udp->local_ip, dst, dst_if, dst_ip);
104
105 if ((dst_if != NULL) && (dst_ip != NULL)) {
106 ip_addr_copy(*result, *dst_ip);
107 return 1;
108 } else {
109 return 0;
110 }
111}
112
116void
117snmp_init(void)
118{
119 sys_thread_new("snmp_netconn", snmp_netconn_thread, NULL, SNMP_STACK_SIZE, SNMP_THREAD_PRIO);
120}
121
122#endif /* LWIP_SNMP && SNMP_USE_NETCONN */
#define NULL
Definition: types.h:112
USHORT port
Definition: uri.c:228
BOOL netconn_recv(struct netconn *conn, void *buf, size_t len, int flags, int *recvd)
Definition: net.c:539
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:130
#define ip_route_get_local_ip(src, dest, netif, ipaddr)
Definition: ip.h:330
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum dst
Definition: glext.h:6340
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
uint8_t u8_t
Definition: arch.h:125
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
uint16_t u16_t
Definition: arch.h:127
@ LWIP_IANA_PORT_SNMP
Definition: iana.h:78
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:275
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:360
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
Definition: types.h:144
Definition: netif.h:269
Definition: pbuf.h:186