tcpreset.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 97 行
C,V
97 行
head 1.2;
access;
symbols;
locks
dls:1.2; strict;
comment @ * @;
1.2
date 97.09.21.19.29.52; author dls; state Dist;
branches;
next 1.1;
1.1
date 94.01.14.03.51.20; author dls; state v2e1;
branches;
next ;
desc
@@
1.2
log
@pre-3e code
@
text
@/* tcpreset.c - tcpreset */
#include <conf.h>
#include <kernel.h>
#include <network.h>
/*------------------------------------------------------------------------
* tcpreset - generate a reset in response to a bad packet
*------------------------------------------------------------------------
*/
int tcpreset(pepin)
struct ep *pepin;
{
struct ep *pepout;
struct ip *pipin = (struct ip *)pepin->ep_data, *pipout;
struct tcp *ptcpin = (struct tcp *)pipin->ip_data, *ptcpout;
int datalen;
if (ptcpin->tcp_code & TCPF_RST)
return OK; /* no RESETs on RESETs */
pepout = (struct ep *)getbuf(Net.netpool);
if ((int)pepout == SYSERR)
return SYSERR;
pipout = (struct ip *)pepout->ep_data;
pipout->ip_src = pipin->ip_dst;
pipout->ip_dst = pipin->ip_src;
ptcpout = (struct tcp *)pipout->ip_data;
ptcpout->tcp_sport = ptcpin->tcp_dport;
ptcpout->tcp_dport = ptcpin->tcp_sport;
if (ptcpin->tcp_code & TCPF_ACK) {
ptcpout->tcp_seq = ptcpin->tcp_ack;
ptcpout->tcp_code = TCPF_RST;
} else {
ptcpout->tcp_seq = 0;
ptcpout->tcp_code = TCPF_RST|TCPF_ACK;
}
datalen = pipin->ip_len - IP_HLEN(pipin) - TCP_HLEN(ptcpin);
if (ptcpin->tcp_code & TCPF_SYN)
datalen++;
if (ptcpin->tcp_code & TCPF_FIN)
datalen++;
ptcpout->tcp_ack = ptcpin->tcp_seq + datalen;
ptcpout->tcp_offset = TCPHOFFSET;
ptcpout->tcp_window = ptcpout->tcp_urgptr = 0;
tcph2net(ptcpout);
ptcpout->tcp_cksum = 0;
ptcpout->tcp_cksum = tcpcksum(pepout, TCPMHLEN);
TcpOutSegs++;
return ipsend(pipin->ip_src, pepout, TCPMHLEN, IPT_TCP,
IPP_NORMAL, IP_TTL);
}
@
1.1
log
@Initial revision
@
text
@d25 2
a26 2
blkcopy(pipout->ip_src, pipin->ip_dst, IP_ALEN);
blkcopy(pipout->ip_dst, pipin->ip_src, IP_ALEN);
d48 1
a48 1
ptcpout->tcp_cksum = tcpcksum(pipout);
@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?