Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
lwip_snmp_netconn.c
00001 /** 00002 * @file 00003 * SNMP netconn frontend. 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * Author: Dirk Ziegelmeier <dziegel@gmx.de> 00033 */ 00034 00035 #include "lwip/apps/snmp_opts.h" 00036 00037 #if LWIP_SNMP && SNMP_USE_NETCONN 00038 00039 #include <string.h> 00040 #include "lwip/api.h" 00041 #include "lwip/ip.h" 00042 #include "lwip/udp.h" 00043 #include "snmp_msg.h" 00044 #include "lwip/sys.h" 00045 #include "lwip/prot/iana.h" 00046 00047 /** SNMP netconn API worker thread */ 00048 static void 00049 snmp_netconn_thread(void *arg) 00050 { 00051 struct netconn *conn; 00052 struct netbuf *buf; 00053 err_t err; 00054 LWIP_UNUSED_ARG(arg); 00055 00056 /* Bind to SNMP port with default IP address */ 00057 #if LWIP_IPV6 00058 conn = netconn_new(NETCONN_UDP_IPV6); 00059 netconn_bind(conn, IP6_ADDR_ANY, LWIP_IANA_PORT_SNMP); 00060 #else /* LWIP_IPV6 */ 00061 conn = netconn_new(NETCONN_UDP); 00062 netconn_bind(conn, IP4_ADDR_ANY, LWIP_IANA_PORT_SNMP); 00063 #endif /* LWIP_IPV6 */ 00064 LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;); 00065 00066 snmp_traps_handle = conn; 00067 00068 do { 00069 err = netconn_recv(conn, &buf); 00070 00071 if (err == ERR_OK) { 00072 snmp_receive(conn, buf->p, &buf->addr, buf->port); 00073 } 00074 00075 if (buf != NULL) { 00076 netbuf_delete(buf); 00077 } 00078 } while (1); 00079 } 00080 00081 err_t 00082 snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port) 00083 { 00084 err_t result; 00085 struct netbuf buf; 00086 00087 memset(&buf, 0, sizeof(buf)); 00088 buf.p = p; 00089 result = netconn_sendto((struct netconn *)handle, &buf, dst, port); 00090 00091 return result; 00092 } 00093 00094 u8_t 00095 snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result) 00096 { 00097 struct netconn *conn = (struct netconn *)handle; 00098 struct netif *dst_if; 00099 const ip_addr_t *dst_ip; 00100 00101 LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */ 00102 00103 ip_route_get_local_ip(&conn->pcb.udp->local_ip, dst, dst_if, dst_ip); 00104 00105 if ((dst_if != NULL) && (dst_ip != NULL)) { 00106 ip_addr_copy(*result, *dst_ip); 00107 return 1; 00108 } else { 00109 return 0; 00110 } 00111 } 00112 00113 /** 00114 * Starts SNMP Agent. 00115 */ 00116 void 00117 snmp_init(void) 00118 { 00119 LWIP_ASSERT_CORE_LOCKED(); 00120 sys_thread_new("snmp_netconn", snmp_netconn_thread, NULL, SNMP_STACK_SIZE, SNMP_THREAD_PRIO); 00121 } 00122 00123 #endif /* LWIP_SNMP && SNMP_USE_NETCONN */
Generated on Tue Jul 12 2022 13:54:30 by
