ReactOS 0.4.16-dev-959-g2ec3a19
snmp_raw.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#include "lwip/ip_addr.h"
37
38#if LWIP_SNMP && SNMP_USE_RAW
39
40#include "lwip/udp.h"
41#include "lwip/ip.h"
42#include "lwip/prot/iana.h"
43#include "snmp_msg.h"
44
45/* lwIP UDP receive callback function */
46static void
47snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
48{
50
51 snmp_receive(pcb, p, addr, port);
52
53 pbuf_free(p);
54}
55
57snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
58{
59 return udp_sendto((struct udp_pcb *)handle, p, dst, port);
60}
61
62u8_t
63snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
64{
65 struct udp_pcb *udp_pcb = (struct udp_pcb *)handle;
66 struct netif *dst_if;
67 const ip_addr_t *dst_ip;
68
69 LWIP_UNUSED_ARG(udp_pcb); /* unused in case of IPV4 only configuration */
70
71 ip_route_get_local_ip(&udp_pcb->local_ip, dst, dst_if, dst_ip);
72
73 if ((dst_if != NULL) && (dst_ip != NULL)) {
74 ip_addr_copy(*result, *dst_ip);
75 return 1;
76 } else {
77 return 0;
78 }
79}
80
86void
87snmp_init(void)
88{
89 err_t err;
90
91 struct udp_pcb *snmp_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
92 LWIP_ERROR("snmp_raw: no PCB", (snmp_pcb != NULL), return;);
93
95
96 snmp_traps_handle = snmp_pcb;
97
98 udp_recv(snmp_pcb, snmp_recv, NULL);
99 err = udp_bind(snmp_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_SNMP);
100 LWIP_ERROR("snmp_raw: Unable to bind PCB", (err == ERR_OK), return;);
101}
102
103#endif /* LWIP_SNMP && SNMP_USE_RAW */
#define NULL
Definition: types.h:112
USHORT port
Definition: uri.c:228
#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 GLenum dst
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
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
#define IP_ANY_TYPE
Definition: ip_addr.h:461
@ IPADDR_TYPE_ANY
Definition: ip_addr.h:60
#define LWIP_ASSERT_CORE_LOCKED()
Definition: opt.h:227
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:360
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
#define err(...)
Definition: netif.h:269
Definition: pbuf.h:186