📄 uip.h
字号:
* * \hideinitializer */void uip_send(const void *data, int len);/** * The length of any incoming data that is currently avaliable (if avaliable) * in the uip_appdata buffer. * * The test function uip_data() must first be used to check if there * is any data available at all. * * \hideinitializer *//*void uip_datalen(void);*/#define uip_datalen() uip_len/** * The length of any out-of-band data (urgent data) that has arrived * on the connection. * * \note The configuration parameter UIP_URGDATA must be set for this * function to be enabled. * * \hideinitializer */#define uip_urgdatalen() uip_urglen/** * Close the current connection. * * This function will close the current connection in a nice way. * * \hideinitializer */#define uip_close() (uip_flags = UIP_CLOSE)/** * Abort the current connection. * * This function will abort (reset) the current connection, and is * usually used when an error has occured that prevents using the * uip_close() function. * * \hideinitializer */#define uip_abort() (uip_flags = UIP_ABORT)/** * Tell the sending host to stop sending data. * * This function will close our receiver's window so that we stop * receiving data for the current connection. * * \hideinitializer */#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)/** * Find out if the current connection has been previously stopped with * uip_stop(). * * \hideinitializer */#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)/** * Restart the current connection, if is has previously been stopped * with uip_stop(). * * This function will open the receiver's window again so that we * start receiving data for the current connection. * * \hideinitializer */#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. *//** * Is the current connection a UDP connection? * * This function checks whether the current connection is a UDP connection. * * \hideinitializer * */#define uip_udpconnection() (uip_conn == NULL)/** * Is new incoming data available? * * 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. * * \hideinitializer */#define uip_newdata() (uip_flags & UIP_NEWDATA)/** * Has previously sent data been acknowledged? * * 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. * * \hideinitializer */#define uip_acked() (uip_flags & UIP_ACKDATA)/** * Has the connection just been 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()). * * \hideinitializer */#define uip_connected() (uip_flags & UIP_CONNECTED)/** * Has the connection been closed by the other end? * * Is non-zero if the connection has been closed by the remote * host. The application may then do the necessary clean-ups. * * \hideinitializer */#define uip_closed() (uip_flags & UIP_CLOSE)/** * Has the connection been aborted by the other end? * * Non-zero if the current connection has been aborted (reset) by the * remote host. * * \hideinitializer */#define uip_aborted() (uip_flags & UIP_ABORT)/** * Has the connection timed out? * * Non-zero if the current connection has been aborted due to too many * retransmissions. * * \hideinitializer */#define uip_timedout() (uip_flags & UIP_TIMEDOUT)/** * Do we need to retransmit previously data? * * Reduces to non-zero if the previously sent data has been lost in * the network, and the application should retransmit it. The * application should send the exact same data as it did the last * time, using the uip_send() function. * * \hideinitializer */#define uip_rexmit() (uip_flags & UIP_REXMIT)/** * Is the connection being polled by uIP? * * 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. * * The polling event can be used for sending data without having to * wait for the remote host to send data. * * \hideinitializer */#define uip_poll() (uip_flags & UIP_POLL)/** * Get the initial maxium segment size (MSS) of the current * connection. * * \hideinitializer */#define uip_initialmss() (uip_conn->initialmss)/** * Get the current maxium segment size that can be sent on the current * connection. * * The current maxiumum segment size that can be sent on the * connection is computed from the receiver's window and the MSS of * the connection (which also is available by calling * uip_initialmss()). * * \hideinitializer */#define uip_mss() (uip_conn->mss)/** * Set up a new UDP connection. * * This function sets up a new UDP connection. The function will * automatically allocate an unused local port for the new * connection. However, another port can be chosen by using the * uip_udp_bind() call, after the uip_udp_new() function has been * called. * * Example: \code uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 192,168,2,1); c = uip_udp_new(&addr, HTONS(12345)); if(c != NULL) { uip_udp_bind(c, HTONS(12344)); } \endcode * \param ripaddr The IP address of the remote host. * * \param rport The remote port number in network byte order. * * \return The uip_udp_conn structure for the new connection or NULL * if no connection could be allocated. */struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);/** * Removed a UDP connection. * * \param conn A pointer to the uip_udp_conn structure for the connection. * * \hideinitializer */#define uip_udp_remove(conn) (conn)->lport = 0/** * Bind a UDP connection to a local port. * * \param conn A pointer to the uip_udp_conn structure for the * connection. * * \param port The local port number, in network byte order. * * \hideinitializer */#define uip_udp_bind(conn, port) (conn)->lport = port/** * Send a UDP datagram of length len on the current connection. * * This function can only be called in response to a UDP event (poll * or newdata). The data must be present in the uip_buf buffer, at the * place pointed to by the uip_appdata pointer. * * \param len The length of the data in the uip_buf buffer. * * \hideinitializer */#define uip_udp_send(len) uip_send((char *)uip_appdata, len)/** @} *//* uIP convenience and converting functions. *//** * \defgroup uipconvfunc uIP conversion functions * @{ * * These functions can be used for converting between different data * formats used by uIP. */ /** * Construct an IP address from four bytes. * * This function constructs an IP address of the type that uIP handles * internally from four bytes. The function is handy for specifying IP * addresses to use with e.g. the uip_connect() function. * * Example: \code uip_ipaddr_t ipaddr; struct uip_conn *c; uip_ipaddr(&ipaddr, 192,168,1,2); c = uip_connect(&ipaddr, HTONS(80)); \endcode * * \param addr A pointer to a uip_ipaddr_t variable that will be * filled in with the IP address. * * \param addr0 The first octet of the IP address. * \param addr1 The second octet of the IP address. * \param addr2 The third octet of the IP address. * \param addr3 The forth octet of the IP address. * * \hideinitializer */#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ } while(0)/** * Construct an IPv6 address from eight 16-bit words. * * This function constructs an IPv6 address. * * \hideinitializer */#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ ((u16_t *)(addr))[0] = HTONS((addr0)); \ ((u16_t *)(addr))[1] = HTONS((addr1)); \ ((u16_t *)(addr))[2] = HTONS((addr2)); \ ((u16_t *)(addr))[3] = HTONS((addr3)); \ ((u16_t *)(addr))[4] = HTONS((addr4)); \ ((u16_t *)(addr))[5] = HTONS((addr5)); \ ((u16_t *)(addr))[6] = HTONS((addr6)); \ ((u16_t *)(addr))[7] = HTONS((addr7)); \ } while(0)/** * Copy an IP address to another IP address. * * Copies an IP address from one place to another. * * Example: \code uip_ipaddr_t ipaddr1, ipaddr2; uip_ipaddr(&ipaddr1, 192,16,1,2); uip_ipaddr_copy(&ipaddr2, &ipaddr1); \endcode * * \param dest The destination for the copy. * \param src The source from where to copy. * * \hideinitializer */#if !UIP_CONF_IPV6#define uip_ipaddr_copy(dest, src) do { \ ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ } while(0)#else /* !UIP_CONF_IPV6 */#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))#endif /* !UIP_CONF_IPV6 *//** * Compare two IP addresses * * Compares two IP addresses. * * Example: \code uip_ipaddr_t ipaddr1, ipaddr2; uip_ipaddr(&ipaddr1, 192,16,1,2); if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) { printf("They are the same"); } \endcode * * \param addr1 The first IP address. * \param addr2 The second IP address. * * \hideinitializer */#if !UIP_CONF_IPV6#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1])#else /* !UIP_CONF_IPV6 */#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)#endif /* !UIP_CONF_IPV6 *//** * Compare two IP addresses with netmasks * * Compares two IP addresses with netmasks. The masks are used to mask * out the bits that are to be compared. * * Example: \code uip_ipaddr_t ipaddr1, ipaddr2, mask; uip_ipaddr(&mask, 255,255,255,0); uip_ipaddr(&ipaddr1, 192,16,1,2); uip_ipaddr(&ipaddr2, 192,16,1,3); if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) { printf("They are the same"); } \endcode * * \param addr1 The first IP address. * \param addr2 The second IP address. * \param mask The netmask. * * \hideinitializer */#define uip_ipaddr_maskcmp(addr1, addr2, mask) \ (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))/** * Mask out the network part of an IP address. * * Masks out the network part of an IP address, given the address and * the netmask. * * Example: \code uip_ipaddr_t ipaddr1, ipaddr2, netmask; uip_ipaddr(&ipaddr1, 192,16,1,2); uip_ipaddr(&netmask, 255,255,255,0); uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask); \endcode * * In the example above, the variable "ipaddr2" will contain the IP * address 192.168.1.0. * * \param dest Where the result is to be placed. * \param src The IP address. * \param mask The netmask. * * \hideinitializer */#define uip_ipaddr_mask(dest, src, mask) do { \ ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ } while(0)/** * Pick the first octet of an IP address. * * Picks out the first octet of an IP address. * * Example: \code uip_ipaddr_t ipaddr; u8_t octet; uip_ipaddr(&ipaddr, 1,2,3,4); octet = uip_ipaddr1(&ipaddr); \endcode * * In the example above, the variable "octet" will contain the value 1. * * \hideinitializer */#define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8)/** * Pick the second octet of an IP address. * * Picks out the second octet of an IP address. * * Example: \code uip_ipaddr_t ipaddr; u8_t octet; uip_ipaddr(&ipaddr, 1,2,3,4); octet = uip_ipaddr2(&ipaddr); \endcode * * In the example above, the variable "octet" will contain the value 2. * * \hideinitializer */#define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff)/** * Pick the third octet of an IP address. * * Picks out the third octet of an IP address. * * Example: \code uip_ipaddr_t ipaddr; u8_t octet; uip_ipaddr(&ipaddr, 1,2,3,4); octet = uip_ipaddr3(&ipaddr); \endcode * * In the example above, the variable "octet" will contain the value 3. * * \hideinitializer */#define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8)/** * Pick the fourth octet of an IP address. * * Picks out the fourth octet of an IP address. * * Example: \code uip_ipaddr_t ipaddr; u8_t octet; uip_ipaddr(&ipaddr, 1,2,3,4); octet = uip_ipaddr4(&ipaddr); \endcode * * In the example above, the variable "octet" will contain the value 4. * * \hideinitializer */#define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff)/** * Convert 16-bit quantity from host byte order to network byte order. * * This macro is primarily used for converting constants from host * byte order to network byte order. For converting variables to * network byte order, use the htons() function instead. * * \hideinitializer */#ifndef HTONS# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN# define HTONS(n) (n)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -