📄 httpd.i
字号:
u16_t mtu;
char name[2];
u8_t num;
u8_t flags;
};
extern struct netif *netif_list;
extern struct netif *netif_default;
void netif_init(void);
struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw,
void *state,
err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif));
void
netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw);
void netif_remove(struct netif * netif);
struct netif *netif_find(char *name);
void netif_set_default(struct netif *netif);
void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
void netif_set_gw(struct netif *netif, struct ip_addr *gw);
# 58 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\lwip\\tcp.h" 1
# 1 "..\\unip\\include\\lwip\\sys.h" 1
typedef u8_t sys_sem_t;
typedef u8_t sys_mbox_t;
struct sys_timeout {u8_t dummy;};
# 131 "..\\unip\\include\\lwip\\sys.h"
# 174 "..\\unip\\include\\lwip\\sys.h"
# 35 "..\\unip\\include\\lwip\\tcp.h" 2
# 1 "..\\unip\\include\\lwip\\ip.h" 1
struct netif;
void ip_init(void);
u8_t ip_lookup(void *header, struct netif *inp);
struct netif *ip_route(struct ip_addr *dest);
err_t ip_input(struct pbuf *p, struct netif *inp);
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t proto);
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t proto,
struct netif *netif);
struct ip_hdr {
u16_t _v_hl_tos __attribute__((packed)) ;
u16_t _len __attribute__((packed)) ;
u16_t _id __attribute__((packed)) ;
u16_t _offset __attribute__((packed)) ;
u16_t _ttl_proto __attribute__((packed)) ;
u16_t _chksum __attribute__((packed)) ;
struct ip_addr src __attribute__((packed)) ;
struct ip_addr dest __attribute__((packed)) ;
} __attribute__((packed)) ;
# 40 "..\\unip\\include\\lwip\\tcp.h" 2
# 1 "..\\unip\\include\\lwip\\icmp.h" 1
enum icmp_dur_type {
ICMP_DUR_NET = 0,
ICMP_DUR_HOST = 1,
ICMP_DUR_PROTO = 2,
ICMP_DUR_PORT = 3,
ICMP_DUR_FRAG = 4,
ICMP_DUR_SR = 5
};
enum icmp_te_type {
ICMP_TE_TTL = 0,
ICMP_TE_FRAG = 1
};
void icmp_input(struct pbuf *p, struct netif *inp);
void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
struct icmp_echo_hdr {
u16_t _type_code __attribute__((packed)) ;
u16_t chksum __attribute__((packed)) ;
u16_t id __attribute__((packed)) ;
u16_t seqno __attribute__((packed)) ;
} __attribute__((packed)) ;
struct icmp_dur_hdr {
u16_t _type_code __attribute__((packed)) ;
u16_t chksum __attribute__((packed)) ;
u32_t unused __attribute__((packed)) ;
} __attribute__((packed)) ;
struct icmp_te_hdr {
u16_t _type_code __attribute__((packed)) ;
u16_t chksum __attribute__((packed)) ;
u32_t unused __attribute__((packed)) ;
} __attribute__((packed)) ;
# 41 "..\\unip\\include\\lwip\\tcp.h" 2
struct tcp_pcb;
void tcp_init (void);
void tcp_tmr (void);
struct tcp_pcb * tcp_new (void);
struct tcp_pcb * tcp_alloc (u8_t prio);
void tcp_arg (struct tcp_pcb *pcb, void *arg);
void tcp_accept (struct tcp_pcb *pcb,
err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
err_t err));
void tcp_recv (struct tcp_pcb *pcb,
err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
struct pbuf *p, err_t err));
void tcp_sent (struct tcp_pcb *pcb,
err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
u16_t len));
void tcp_poll (struct tcp_pcb *pcb,
err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
u8_t interval);
void tcp_err (struct tcp_pcb *pcb,
void (* err)(void *arg, err_t err));
void tcp_recved (struct tcp_pcb *pcb, u16_t len);
err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port);
err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port, err_t (* connected)(void *arg,
struct tcp_pcb *tpcb,
err_t err));
struct tcp_pcb * tcp_listen (struct tcp_pcb *pcb);
void tcp_abort (struct tcp_pcb *pcb);
err_t tcp_close (struct tcp_pcb *pcb);
err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
u8_t copy);
void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
void tcp_slowtmr (void);
void tcp_fasttmr (void);
void tcp_input (struct pbuf *p, struct netif *inp);
err_t tcp_output (struct tcp_pcb *pcb);
void tcp_rexmit (struct tcp_pcb *pcb);
struct tcp_hdr {
u16_t src __attribute__((packed)) ;
u16_t dest __attribute__((packed)) ;
u32_t seqno __attribute__((packed)) ;
u32_t ackno __attribute__((packed)) ;
u16_t _offset_flags __attribute__((packed)) ;
u16_t wnd __attribute__((packed)) ;
u16_t chksum __attribute__((packed)) ;
u16_t urgp __attribute__((packed)) ;
} __attribute__((packed)) ;
enum tcp_state {
CLOSED = 0,
LISTEN = 1,
SYN_SENT = 2,
SYN_RCVD = 3,
ESTABLISHED = 4,
FIN_WAIT_1 = 5,
FIN_WAIT_2 = 6,
CLOSE_WAIT = 7,
CLOSING = 8,
LAST_ACK = 9,
TIME_WAIT = 10
};
struct tcp_pcb {
struct tcp_pcb *next;
u8_t prio;
void *callback_arg;
struct ip_addr local_ip;
u16_t local_port;
enum tcp_state state;
struct ip_addr remote_ip;
u16_t remote_port;
u32_t rcv_nxt;
u16_t rcv_wnd;
u32_t tmr;
u8_t polltmr, pollinterval;
u16_t rtime;
u16_t mss;
u8_t flags;
u16_t rttest;
u32_t rtseq;
s16_t sa, sv;
u16_t rto;
u8_t nrtx;
u32_t lastack;
u8_t dupacks;
u16_t cwnd;
u16_t ssthresh;
u32_t snd_nxt,
snd_max,
snd_wnd,
snd_wl1, snd_wl2,
snd_lbb;
u16_t acked;
u16_t snd_buf;
u8_t snd_queuelen;
struct tcp_seg *unsent;
struct tcp_seg *unacked;
struct tcp_seg *ooseq;
err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);
err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
err_t (* poll)(void *arg, struct tcp_pcb *pcb);
void (* errf)(void *arg, err_t err);
};
struct tcp_pcb_listen {
struct tcp_pcb_listen *next;
u8_t prio;
void *callback_arg;
struct ip_addr local_ip;
u16_t local_port;
enum tcp_state state;
err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
};
# 335 "..\\unip\\include\\lwip\\tcp.h"
struct tcp_seg {
struct tcp_seg *next;
struct pbuf *p;
void *dataptr;
u16_t len;
struct tcp_hdr *tcphdr;
};
struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
void tcp_pcb_purge(struct tcp_pcb *pcb);
void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
u8_t tcp_segs_free(struct tcp_seg *seg);
u8_t tcp_seg_free(struct tcp_seg *seg);
struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
u8_t flags, u8_t copy,
u8_t *optdata, u8_t optlen);
void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
void tcp_rst(u32_t seqno, u32_t ackno,
struct ip_addr *local_ip, struct ip_addr *remote_ip,
u16_t local_port, u16_t remote_port);
u32_t tcp_next_iss(void);
extern struct tcp_pcb *tcp_input_pcb;
extern u32_t tcp_ticks;
extern struct tcp_pcb_listen *tcp_listen_pcbs;
extern struct tcp_pcb *tcp_active_pcbs;
extern struct tcp_pcb *tcp_tw_pcbs;
extern struct tcp_pcb *tcp_tmp_pcb;
# 467 "..\\unip\\include\\lwip\\tcp.h"
# 484 "..\\unip\\include\\lwip\\tcp.h"
extern u16_t tcp_mss ;
extern u16_t tcp_window ;
extern u16_t tcp_maxrtx ;
extern u16_t tcp_synmaxrtx ;
# 59 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\lwip\\udp.h" 1
struct udp_hdr {
u16_t src __attribute__((packed)) ;
u16_t dest __attribute__((packed)) ;
u16_t len __attribute__((packed)) ;
u16_t chksum __attribute__((packed)) ;
} __attribute__((packed)) ;
struct udp_pcb {
struct udp_pcb *next;
struct ip_addr local_ip, remote_ip;
u16_t local_port, remote_port;
u8_t flags;
u16_t chksum_len;
void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
struct ip_addr *addr, u16_t port);
void *recv_arg;
};
struct udp_pcb * udp_new (void);
void udp_remove (struct udp_pcb *pcb);
err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port);
err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port);
void udp_disconnect (struct udp_pcb *pcb);
void udp_recv (struct udp_pcb *pcb,
void (* recv)(void *arg, struct udp_pcb *upcb,
struct pbuf *p,
struct ip_addr *addr,
u16_t port),
void *recv_arg);
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
u8_t udp_lookup (struct ip_hdr *iphdr, struct netif *inp);
void udp_input (struct pbuf *p, struct netif *inp);
void udp_init (void);
# 60 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\lwip\\memp.h" 1
typedef enum {
MEMP_PBUF,
MEMP_TCP_PCB,
MEMP_TCP_PCB_LISTEN,
MEMP_TCP_SEG,
MEMP_MAX
} memp_t;
struct memp {
struct memp *next;
};
void memp_init(void);
void *memp_malloc(memp_t type);
void *memp_realloc(memp_t fromtype, memp_t totype, void *mem);
void memp_free(memp_t type, void *mem);
void *memp_mallocp(memp_t type);
void memp_freep(memp_t type, void *mem);
# 93 "..\\unip\\include\\lwip\\memp.h"
extern u16_t memp_num[];
extern u8_t memp_memory [] ;
# 146 "..\\unip\\include\\lwip\\memp.h"
extern pbuf_num ;
extern udp_num ;
extern tcp_num ;
extern ltcp_num ;
extern tcp_seg_num ;
# 64 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\lwip\\stats.h" 1
struct stats_proto {
u16_t xmit;
u16_t rexmit;
u16_t recv;
u16_t drop;
u16_t chkerr;
u16_t lenerr;
u16_t memerr;
u16_t rterr;
u16_t proterr;
u16_t opterr;
u16_t err;
};
struct stats_mem {
mem_size_t avail;
mem_size_t used;
mem_size_t max;
mem_size_t err;
};
struct stats_pbuf {
u16_t avail;
u16_t used;
u16_t max;
u16_t err;
u16_t alloc_locked;
u16_t refresh_locked;
};
struct stats_syselem {
u16_t used;
u16_t max;
u16_t err;
};
struct stats_sys {
struct stats_syselem sem;
struct stats_syselem mbox;
};
# 115 "..\\unip\\include\\lwip\\stats.h"
struct stats_ {
struct stats_proto icmp;
struct stats_proto tcp;
struct stats_pbuf pbuf;
struct stats_mem mem;
struct stats_mem memp[MEMP_MAX];
};
extern struct stats_ lwip_stats ;
void stats_init(void);
# 65 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\netif\\etharp.h" 1
struct eth_addr {
u16_t addr[3];
} __attribute__((packed)) ;
struct eth_hdr {
struct eth_addr dest __attribute__((packed)) ;
struct eth_addr src __attribute__((packed)) ;
u16_t type __attribute__((packed)) ;
} __attribute__((packed)) ;
struct etharp_hdr {
struct eth_hdr ethhdr __attribute__((packed)) ;
u16_t hwtype __attribute__((packed)) ;
u16_t proto __attribute__((packed)) ;
u16_t _hwlen_protolen __attribute__((packed)) ;
u16_t opcode __attribute__((packed)) ;
struct eth_addr shwaddr __attribute__((packed)) ;
struct ip_addr sipaddr __attribute__((packed)) ;
struct eth_addr dhwaddr __attribute__((packed)) ;
struct ip_addr dipaddr __attribute__((packed)) ;
} __attribute__((packed)) ;
struct ethip_hdr {
struct eth_hdr eth __attribute__((packed)) ;
struct ip_hdr ip __attribute__((packed)) ;
};
enum etharp_state {
ETHARP_STATE_EMPTY,
ETHARP_STATE_PENDING,
ETHARP_STATE_STABLE
};
struct etharp_entry {
struct ip_addr ipaddr;
struct eth_addr ethaddr;
enum etharp_state state;
struct pbuf *p;
u8_t ctime;
};
void etharp_init(void);
void etharp_tmr(void);
struct pbuf *etharp_ip_input(struct netif *netif, struct pbuf *p);
struct pbuf *etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
struct pbuf *p);
struct pbuf *etharp_output(struct netif *netif, struct ip_addr *ipaddr,
struct pbuf *q);
err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);
struct eth_addr * etharp_lookup(struct ip_addr *ipaddr);
extern struct etharp_entry arp_table [] ;
extern u16_t arp_num ;
# 68 "..\\unip\\include\\lwipopts.h" 2
# 1 "..\\unip\\include\\unsp\\include\\ethernet.h" 1
err_t ethernetif_init(struct netif *netif);
void etharp_timer(void *arg);
# 73 "..\\unip\\include\\lwipopts.h" 2
# 21 "..\\code\\include\\config.h" 2
# 39 "G:/\301\350\321\364\265\245\306\254\273\372/\320\302\275\250\316\304\274\376\274\320/9.\304\243\327\351\327\312\301\317/\322\324\314\253\315\370\315\250\321\266\304\243\327\351/\322\324\314\253\315\370DemoCode/DemoCode/code/httpd.c" 2
# 1 "..\\code\\include\\httpd.h" 1
void httpd_init(void);
struct webdata {
struct webdata *next;
u16_t *payload;
u16_t offset;
u16_t len;
u16_t attr;
};
struct http_state {
struct webdata *web;
u8_t retries;
};
# 40 "G:/\301\350\321\364\265\245\306\254\273\372/\320\302\275\250\316\304\274\376\274\320/9.\304\243\327\351\327\312\301\317/\322\324\314\253\315\370\315\250\321\266\304\243\327\351/\322\324\314\253\315\370DemoCode/DemoCode/code/httpd.c" 2
# 1 "..\\code\\include\\web.h" 1
# 1 "..\\code\\include\\fs.h" 1
struct fs_file {
unsigned int *data;
int len;
};
int fs_open(char *name, struct fs_file *file);
# 4 "..\\code\\include\\web.h" 2
struct CGI_StaS{
u16_t Hour;
u16_t Min;
u16_t Sec;
u16_t* Input;
u16_t* Output;
};
void web_free(struct webdata *head);
struct webdata *Web_Init(struct fs_file *file,u16_t opt);
err_t web_head_alloc(struct webdata *headw, struct webdata *web);
struct webdata *Web_Request(char *req);
# 41 "G:/\301\350\321\364\265\245\306\254\273\372/\320\302\275\250\316\304\274\376\274\320/9.\304\243\327\351\327\312\301\317/\322\324\314\253\315\370\315\250\321\266\304\243\327\351/\322\324\314\253\315\370DemoCode/DemoCode/code/httpd.c" 2
extern struct webdata * CGI_Callback(char *tempdata);
void
conn_err(void *arg, err_t err)
{
struct http_state *hs;
hs = arg;
if (hs!= ((void *)0) )
{
web_free(hs->web);
mem_free(hs);
}
}
static void
close_conn(struct tcp_pcb *pcb, struct http_state *hs)
{
tcp_arg(pcb, ((void *)0) );
tcp_sent(pcb, ((void *)0) );
tcp_recv(pcb, ((void *)0) );
tcp_poll(pcb,((void *)0) ,10);
if (hs!= ((void *)0) )
{
web_free(hs->web);
mem_free(hs);
}
tcp_close(pcb);
}
static err_t
send_data(struct tcp_pcb *pcb, struct http_state *hs)
{
err_t err;
u16_t len,*data,copy;
while (((( pcb )->snd_buf) >2)&&(hs->web!= ((void *)0) ))
{
len = hs->web->len - hs->web->offset;
if((( pcb )->snd_buf) < len) {
len = ((( pcb )->snd_buf) -1)/2;
len *= 2;
}
data = (u16_t *)(hs->web->payload + (hs->web->offset / 2));
do {
if (hs->web->attr == 0x01U ) copy = 0;
else copy = 1;
err = tcp_write(pcb, data, len, copy);
if(err == -1 ) {
close_conn(pcb,hs);
return err;
}
} while(err == -1 && len > 0);
if(err == 0 ) {
hs->web->offset += len;
if (hs->web->offset == hs->web->len)
{
if (hs->web->attr == 0x00U )
mem_free(hs->web->payload);
data = (u16_t *)hs->web;
hs->web = hs->web->next;
mem_free(data);
}
}
}
return 0 ;
}
err_t
http_poll(void *arg, struct tcp_pcb *pcb)
{
err_t err;
struct http_state *hs;
hs = arg;
if(hs ->web == ((void *)0) ) {
close_conn(pcb,hs);
return 0 ;
} else {
++hs->retries;
if(hs->retries >= 30) {
tcp_abort(pcb);
return -3 ;
}
err = send_data(pcb, hs);
return err;
}
return 0 ;
}
err_t
http_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
struct http_state *hs;
hs = arg;
hs->retries = 0;
if (hs->web != ((void *)0) )
{
send_data(pcb, hs);
} else {
close_conn(pcb, hs);
}
return 0 ;
}
err_t
http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
int i;
u16_t *data;
struct http_state *hs;
u16_t * tempdata;
hs = arg;
tcp_recved(pcb, p->tot_len);
if(err == 0 && p != ((void *)0) ) {
if(hs->web == ((void *)0) ) {
tempdata = mem_malloc(58);
data = p->payload;
for(i=0;i<50;i++)
tempdata[i] = getbyte(data, i);
pbuf_free(p);
if(strncmp(tempdata, "GET ", 4) == 0) {
for(i = 0; i < 50; i++) {
if(((char *)tempdata + 4)[i] == ' ' ||
((char *)tempdata + 4)[i] == '\r' ||
((char *)tempdata + 4)[i] == '\n' ||
((char *)tempdata + 4)[i] == '=' ||
((char *)tempdata + 4)[i] == '&' ||
((char *)tempdata + 4)[i] == '?' ) {
((char *)tempdata + 4)[i] = 0;
}
}
hs->web = Web_Request((char *)&tempdata[4]);
send_data(pcb, hs);
tcp_sent(pcb, http_sent);
}
mem_free(tempdata);
}
pbuf_free(p);
}
else if(err == 0 && p == ((void *)0) ) {
close_conn(pcb, hs);
}
else
{
tcp_abort(pcb);
return -3 ;
}
return 0 ;
}
err_t
http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
struct http_state *hs;
tcp_setprio(pcb, 1 );
hs = mem_malloc(sizeof(struct http_state));
if(hs == ((void *)0) ) {
return -1 ;
}
hs->retries = 0;
hs->web = ((void *)0) ;
tcp_arg(pcb, hs);
tcp_recv(pcb, http_recv);
tcp_err(pcb, conn_err);
tcp_poll(pcb, http_poll, 10);
return 0 ;
}
void
httpd_init(void)
{
struct tcp_pcb *pcb;
pcb = tcp_new();
tcp_bind(pcb, ((struct ip_addr *)&ip_addr_any) , 80);
pcb = tcp_listen(pcb);
tcp_accept(pcb, http_accept);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -