📄 uip.h
字号:
/*
* Copyright (c) 2001-2002, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Adam Dunkels.
* 4. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
* $Id: uip.h,v 1.19 2002/01/15 17:54:54 adam Exp $
*
*/
#ifndef __UIP_H__
#define __UIP_H__
#include "uipopt.h"
/*-----------------------------------------------------------------------------------*/
/* First, the functions that should be called from the
* system. Initialization, the periodic timer and incoming packets are
* handled by the following three functions.
*/
/* uip_init():
*
* Must be called at boot up to configure the uIP data structures.
*/
void uip_init(void);
/* uip_periodic(conn):
*
* Should be called when the periodic timer has fired. Should be
* called once per connection (0 - UIP_CONNS).
*/
#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
uip_process(UIP_TIMER); } while (0)
/* uip_input():
*
* Is called when the network device driver has received new data.
*/
#define uip_input() uip_process(UIP_DATA)
/*-----------------------------------------------------------------------------------*/
/* Functions that are used by the uIP application program. Opening and
* closing connections, sending and receiving data, etc. is all
* handled by the functions below.
*/
/* uip_listen(port):
*
* Starts listening to the specified port.
*/
void uip_listen(u16_t port);
/* uip_connect(ripaddr, port):
*
* Returns a connection identifier that connects to a port on the
* specified host (given in ripaddr). If no connections are avaliable,
* the function returns NULL. This function is avaliable only if
* support for active open has been configured (#define
* UIP_ACTIVE_OPEN 1 in uipopt.h)
*/
struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
/* uip_send(data, len):
*
* Send data on the current connection. The length of the data must
* not exceed the maxium segment size (MSS) for the connection.
*/
#define uip_send(data, len) do { uip_appdata = data; uip_len = len;} while(0)
/* uip_datalen():
*
* The length of the data that is currently avaliable (if avaliable)
* in the uip_appdata buffer. The test function uip_data() is
* used to check if data is avaliable.
*/
#define uip_datalen() uip_len
/* uip_close():
*
* Close the current connection.
*/
#define uip_close() (uip_flags = UIP_CLOSE)
/* uip_abort():
*
* Abort the current connection.
*/
#define uip_abort() (uip_flags = UIP_ABORT)
/* uip_stop():
*
* Close our receiver's window so that we stop receiving data for the
* current connection.
*/
#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
/* uip_stopped():
*
* Find out if the current connection has been previously stopped.
*/
#define uip_stopped() (uip_conn->tcpstateflags & UIP_STOPPED)
/* uip_restart():
*
* Open the window again so that we start receiving data for the
* current connection.
*/
#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
uip_conn->tcpstateflags &= ~UIP_STOPPED; \
} while(0)
/* uIP tests that can be made to determine in what state the current
connection is, and what the application function should do. */
/* uip_newdata():
*
* Will reduce to non-zero if there is new data for the application
* present at the uip_appdata pointer. The size of the data is
* avaliable through the uip_len variable.
*/
#define uip_newdata() (uip_flags & UIP_NEWDATA)
/* uip_acked():
*
* Will reduce to non-zero if the previously sent data has been
* acknowledged by the remote host. This means that the application
* can send new data. uip_reset_acked() can be used to reset the acked
* flag.
*/
#define uip_acked() (uip_flags & UIP_ACKDATA)
#define uip_reset_acked() (uip_flags &= ~UIP_ACKDATA)
/* uip_connected():
*
* Reduces to non-zero if the current connection has been connected to
* a remote host. This will happen both if the connection has been
* actively opened (with uip_connect()) or passively opened (with
* uip_listen()).
*/
#define uip_connected() (uip_flags & UIP_CONNECTED)
/* uip_closed():
*
* Is non-zero if the connection has been closed by the remote
* host. The application may do the necessary clean-ups.
*/
#define uip_closed() (uip_flags & UIP_CLOSE)
/* uip_aborted():
*
* Non-zero if the current connection has been aborted (reset) by the
* remote host.
*/
#define uip_aborted() (uip_flags & UIP_ABORT)
/* uip_timedout():
*
* Non-zero if the current connection has been aborted due to too many
* retransmissions.
*/
#define uip_timedout() (uip_flags & UIP_TIMEDOUT)
/* uip_rexmit():
*
* Reduces to non-zero if the previously sent data has been lost in
* the network, and the application should retransmit it. The
* application should set the uip_appdata buffer and the uip_len
* variable just as it did the last time this data was to be
* transmitted.
*/
#define uip_rexmit() (uip_flags & UIP_REXMIT)
/* uip_poll():
*
* Is non-zero if the reason the application is invoked is that the
* current connection has been idle for a while and should be
* polled.
*/
#define uip_poll() (uip_flags & UIP_POLL)
/* uip_mss():
*
* Gives the current maxium segment size (MSS) of the current
* connection.
*/
#define uip_mss() (uip_conn->mss)
/* uIP convenience and converting functions. */
/* uip_ipaddr(&ipaddr, addr0,addr1,addr2,addr3):
*
* Packs an IP address into a two element 16-bit array. Such arrays
* are used to represent IP addresses in uIP.
*/
#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
(addr)[0] = htons(((addr0) << 8) | (addr1)); \
(addr)[1] = htons(((addr2) << 8) | (addr3)); \
} while(0)
/* htons(), ntohs():
*
* Macros for converting 16-bit quantities between host and network
* byte order.
*/
#ifndef htons
# if BYTE_ORDER == BIG_ENDIAN
# define htons(n) (n)
# else /* BYTE_ORDER == BIG_ENDIAN */
# define htons(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
# endif /* BYTE_ORDER == BIG_ENDIAN */
#endif /* htons */
#define ntohs(n) htons(n)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -