ReactOS 0.4.16-dev-311-g9382aa2
api.h
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 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Adam Dunkels <adam@sics.se>
35 *
36 */
37#ifndef LWIP_HDR_API_H
38#define LWIP_HDR_API_H
39
40#include "lwip/opt.h"
41
42#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
43/* Note: Netconn API is always available when sockets are enabled -
44 * sockets are implemented on top of them */
45
46#include "lwip/arch.h"
47#include "lwip/netbuf.h"
48#include "lwip/sys.h"
49#include "lwip/ip_addr.h"
50#include "lwip/err.h"
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56/* Throughout this file, IP addresses and port numbers are expected to be in
57 * the same byte order as in the corresponding pcb.
58 */
59
60/* Flags for netconn_write (u8_t) */
61#define NETCONN_NOFLAG 0x00
62#define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
63#define NETCONN_COPY 0x01
64#define NETCONN_MORE 0x02
65#define NETCONN_DONTBLOCK 0x04
66#define NETCONN_NOAUTORCVD 0x08 /* prevent netconn_recv_data_tcp() from updating the tcp window - must be done manually via netconn_tcp_recvd() */
67#define NETCONN_NOFIN 0x10 /* upper layer already received data, leave FIN in queue until called again */
68
69/* Flags for struct netconn.flags (u8_t) */
71#define NETCONN_FLAG_MBOXCLOSED 0x01
73#define NETCONN_FLAG_NON_BLOCKING 0x02
75#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
76#if LWIP_NETCONN_FULLDUPLEX
78#define NETCONN_FLAG_MBOXINVALID 0x08
79#endif /* LWIP_NETCONN_FULLDUPLEX */
82#define NETCONN_FLAG_CHECK_WRITESPACE 0x10
83#if LWIP_IPV6
87#define NETCONN_FLAG_IPV6_V6ONLY 0x20
88#endif /* LWIP_IPV6 */
89#if LWIP_NETBUF_RECVINFO
91#define NETCONN_FLAG_PKTINFO 0x40
92#endif /* LWIP_NETBUF_RECVINFO */
94#define NETCONN_FIN_RX_PENDING 0x80
95
96/* Helpers to process several netconn_types by the same code */
97#define NETCONNTYPE_GROUP(t) ((t)&0xF0)
98#define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0)
99#if LWIP_IPV6
100#define NETCONN_TYPE_IPV6 0x08
101#define NETCONNTYPE_ISIPV6(t) (((t)&NETCONN_TYPE_IPV6) != 0)
102#define NETCONNTYPE_ISUDPLITE(t) (((t)&0xF3) == NETCONN_UDPLITE)
103#define NETCONNTYPE_ISUDPNOCHKSUM(t) (((t)&0xF3) == NETCONN_UDPNOCHKSUM)
104#else /* LWIP_IPV6 */
105#define NETCONNTYPE_ISIPV6(t) (0)
106#define NETCONNTYPE_ISUDPLITE(t) ((t) == NETCONN_UDPLITE)
107#define NETCONNTYPE_ISUDPNOCHKSUM(t) ((t) == NETCONN_UDPNOCHKSUM)
108#endif /* LWIP_IPV6 */
109
113enum netconn_type {
114 NETCONN_INVALID = 0,
116 NETCONN_TCP = 0x10,
117#if LWIP_IPV6
119 NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 /* 0x18 */,
120#endif /* LWIP_IPV6 */
122 NETCONN_UDP = 0x20,
124 NETCONN_UDPLITE = 0x21,
126 NETCONN_UDPNOCHKSUM = 0x22,
127
128#if LWIP_IPV6
130 NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 /* 0x28 */,
132 NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 /* 0x29 */,
134 NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 /* 0x2a */,
135#endif /* LWIP_IPV6 */
136
138 NETCONN_RAW = 0x40
139#if LWIP_IPV6
141 , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */
142#endif /* LWIP_IPV6 */
143};
144
147enum netconn_state {
148 NETCONN_NONE,
149 NETCONN_WRITE,
150 NETCONN_LISTEN,
151 NETCONN_CONNECT,
152 NETCONN_CLOSE
153};
154
181enum netconn_evt {
182 NETCONN_EVT_RCVPLUS,
183 NETCONN_EVT_RCVMINUS,
184 NETCONN_EVT_SENDPLUS,
185 NETCONN_EVT_SENDMINUS,
186 NETCONN_EVT_ERROR
187};
188
189#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
191enum netconn_igmp {
192 NETCONN_JOIN,
193 NETCONN_LEAVE
194};
195#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
196
197#if LWIP_DNS
198/* Used for netconn_gethostbyname_addrtype(), these should match the DNS_ADDRTYPE defines in dns.h */
199#define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV4_IPV6
200#define NETCONN_DNS_IPV4 0
201#define NETCONN_DNS_IPV6 1
202#define NETCONN_DNS_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
203#define NETCONN_DNS_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
204#endif /* LWIP_DNS */
205
206/* forward-declare some structs to avoid to include their headers */
207struct ip_pcb;
208struct tcp_pcb;
209struct udp_pcb;
210struct raw_pcb;
211struct netconn;
212struct api_msg;
213
215typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
216
218struct netconn {
220 enum netconn_type type;
222 enum netconn_state state;
224 union {
225 struct ip_pcb *ip;
226 struct tcp_pcb *tcp;
227 struct udp_pcb *udp;
228 struct raw_pcb *raw;
229 } pcb;
231 err_t pending_err;
232#if !LWIP_NETCONN_SEM_PER_THREAD
234 sys_sem_t op_completed;
235#endif
238 sys_mbox_t recvmbox;
239#if LWIP_TCP
242 sys_mbox_t acceptmbox;
243#endif /* LWIP_TCP */
244#if LWIP_NETCONN_FULLDUPLEX
247 int mbox_threads_waiting;
248#endif
249 union {
250 int socket;
251 void *ptr;
252 } callback_arg;
253#if LWIP_SO_SNDTIMEO
256 s32_t send_timeout;
257#endif /* LWIP_SO_RCVTIMEO */
258#if LWIP_SO_RCVTIMEO
261 u32_t recv_timeout;
262#endif /* LWIP_SO_RCVTIMEO */
263#if LWIP_SO_RCVBUF
266 int recv_bufsize;
270 int recv_avail;
271#endif /* LWIP_SO_RCVBUF */
272#if LWIP_SO_LINGER
275#endif /* LWIP_SO_LINGER */
277 u8_t flags;
278#if LWIP_TCP
282 struct api_msg *current_msg;
283#endif /* LWIP_TCP */
285 netconn_callback callback;
286};
287
293struct netvector {
295 const void *ptr;
297 size_t len;
298};
299
301#define API_EVENT(c,e,l) if (c->callback) { \
302 (*c->callback)(c, e, l); \
303 }
304
305/* Network connection functions: */
306
310#define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
311#define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
312struct netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
313 netconn_callback callback);
314err_t netconn_prepare_delete(struct netconn *conn);
315err_t netconn_delete(struct netconn *conn);
317#define netconn_type(conn) (conn->type)
318
319err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
320 u16_t *port, u8_t local);
322#define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
324#define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
325
326err_t netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port);
327err_t netconn_bind_if(struct netconn *conn, u8_t if_idx);
328err_t netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port);
329err_t netconn_disconnect (struct netconn *conn);
330err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
332#define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
333err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
334err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
335err_t netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf);
336err_t netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags);
337err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
338err_t netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags);
339err_t netconn_tcp_recvd(struct netconn *conn, size_t len);
340err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
341 const ip_addr_t *addr, u16_t port);
342err_t netconn_send(struct netconn *conn, struct netbuf *buf);
343err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
344 u8_t apiflags, size_t *bytes_written);
345err_t netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u16_t vectorcnt,
346 u8_t apiflags, size_t *bytes_written);
348#define netconn_write(conn, dataptr, size, apiflags) \
349 netconn_write_partly(conn, dataptr, size, apiflags, NULL)
350err_t netconn_close(struct netconn *conn);
351err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
352
353#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
354err_t netconn_join_leave_group(struct netconn *conn, const ip_addr_t *multiaddr,
355 const ip_addr_t *netif_addr, enum netconn_igmp join_or_leave);
356err_t netconn_join_leave_group_netif(struct netconn *conn, const ip_addr_t *multiaddr,
357 u8_t if_idx, enum netconn_igmp join_or_leave);
358#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
359#if LWIP_DNS
360#if LWIP_IPV4 && LWIP_IPV6
361err_t netconn_gethostbyname_addrtype(const char *name, ip_addr_t *addr, u8_t dns_addrtype);
362#define netconn_gethostbyname(name, addr) netconn_gethostbyname_addrtype(name, addr, NETCONN_DNS_DEFAULT)
363#else /* LWIP_IPV4 && LWIP_IPV6 */
364err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
365#define netconn_gethostbyname_addrtype(name, addr, dns_addrtype) netconn_gethostbyname(name, addr)
366#endif /* LWIP_IPV4 && LWIP_IPV6 */
367#endif /* LWIP_DNS */
368
369err_t netconn_err(struct netconn *conn);
370#define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
371
372#define netconn_set_flags(conn, set_flags) do { (conn)->flags = (u8_t)((conn)->flags | (set_flags)); } while(0)
373#define netconn_clear_flags(conn, clr_flags) do { (conn)->flags = (u8_t)((conn)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
374#define netconn_is_flag_set(conn, flag) (((conn)->flags & (flag)) != 0)
375
376#define netconn_set_callback_arg(conn, arg) do { (conn)->callback_arg.ptr = (arg); } while(0)
377#define netconn_get_callback_arg(conn) ((conn)->callback_arg.ptr)
378
380#define netconn_set_nonblocking(conn, val) do { if(val) { \
381 netconn_set_flags(conn, NETCONN_FLAG_NON_BLOCKING); \
382} else { \
383 netconn_clear_flags(conn, NETCONN_FLAG_NON_BLOCKING); }} while(0)
385#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
386
387#if LWIP_IPV6
391#define netconn_set_ipv6only(conn, val) do { if(val) { \
392 netconn_set_flags(conn, NETCONN_FLAG_IPV6_V6ONLY); \
393} else { \
394 netconn_clear_flags(conn, NETCONN_FLAG_IPV6_V6ONLY); }} while(0)
398#define netconn_get_ipv6only(conn) (((conn)->flags & NETCONN_FLAG_IPV6_V6ONLY) != 0)
399#endif /* LWIP_IPV6 */
400
401#if LWIP_SO_SNDTIMEO
403#define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout))
405#define netconn_get_sendtimeout(conn) ((conn)->send_timeout)
406#endif /* LWIP_SO_SNDTIMEO */
407#if LWIP_SO_RCVTIMEO
409#define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout))
411#define netconn_get_recvtimeout(conn) ((conn)->recv_timeout)
412#endif /* LWIP_SO_RCVTIMEO */
413#if LWIP_SO_RCVBUF
415#define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize))
417#define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize)
418#endif /* LWIP_SO_RCVBUF*/
419
420#if LWIP_NETCONN_SEM_PER_THREAD
421void netconn_thread_init(void);
422void netconn_thread_cleanup(void);
423#else /* LWIP_NETCONN_SEM_PER_THREAD */
424#define netconn_thread_init()
425#define netconn_thread_cleanup()
426#endif /* LWIP_NETCONN_SEM_PER_THREAD */
427
428#ifdef __cplusplus
429}
430#endif
431
432#endif /* LWIP_NETCONN || LWIP_SOCKET */
433
434#endif /* LWIP_HDR_API_H */
static int state
Definition: maze.c:121
USHORT port
Definition: uri.c:228
void netconn_close(struct netconn *conn)
Definition: net.c:250
BOOL netconn_recv(struct netconn *conn, void *buf, size_t len, int flags, int *recvd)
Definition: net.c:539
BOOL netconn_send(struct netconn *conn, const void *msg, size_t len, int *sent)
Definition: net.c:424
#define local
Definition: zutil.h:30
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
int32_t s32_t
Definition: arch.h:130
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128
s8_t err_t
Definition: err.h:96
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
int const JOCTET * dataptr
Definition: jpeglib.h:1031
static PVOID ptr
Definition: dispmode.c:27
static IPrintDialogCallback callback
Definition: printdlg.c:326
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
Definition: ip.h:91
Definition: dhcpd.h:62
Definition: name.c:39
Definition: types.h:144
Definition: pbuf.h:186