4 * Transmission Control Protocol, outgoing traffic
6 * The output functions of TCP.
11 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
17 * 1. Redistributions of source code must retain the above copyright notice,
18 * this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright notice,
20 * this list of conditions and the following disclaimer in the documentation
21 * and/or other materials provided with the distribution.
22 * 3. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
28 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
36 * This file is part of the lwIP TCP/IP stack.
38 * Author: Adam Dunkels <adam@sics.se>
47 #include "lwip/memp.h"
49 #include "lwip/ip_addr.h"
50 #include "lwip/netif.h"
51 #include "lwip/inet.h"
53 #include "lwip/stats.h"
54 #include "lwip/snmp.h"
58 /* Forward declarations.*/
59 static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
62 tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags)
64 /* no data, no length, flags, copy=1, no optdata, no optdatalen */
65 return tcp_enqueue(pcb, NULL, 0, flags, 1, NULL, 0);
69 * Write data for sending (but does not send it immediately).
71 * It waits in the expectation of more data being sent soon (as
72 * it can send them more efficiently by combining them together).
73 * To prompt the system to send data now, call tcp_output() after
74 * calling tcp_write().
76 * @arg pcb Protocol control block of the TCP connection to enqueue data for.
82 tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t copy)
84 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, arg=%p, len=%"U16_F", copy=%"U16_F")\n", (void *)pcb,
85 arg, len, (u16_t)copy));
86 /* connection is in valid state for data transmission? */
87 if (pcb->state == ESTABLISHED ||
88 pcb->state == CLOSE_WAIT ||
89 pcb->state == SYN_SENT ||
90 pcb->state == SYN_RCVD) {
92 return tcp_enqueue(pcb, (void *)arg, len, 0, copy, NULL, 0);
96 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | DBG_STATE | 3, ("tcp_write() called in invalid state\n"));
102 * Enqueue either data or TCP options (but not both) for tranmission
106 * @arg pcb Protocol control block for the TCP connection to enqueue data for.
107 * @arg arg Pointer to the data to be enqueued for sending.
108 * @arg len Data length in bytes
110 * @arg copy 1 if data must be copied, 0 if data is non-volatile and can be
116 tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
117 u8_t flags, u8_t copy,
118 u8_t *optdata, u8_t optlen)
121 struct tcp_seg *seg, *useg, *queue;
127 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_enqueue(pcb=%p, arg=%p, len=%"U16_F", flags=%"X16_F", copy=%"U16_F")\n",
128 (void *)pcb, arg, len, (u16_t)flags, (u16_t)copy));
129 LWIP_ASSERT("tcp_enqueue: len == 0 || optlen == 0 (programmer violates API)",
130 len == 0 || optlen == 0);
131 LWIP_ASSERT("tcp_enqueue: arg == NULL || optdata == NULL (programmer violates API)",
132 arg == NULL || optdata == NULL);
133 /* fail on too much data */
134 if (len > pcb->snd_buf) {
135 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too much data (len=%"U16_F" > snd_buf=%"U16_F")\n", len, pcb->snd_buf));
\r
141 /* seqno will be the sequence number of the first segment enqueued
142 * by the call to this function. */
143 seqno = pcb->snd_lbb;
145 LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: queuelen: %"U16_F"\n", (u16_t)pcb->snd_queuelen));
147 /* If total number of pbufs on the unsent/unacked queues exceeds the
148 * configured maximum, return an error */
149 queuelen = pcb->snd_queuelen;
150 if (queuelen >= TCP_SND_QUEUELEN) {
151 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too long queue %"U16_F" (max %"U16_F")\n", queuelen, TCP_SND_QUEUELEN));
\r
152 TCP_STATS_INC(tcp.memerr);
156 LWIP_ASSERT("tcp_enqueue: pbufs on queue => at least one queue non-empty",
157 pcb->unacked != NULL || pcb->unsent != NULL);
159 LWIP_ASSERT("tcp_enqueue: no pbufs on queue => both queues empty",
160 pcb->unacked == NULL && pcb->unsent == NULL);
163 /* First, break up the data into segments and tuck them together in
164 * the local "queue" variable. */
165 useg = queue = seg = NULL;
167 while (queue == NULL || left > 0) {
169 /* The segment length should be the MSS if the data to be enqueued
170 * is larger than the MSS. */
171 seglen = left > pcb->mss? pcb->mss: left;
173 /* Allocate memory for tcp_seg, and fill in fields. */
174 seg = memp_malloc(MEMP_TCP_SEG);
176 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for tcp_seg\n"));
\r
182 /* first segment of to-be-queued data? */
186 /* subsequent segments of to-be-queued data */
188 /* Attach the segment to the end of the queued segments */
189 LWIP_ASSERT("useg != NULL", useg != NULL);
192 /* remember last segment of to-be-queued data for next iteration */
195 /* If copy is set, memory should be allocated
196 * and data copied into pbuf, otherwise data comes from
197 * ROM or other static memory, and need not be copied. If
198 * optdata is != NULL, we have options instead of data. */
201 if (optdata != NULL) {
202 if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) {
206 seg->dataptr = seg->p->payload;
208 /* copy from volatile memory? */
210 if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_RAM)) == NULL) {
211 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue : could not allocate memory for pbuf copy size %"U16_F"\n", seglen));
\r
216 memcpy(seg->p->payload, ptr, seglen);
218 seg->dataptr = seg->p->payload;
220 /* do not copy data */
222 /* First, allocate a pbuf for holding the data.
223 * since the referenced data is available at least until it is sent out on the
224 * link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM
225 * instead of PBUF_REF here.
227 if ((p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_ROM)) == NULL) {
228 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n"));
\r
232 /* reference the non-volatile payload data */
236 /* Second, allocate a pbuf for the headers. */
237 if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM)) == NULL) {
238 /* If allocation fails, we have to deallocate the data pbuf as
241 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for header pbuf\n"));
\r
246 /* Concatenate the headers and data pbufs together. */
247 pbuf_cat(seg->p/*header*/, p/*data*/);
251 /* Now that there are more segments queued, we check again if the
252 length of the queue exceeds the configured maximum. */
253 if (queuelen > TCP_SND_QUEUELEN) {
254 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: queue too long %"U16_F" (%"U16_F")\n", queuelen, TCP_SND_QUEUELEN));
\r
260 /* build TCP header */
261 if (pbuf_header(seg->p, TCP_HLEN)) {
262 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n"));
\r
263 TCP_STATS_INC(tcp.err);
266 seg->tcphdr = seg->p->payload;
267 seg->tcphdr->src = htons(pcb->local_port);
268 seg->tcphdr->dest = htons(pcb->remote_port);
269 seg->tcphdr->seqno = htonl(seqno);
270 seg->tcphdr->urgp = 0;
271 TCPH_FLAGS_SET(seg->tcphdr, flags);
272 /* don't fill in tcphdr->ackno and tcphdr->wnd until later */
274 /* Copy the options into the header, if they are present. */
275 if (optdata == NULL) {
276 TCPH_HDRLEN_SET(seg->tcphdr, 5);
279 TCPH_HDRLEN_SET(seg->tcphdr, (5 + optlen / 4));
280 /* Copy options into data portion of segment.
281 Options can thus only be sent in non data carrying
282 segments such as SYN|ACK. */
283 memcpy(seg->dataptr, optdata, optlen);
285 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | DBG_TRACE, ("tcp_enqueue: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n",
286 ntohl(seg->tcphdr->seqno),
287 ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg),
292 ptr = (void *)((u8_t *)ptr + seglen);
295 /* Now that the data to be enqueued has been broken up into TCP
296 segments in the queue variable, we add them to the end of the
297 pcb->unsent queue. */
298 if (pcb->unsent == NULL) {
302 for (useg = pcb->unsent; useg->next != NULL; useg = useg->next);
304 /* { useg is last segment on the unsent queue, NULL if list is empty } */
306 /* If there is room in the last pbuf on the unsent queue,
307 chain the first pbuf on the queue together with that. */
309 TCP_TCPLEN(useg) != 0 &&
310 !(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) &&
311 !(flags & (TCP_SYN | TCP_FIN)) &&
312 /* fit within max seg size */
313 useg->len + queue->len <= pcb->mss) {
314 /* Remove TCP header from first segment of our to-be-queued list */
315 pbuf_header(queue->p, -TCP_HLEN);
316 pbuf_cat(useg->p, queue->p);
317 useg->len += queue->len;
318 useg->next = queue->next;
320 LWIP_DEBUGF(TCP_OUTPUT_DEBUG | DBG_TRACE | DBG_STATE, ("tcp_enqueue: chaining segments, new len %"U16_F"\n", useg->len));
324 memp_free(MEMP_TCP_SEG, queue);
329 /* initialize list with this segment */
332 /* enqueue segment */
337 if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
344 /* update number of segments on the queues */
345 pcb->snd_queuelen = queuelen;
346 LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %"S16_F" (after enqueued)\n", pcb->snd_queuelen));
347 if (pcb->snd_queuelen != 0) {
348 LWIP_ASSERT("tcp_enqueue: valid queue length",
349 pcb->unacked != NULL || pcb->unsent != NULL);
352 /* Set the PSH flag in the last segment that we enqueued, but only
353 if the segment has data (indicated by seglen > 0). */
354 if (seg != NULL && seglen > 0 && seg->tcphdr != NULL) {
355 TCPH_SET_FLAG(seg->tcphdr, TCP_PSH);
360 TCP_STATS_INC(tcp.memerr);
363 tcp_segs_free(queue);
365 if (pcb->snd_queuelen != 0) {
366 LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
367 pcb->unsent != NULL);
369 LWIP_DEBUGF(TCP_QLEN_DEBUG | DBG_STATE, ("tcp_enqueue: %"S16_F" (with mem err)\n", pcb->snd_queuelen));
\r
373 /* find out what we can send and send it */
375 tcp_output(struct tcp_pcb *pcb)
378 struct tcp_hdr *tcphdr;
379 struct tcp_seg *seg, *useg;
383 #endif /* TCP_CWND_DEBUG */
385 /* First, check if we are invoked by the TCP input processing
386 code. If so, we do not output anything. Instead, we rely on the
387 input processing code to call us when input processing is done
389 if (tcp_input_pcb == pcb) {
393 wnd = LWIP_MIN(pcb->snd_wnd, pcb->cwnd);
397 /* useg should point to last segment on unacked queue */
400 for (; useg->next != NULL; useg = useg->next);
403 /* If the TF_ACK_NOW flag is set and no data will be sent (either
404 * because the ->unsent queue is empty or because the window does
405 * not allow it), construct an empty ACK segment and send it.
407 * If data is to be sent, we will just piggyback the ACK (see below).
409 if (pcb->flags & TF_ACK_NOW &&
411 ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) {
412 p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
414 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
417 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: sending ACK for %"U32_F"\n", pcb->rcv_nxt));
418 /* remove ACK flags from the PCB, as we send an empty ACK now */
419 pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
422 tcphdr->src = htons(pcb->local_port);
423 tcphdr->dest = htons(pcb->remote_port);
424 tcphdr->seqno = htonl(pcb->snd_nxt);
425 tcphdr->ackno = htonl(pcb->rcv_nxt);
426 TCPH_FLAGS_SET(tcphdr, TCP_ACK);
427 tcphdr->wnd = htons(pcb->rcv_wnd);
429 TCPH_HDRLEN_SET(tcphdr, 5);
433 tcphdr->chksum = inet_chksum_pseudo(p, &(pcb->local_ip), &(pcb->remote_ip),
434 IP_PROTO_TCP, p->tot_len);
436 ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
445 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", (void*)pcb->unsent));
447 #endif /* TCP_OUTPUT_DEBUG */
450 LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U32_F", cwnd %"U16_F", wnd %"U32_F", seg == NULL, ack %"U32_F"\n",
451 pcb->snd_wnd, pcb->cwnd, wnd,
454 LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U32_F", cwnd %"U16_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n",
455 pcb->snd_wnd, pcb->cwnd, wnd,
456 ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len,
457 ntohl(seg->tcphdr->seqno), pcb->lastack));
459 #endif /* TCP_CWND_DEBUG */
460 /* data available and window allows it to be sent? */
461 while (seg != NULL &&
462 ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) {
464 LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U32_F", cwnd %"U16_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n",
465 pcb->snd_wnd, pcb->cwnd, wnd,
466 ntohl(seg->tcphdr->seqno) + seg->len -
468 ntohl(seg->tcphdr->seqno), pcb->lastack, i));
470 #endif /* TCP_CWND_DEBUG */
472 pcb->unsent = seg->next;
474 if (pcb->state != SYN_SENT) {
475 TCPH_SET_FLAG(seg->tcphdr, TCP_ACK);
476 pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
479 tcp_output_segment(seg, pcb);
480 pcb->snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg);
481 if (TCP_SEQ_LT(pcb->snd_max, pcb->snd_nxt)) {
482 pcb->snd_max = pcb->snd_nxt;
484 /* put segment on unacknowledged list if length > 0 */
485 if (TCP_TCPLEN(seg) > 0) {
487 /* unacked list is empty? */
488 if (pcb->unacked == NULL) {
491 /* unacked list is not empty? */
493 /* In the case of fast retransmit, the packet should not go to the tail
494 * of the unacked queue, but rather at the head. We need to check for
495 * this case. -STJ Jul 27, 2004 */
496 if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))){
497 /* add segment to head of unacked list */
498 seg->next = pcb->unacked;
501 /* add segment to tail of unacked list */
506 /* do not queue empty segments on the unacked list */
516 * Actually send a TCP segment over IP
519 tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
524 /** @bug Exclude retransmitted segments from this count. */
525 snmp_inc_tcpoutsegs();
527 /* The TCP header has already been constructed, but the ackno and
528 wnd fields remain. */
529 seg->tcphdr->ackno = htonl(pcb->rcv_nxt);
531 /* silly window avoidance */
532 if (pcb->rcv_wnd < pcb->mss) {
533 seg->tcphdr->wnd = 0;
535 /* advertise our receive window size in this TCP segment */
536 seg->tcphdr->wnd = htons(pcb->rcv_wnd);
539 /* If we don't have a local IP address, we get one by
540 calling ip_route(). */
541 if (ip_addr_isany(&(pcb->local_ip))) {
542 netif = ip_route(&(pcb->remote_ip));
546 ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
551 if (pcb->rttest == 0) {
552 pcb->rttest = tcp_ticks;
553 pcb->rtseq = ntohl(seg->tcphdr->seqno);
555 LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq));
557 LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n",
558 htonl(seg->tcphdr->seqno), htonl(seg->tcphdr->seqno) +
561 len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload);
564 seg->p->tot_len -= len;
566 seg->p->payload = seg->tcphdr;
568 seg->tcphdr->chksum = 0;
570 seg->tcphdr->chksum = inet_chksum_pseudo(seg->p,
573 IP_PROTO_TCP, seg->p->tot_len);
575 TCP_STATS_INC(tcp.xmit);
577 ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
582 tcp_rst(u32_t seqno, u32_t ackno,
583 struct ip_addr *local_ip, struct ip_addr *remote_ip,
584 u16_t local_port, u16_t remote_port)
587 struct tcp_hdr *tcphdr;
588 p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
590 LWIP_DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n"));
595 tcphdr->src = htons(local_port);
596 tcphdr->dest = htons(remote_port);
597 tcphdr->seqno = htonl(seqno);
598 tcphdr->ackno = htonl(ackno);
599 TCPH_FLAGS_SET(tcphdr, TCP_RST | TCP_ACK);
600 tcphdr->wnd = htons(TCP_WND);
602 TCPH_HDRLEN_SET(tcphdr, 5);
606 tcphdr->chksum = inet_chksum_pseudo(p, local_ip, remote_ip,
607 IP_PROTO_TCP, p->tot_len);
609 TCP_STATS_INC(tcp.xmit);
610 snmp_inc_tcpoutrsts();
611 /* Send output with hardcoded TTL since we have no access to the pcb */
612 ip_output(p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP);
614 LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno));
617 /* requeue all unacked segments for retransmission */
619 tcp_rexmit_rto(struct tcp_pcb *pcb)
623 if (pcb->unacked == NULL) {
627 /* Move all unacked segments to the head of the unsent queue */
628 for (seg = pcb->unacked; seg->next != NULL; seg = seg->next);
629 /* concatenate unsent queue after unacked queue */
630 seg->next = pcb->unsent;
631 /* unsent queue is the concatenated queue (of unacked, unsent) */
632 pcb->unsent = pcb->unacked;
633 /* unacked queue is now empty */
636 pcb->snd_nxt = ntohl(pcb->unsent->tcphdr->seqno);
637 /* increment number of retransmissions */
640 /* Don't take any RTT measurements after retransmitting. */
643 /* Do the actual retransmission */
648 tcp_rexmit(struct tcp_pcb *pcb)
652 if (pcb->unacked == NULL) {
656 /* Move the first unacked segment to the unsent queue */
657 seg = pcb->unacked->next;
658 pcb->unacked->next = pcb->unsent;
659 pcb->unsent = pcb->unacked;
662 pcb->snd_nxt = ntohl(pcb->unsent->tcphdr->seqno);
666 /* Don't take any rtt measurements after retransmitting. */
669 /* Do the actual retransmission. */
670 snmp_inc_tcpretranssegs();
677 tcp_keepalive(struct tcp_pcb *pcb)
680 struct tcp_hdr *tcphdr;
682 LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
683 ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
684 ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
686 LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt %"U16_F"\n", tcp_ticks, pcb->tmr, pcb->keep_cnt));
688 p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
691 LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: could not allocate memory for pbuf\n"));
696 tcphdr->src = htons(pcb->local_port);
697 tcphdr->dest = htons(pcb->remote_port);
698 tcphdr->seqno = htonl(pcb->snd_nxt - 1);
699 tcphdr->ackno = htonl(pcb->rcv_nxt);
700 tcphdr->wnd = htons(pcb->rcv_wnd);
702 TCPH_HDRLEN_SET(tcphdr, 5);
706 tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip, IP_PROTO_TCP, p->tot_len);
708 TCP_STATS_INC(tcp.xmit);
710 /* Send output to IP */
711 ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
715 LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_keepalive: seqno %"U32_F" ackno %"U32_F".\n", pcb->snd_nxt - 1, pcb->rcv_nxt));
718 #endif /* LWIP_TCP */