void tcp_send(UINT flags, UINT hdr_len, UCHAR nr) { ULONG idata sum, dest; UINT idata result; UCHAR xdata * outbuf; TCP_HEADER xdata * tcp; IP_HEADER xdata * ip; outbuf = outbuf1; tcp = (TCP_HEADER xdata *)(outbuf + 34); ip = (IP_HEADER xdata *)(outbuf + 14);
if (nr == NO_CONNECTION) { tcp->source_port = HTTP_PORT; tcp->dest_port = sender_tcpport; tcp->sequence = 0; tcp->ack_number = 0; dest = sender_ipaddr; } else if (nr < 5) { // This message is to connected port tcp->source_port = HTTP_PORT; tcp->dest_port = conxn[nr].port; tcp->sequence = conxn[nr].my_sequence; tcp->ack_number = conxn[nr].his_sequence; dest = conxn[nr].ipaddr; } else {
return; }
tcp->flags = (hdr_len << 10) | flags; //????????????? tcp->window = 1024; tcp->checksum = 0; tcp->urgent_ptr = 0; if (hdr_len == 28) { memcpy(&tcp->options, opt, 8); } ip->dest_ipaddr = dest; ip->source_ipaddr = my_ipaddr;
sum = (ULONG)cksum(outbuf + 26, 8 + hdr_len);
sum += (ULONG)0x0006; sum += (ULONG)hdr_len;
result = (UINT)(sum + (sum >> 16)); tcp->checksum = ~result; ip_send(outbuf, dest, TCP_TYPE, hdr_len);
conxn[nr].timer = TCP_TIMEOUT; } 我觉得这个程序没有把TCP信息封装到IP层去,不知道正确与否,请大家指正
|