51hei.png (8.04 KB, 下載次數: 59)
下載附件
2020-5-28 13:35 上傳
1.png (255.31 KB, 下載次數: 35)
下載附件
2023-3-7 19:05 上傳
單片機源程序如下:
- #define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/
- #include "uip.h"
- #include "uipopt.h"
- #include "uip_arch.h"
- #if UIP_CONF_IPV6
- #include "uip-neighbor.h"
- #endif /* UIP_CONF_IPV6 */
- #include <string.h>
- /*---------------------------------------------------------------------------*/
- /* Variable definitions. */
- /* The IP address of this host. If it is defined to be fixed (by
- setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
- here. Otherwise, the address */
- #if UIP_FIXEDADDR > 0
- const uip_ipaddr_t uip_hostaddr =
- {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
- HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
- const uip_ipaddr_t uip_draddr =
- {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
- HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
- const uip_ipaddr_t uip_netmask =
- {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
- HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
- #else
- uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
- #endif /* UIP_FIXEDADDR */
- static const uip_ipaddr_t all_ones_addr =
- #if UIP_CONF_IPV6
- {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
- #else /* UIP_CONF_IPV6 */
- {0xffff,0xffff};
- #endif /* UIP_CONF_IPV6 */
- static const uip_ipaddr_t all_zeroes_addr =
- #if UIP_CONF_IPV6
- {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
- #else /* UIP_CONF_IPV6 */
- {0x0000,0x0000};
- #endif /* UIP_CONF_IPV6 */
- #if UIP_FIXEDETHADDR
- const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
- UIP_ETHADDR1,
- UIP_ETHADDR2,
- UIP_ETHADDR3,
- UIP_ETHADDR4,
- UIP_ETHADDR5}};
- #else
- struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
- #endif
- #ifndef UIP_CONF_EXTERNAL_BUFFER
- u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
- incoming packets. */
- #endif /* UIP_CONF_EXTERNAL_BUFFER */
- void *uip_appdata; /* The uip_appdata pointer points to
- application data. */
- void *uip_sappdata; /* The uip_appdata pointer points to
- the application data which is to
- be sent. */
- #if UIP_URGDATA > 0
- void *uip_urgdata; /* The uip_urgdata pointer points to
- urgent data (out-of-band data), if
- present. */
- u16_t uip_urglen, uip_surglen;
- #endif /* UIP_URGDATA > 0 */
- u16_t uip_len, uip_slen;
- /* The uip_len is either 8 or 16 bits,
- depending on the maximum packet
- size. */
- u8_t uip_flags; /* The uip_flags variable is used for
- communication between the TCP/IP stack
- and the application program. */
- struct uip_conn *uip_conn; /* uip_conn always points to the current
- connection. */
- struct uip_conn uip_conns[UIP_CONNS];
- /* The uip_conns array holds all TCP
- connections. */
- u16_t uip_listenports[UIP_LISTENPORTS];
- /* The uip_listenports list all currently
- listning ports. */
- #if UIP_UDP
- struct uip_udp_conn *uip_udp_conn;
- struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
- #endif /* UIP_UDP */
- static u16_t ipid; /* Ths ipid variable is an increasing
- number that is used for the IP ID
- field. */
- void uip_setipid(u16_t id) { ipid = id; }
- static u8_t iss[4]; /* The iss variable is used for the TCP
- initial sequence number. */
- #if UIP_ACTIVE_OPEN
- static u16_t lastport; /* Keeps track of the last port used for
- a new connection. */
- #endif /* UIP_ACTIVE_OPEN */
- /* Temporary variables. */
- u8_t uip_acc32[4];
- static u8_t c, opt;
- static u16_t tmp16;
- /* Structures and definitions. */
- #define TCP_FIN 0x01
- #define TCP_SYN 0x02
- #define TCP_RST 0x04
- #define TCP_PSH 0x08
- #define TCP_ACK 0x10
- #define TCP_URG 0x20
- #define TCP_CTL 0x3f
- #define TCP_OPT_END 0 /* End of TCP options list */
- #define TCP_OPT_NOOP 1 /* "No-operation" TCP option */
- #define TCP_OPT_MSS 2 /* Maximum segment size TCP option */
- #define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */
- #define ICMP_ECHO_REPLY 0
- #define ICMP_ECHO 8
- #define ICMP6_ECHO_REPLY 129
- #define ICMP6_ECHO 128
- #define ICMP6_NEIGHBOR_SOLICITATION 135
- #define ICMP6_NEIGHBOR_ADVERTISEMENT 136
- #define ICMP6_FLAG_S (1 << 6)
- #define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
- #define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
- /* Macros. */
- #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
- #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
- #define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
- #define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
- #if UIP_STATISTICS == 1
- struct uip_stats uip_stat;
- #define UIP_STAT(s) s
- #else
- #define UIP_STAT(s)
- #endif /* UIP_STATISTICS == 1 */
- #if UIP_LOGGING == 1
- #include <stdio.h>
- void uip_log(char *msg);
- #define UIP_LOG(m) uip_log(m)
- #else
- #define UIP_LOG(m)
- #endif /* UIP_LOGGING == 1 */
- #if ! UIP_ARCH_ADD32
- void
- uip_add32(u8_t *op32, u16_t op16)
- {
- uip_acc32[3] = op32[3] + (op16 & 0xff);
- uip_acc32[2] = op32[2] + (op16 >> 8);
- uip_acc32[1] = op32[1];
- uip_acc32[0] = op32[0];
-
- if(uip_acc32[2] < (op16 >> 8)) {
- ++uip_acc32[1];
- if(uip_acc32[1] == 0) {
- ++uip_acc32[0];
- }
- }
-
-
- if(uip_acc32[3] < (op16 & 0xff)) {
- ++uip_acc32[2];
- if(uip_acc32[2] == 0) {
- ++uip_acc32[1];
- if(uip_acc32[1] == 0) {
- ++uip_acc32[0];
- }
- }
- }
- }
- #endif /* UIP_ARCH_ADD32 */
- #if ! UIP_ARCH_CHKSUM
- /*---------------------------------------------------------------------------*/
- static u16_t
- chksum(u16_t sum, const u8_t *data, u16_t len)
- {
- u16_t t;
- const u8_t *dataptr;
- const u8_t *last_byte;
- dataptr = data;
- last_byte = data + len - 1;
-
- while(dataptr < last_byte) { /* At least two more bytes */
- t = (dataptr[0] << 8) + dataptr[1];
- sum += t;
- if(sum < t) {
- sum++; /* carry */
- }
- dataptr += 2;
- }
-
- if(dataptr == last_byte) {
- t = (dataptr[0] << 8) + 0;
- sum += t;
- if(sum < t) {
- sum++; /* carry */
- }
- }
- /* Return sum in host byte order. */
- return sum;
- }
- /*---------------------------------------------------------------------------*/
- u16_t
- uip_chksum(u16_t *data, u16_t len)
- {
- return htons(chksum(0, (u8_t *)data, len));
- }
- /*---------------------------------------------------------------------------*/
-
復制代碼
所有資料51hei提供下載:
uIP學習資料.7z
(3.73 MB, 下載次數: 23)
2020-5-28 13:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|