vm: fix a null dereference on out-of-memory
[minix.git] / lib / liblwip / include / lwip / api_msg.h
blobccb1015f286279a3d64084e52c97ab5867305613
1 /*
2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 #ifndef __LWIP_API_MSG_H__
33 #define __LWIP_API_MSG_H__
35 #include "lwip/opt.h"
37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
39 #include <stddef.h> /* for size_t */
41 #include "lwip/ip_addr.h"
42 #include "lwip/err.h"
43 #include "lwip/sys.h"
44 #include "lwip/igmp.h"
45 #include "lwip/api.h"
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 #define NETCONN_SHUT_RD 1
52 #define NETCONN_SHUT_WR 2
53 #define NETCONN_SHUT_RDWR 3
55 /* IP addresses and port numbers are expected to be in
56 * the same byte order as in the corresponding pcb.
58 /** This struct includes everything that is necessary to execute a function
59 for a netconn in another thread context (mainly used to process netconns
60 in the tcpip_thread context to be thread safe). */
61 struct api_msg_msg {
62 /** The netconn which to process - always needed: it includes the semaphore
63 which is used to block the application thread until the function finished. */
64 struct netconn *conn;
65 /** The return value of the function executed in tcpip_thread. */
66 err_t err;
67 /** Depending on the executed function, one of these union members is used */
68 union {
69 /** used for do_send */
70 struct netbuf *b;
71 /** used for do_newconn */
72 struct {
73 u8_t proto;
74 } n;
75 /** used for do_bind and do_connect */
76 struct {
77 ip_addr_t *ipaddr;
78 u16_t port;
79 } bc;
80 /** used for do_getaddr */
81 struct {
82 ip_addr_t *ipaddr;
83 u16_t *port;
84 u8_t local;
85 } ad;
86 /** used for do_write */
87 struct {
88 const void *dataptr;
89 size_t len;
90 u8_t apiflags;
91 } w;
92 /** used for do_recv */
93 struct {
94 u32_t len;
95 } r;
96 /** used for do_close (/shutdown) */
97 struct {
98 u8_t shut;
99 } sd;
100 #if LWIP_IGMP
101 /** used for do_join_leave_group */
102 struct {
103 ip_addr_t *multiaddr;
104 ip_addr_t *netif_addr;
105 enum netconn_igmp join_or_leave;
106 } jl;
107 #endif /* LWIP_IGMP */
108 #if TCP_LISTEN_BACKLOG
109 struct {
110 u8_t backlog;
111 } lb;
112 #endif /* TCP_LISTEN_BACKLOG */
113 } msg;
116 /** This struct contains a function to execute in another thread context and
117 a struct api_msg_msg that serves as an argument for this function.
118 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
119 struct api_msg {
120 /** function to execute in tcpip_thread context */
121 void (* function)(struct api_msg_msg *msg);
122 /** arguments for this function */
123 struct api_msg_msg msg;
126 #if LWIP_DNS
127 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
128 it has its own struct (to avoid struct api_msg getting bigger than necessary).
129 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
130 (see netconn_gethostbyname). */
131 struct dns_api_msg {
132 /** Hostname to query or dotted IP address string */
133 const char *name;
134 /** Rhe resolved address is stored here */
135 ip_addr_t *addr;
136 /** This semaphore is posted when the name is resolved, the application thread
137 should wait on it. */
138 sys_sem_t *sem;
139 /** Errors are given back here */
140 err_t *err;
142 #endif /* LWIP_DNS */
144 void do_newconn ( struct api_msg_msg *msg);
145 void do_delconn ( struct api_msg_msg *msg);
146 void do_bind ( struct api_msg_msg *msg);
147 void do_connect ( struct api_msg_msg *msg);
148 void do_disconnect ( struct api_msg_msg *msg);
149 void do_listen ( struct api_msg_msg *msg);
150 void do_send ( struct api_msg_msg *msg);
151 void do_recv ( struct api_msg_msg *msg);
152 void do_write ( struct api_msg_msg *msg);
153 void do_getaddr ( struct api_msg_msg *msg);
154 void do_close ( struct api_msg_msg *msg);
155 void do_shutdown ( struct api_msg_msg *msg);
156 #if LWIP_IGMP
157 void do_join_leave_group( struct api_msg_msg *msg);
158 #endif /* LWIP_IGMP */
160 #if LWIP_DNS
161 void do_gethostbyname(void *arg);
162 #endif /* LWIP_DNS */
164 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
165 void netconn_free(struct netconn *conn);
167 #ifdef __cplusplus
169 #endif
171 #endif /* LWIP_NETCONN */
173 #endif /* __LWIP_API_MSG_H__ */