/**
* \addtogroup uip
* @{
*/
/**
* \file
* The uIP TCP/IP stack code.
* \author Adam Dunkels <adam@dunkels.com>
*/
/*
* Copyright (c) 2001-2003, 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. 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.c,v 1.62.2.10 2003/10/07 13:23:01 adam Exp $
*
*/
/*
This is a small implementation of the IP and TCP protocols (as well as
some basic ICMP stuff). The implementation couples the IP, TCP and the
application layers very tightly. To keep the size of the compiled code
down, this code also features heavy usage of the goto statement.
The principle is that we have a small buffer, called the uip_buf, in
which the device driver puts an incoming packet. The TCP/IP stack
parses the headers in the packet, and calls upon the application. If
the remote host has sent data to the application, this data is present
in the uip_buf and the application read the data from there. It is up
to the application to put this data into a byte stream if needed. The
application will not be fed with data that is out of sequence.
If the application whishes to send data to the peer, it should put its
data into the uip_buf, 40 bytes from the start of the buffer. The
TCP/IP stack will calculate the checksums, and fill in the necessary
header fields and finally send the packet back to the peer.
*/
#include "uip.h"
#include "uipopt.h"
#include "uip_arch.h"
#include "uart.h"
#include "myopt.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 u16_t uip_hostaddr[2] =
{HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
const u16_t uip_arp_draddr[2] =
{HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
const u16_t uip_arp_netmask[2] =
{HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
#else
u16_t uip_hostaddr[2];
u16_t uip_arp_draddr[2], uip_arp_netmask[2];
#endif /* UIP_FIXEDADDR */
u8_t uip_buf[UIP_BUFSIZE+2]; /* The packet buffer that contains
incoming packets. */
volatile u8_t *uip_appdata; /* The uip_appdata pointer points to
application data. */
volatile u8_t *uip_sappdata; /* The uip_appdata pointer points to the
application data which is to be sent. */
#if UIP_URGDATA > 0
volatile u8_t *uip_urgdata; /* The uip_urgdata pointer points to
urgent data (out-of-band data), if
present. */
volatile u8_t uip_urglen, uip_surglen;
#endif /* UIP_URGDATA > 0 */
volatile u16_t uip_len, uip_slen;
/* The uip_len is either 8 or 16 bits,
depending on the maximum packet
size. */
volatile 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. */
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. */
volatile 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 ICMP_ECHO_REPLY 0
#define ICMP_ECHO 8
/* Macros. */
#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define FBUF ((uip_tcpip_hdr *)&uip_reassbuf[0])
#define ICMPBUF ((uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UDPBUF ((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 */
/*-----------------------------------------------------------------------------------*/
void
uip_init(void)
{
for(c = 0; c < UIP_LISTENPORTS; ++c) {
uip_listenports[c] = 0;
}
for(c = 0; c < UIP_CONNS; ++c) {
uip_conns[c].tcpstateflags = CLOSED;
}
#if UIP_ACTIVE_OPEN
lastport = 1024;
#endif /* UIP_ACTIVE_OPEN */
#if UIP_UDP
for(c = 0; c < UIP_UDP_CONNS; ++c) {
uip_udp_conns[c].lport = 0;
}
#endif /* UIP_UDP */
/* IPv4 initialization. */
#if UIP_FIXEDADDR == 0
uip_hostaddr[0] = uip_hostaddr[1] = 0;
#endif /* UIP_FIXEDADDR */
}
/*-----------------------------------------------------------------------------------*/
#if UIP_ACTIVE_OPEN
struct uip_conn *
uip_connect(u16_t *ripaddr, u16_t rport)
{
register struct uip_conn *conn, *cconn;
/* Find an unused local port. */
again:
++lastport;
if(lastport >= 32000) {
lastport = 4096;
}
/* Check if this port is already in use, and if so try to find
another one. */
for(c = 0; c < UIP_CONNS; ++c) {
conn = &uip_conns[c];
if(conn->tcpstateflags != CLOSED &&
conn->lport == htons(lastport)) {
goto again;
}
}
conn = 0;
for(c = 0; c < UIP_CONNS; ++c) {
cconn = &uip_conns[c];
if(cconn->tcpstateflags == CLOSED) {
conn = cconn;
break;
}
if(cconn->tcpstateflags == TIME_WAIT) {
if(conn == 0 ||
cconn->timer > uip_conn->timer) {
conn = cconn;
}
}
}
if(conn == 0) {
return 0;
}
conn->tcpstateflags = SYN_SENT;
conn->snd_nxt[0] = iss[0];
conn->snd_nxt[1] = iss[1];
conn->snd_nxt[2] = iss[2];
conn->snd_nxt[3] = iss[3];
conn->initialmss = conn->mss = UIP_TCP_MSS;
conn->len = 1; /* TCP length of the SYN is one. */
conn->nrtx = 0;
conn->timer = 1; /* Send the SYN next time around. */
conn->rto = UIP_RTO;
conn->sa = 0;
conn->sv = 16;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
enc28j60 +stc90c516ad+32kram+proteus仿真 (108个子文件)
tcp_server.__i 107B
enc28j60.__i 101B
uip_arch.__i 101B
uip_arp.__i 98B
fsdata.__i 95B
httpd.__i 92B
uart.__i 89B
uip.__i 86B
cgi.__i 86B
spi.__i 86B
fs.__i 83B
struct.h.a 5KB
uIP0.9_uvopt.bak 158KB
uIP0.9_uvproj.bak 15KB
uIP0_9_Opt.Bak 6KB
uIP0.9.opt.bak 6KB
uIP0.9.Uv2.bak 2KB
uIP0_9_Uv2.Bak 2KB
uip.c 45KB
fsdata.c 40KB
splc501.c 14KB
enc28j60.c 14KB
uip_arp.c 13KB
httpd.c 10KB
cgi.c 7KB
main.c 5KB
uart.c 5KB
fs.c 4KB
uip_arch.c 4KB
time.c 1KB
example1.c 1KB
example0.c 1KB
main1.c 973B
tcp_server.c 713B
main2.c 491B
spi.c 347B
Last Loaded 51+enc28j60_proteus.DBK 394KB
51+enc28j60_proteus.dsn 394KB
uip.h 31KB
uipopt.h 16KB
enc28j60.h 9KB
uip_arp.h 6KB
uip_arch.h 4KB
fsdata.h 4KB
fs.h 3KB
arp.h 3KB
httpd.h 2KB
icmp.h 2KB
cgi.h 2KB
ip.h 1KB
ethernet.h 895B
udp.h 849B
splc501.h 746B
main1.h 743B
main.h 743B
uart.h 578B
spi.h 312B
tcp_server.h 211B
example0.h 190B
myopt.h 185B
example1.h 150B
time.h 69B
uIP.hex 63KB
ExtDll.iex 19B
uIP.lnp 347B
uip.lst 74KB
fsdata.lst 56KB
enc28j60.lst 24KB
splc501.lst 23KB
uip_arp.lst 21KB
httpd.lst 18KB
cgi.lst 11KB
main.lst 10KB
uart.lst 10KB
MCU_UART.lst 8KB
fs.lst 7KB
uip_arch.lst 7KB
time.lst 4KB
example0.lst 4KB
example1.lst 3KB
tcp_server.lst 3KB
spi.lst 2KB
uIP.m51 103KB
uip.obj 58KB
enc28j60.obj 46KB
main.obj 36KB
uip_arp.obj 30KB
httpd.obj 28KB
cgi.obj 23KB
fs.obj 22KB
uip_arch.obj 20KB
example1.obj 19KB
example0.obj 18KB
fsdata.obj 17KB
tcp_server.obj 16KB
spi.obj 16KB
uart.obj 13KB
splc501.obj 12KB
MCU_UART.obj 10KB
time.obj 3KB
共 108 条
- 1
- 2
kkt2019
- 粉丝: 3
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- yolov5,SSD 可能使用到的一些代码
- 基于c51单片机+DS1302+DHT11温湿度模块+LCD1602显示的万年历硬件原理图+BOM+软件程源码序+仿真图.zip
- NSGA2的MATLAB代码
- Messagepassingtest_GCN_DGL.py
- Sh,Docker 运维好帮手,一招通过 sh 脚本批量快速启动和重启多个Docker 容器
- PCF2123.pdf
- 打开注册表操作.doc
- Windows 常见运行运行库32+64
- WMJUL8iC.html
- 基于3KW光伏并网单相逆变器设计(TMS320F28035控制板+显示板+STM32F103功率板)硬件(原理图+PCB)工程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页