Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2002 14:10:12 -0400
From:      "kfl" <kfl@xiphos.ca>
To:        "freebsd - net" <freebsd-net@FreeBSD.org>
Subject:   T/TCP and FreeBSD 4.5
Message-ID:  <JCEDLMKGMLLELHAJNIHJCEBJDGAA.kfl@xiphos.ca>

next in thread | raw e-mail | index | archive | help
Hi,

I'm having a problem using TCP for transaction in FreeBSd 4.5. Here's a
trace from tcpdump and the code I'm using.
Also, from the dump you can see that rfc1644 is on ;)

Problem: (At 12:41:05.626586, the ack should also ack the data sent with the
SYN.)

Any hints on what could be wrong?

Regards,

Karim Fodil-Lemelin
Xiphos Technologies Inc.

uname -a:
cartman.xiphos.ca 4.5-RELEASE FreeBSD 4.5-RELEASE #0: Mon Jan 28 14:31:56
GMT 2002 murray@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC i386

TRACE:

12:41:05.626087 cartman.xiphos.ca.1029 > ratbert.xiphos.ca.8888: SFP
361776143:361776543(400) win 65535 <mss 1460,nop,wscale 1,nop,nop,timestamp
145150 0,nop,nop,cc 7> (DF)

12:41:05.626293 ratbert.xiphos.ca.8888 > cartman.xiphos.ca.1029: S
1733428688:1733428688(0) ack 361776144 win 65535 <mss 1460,nop,wscale
1,nop,nop,timestamp 143990 145150,nop,nop,cc 6,nop,nop,ccecho 7>

12:41:05.626451 cartman.xiphos.ca.1029 > ratbert.xiphos.ca.8888: F
361776544:361776544(0) ack 1733428689 win 33120 <nop,nop,timestamp 145150
143990,nop,nop,cc 7> (DF)

12:41:05.626586 ratbert.xiphos.ca.8888 > cartman.xiphos.ca.1029: . ack
361776144 win 33120 <nop,nop,timestamp 143990 145150,nop,nop,cc 6> (DF)

12:41:06.625726 cartman.xiphos.ca.1029 > ratbert.xiphos.ca.8888: FP
361776144:361776544(400) ack 1733428689 win 33120 <nop,nop,timestamp 145250
143990,nop,nop,cc 7> (DF)

12:41:06.625831 ratbert.xiphos.ca.8888 > cartman.xiphos.ca.1029: . ack
361776545 win 32920 <nop,nop,timestamp 144090 145250,nop,nop,cc 6> (DF)

12:41:06.626626 ratbert.xiphos.ca.8888 > cartman.xiphos.ca.1029: FP
1733428689:1733429089(400) ack 361776545 win 33120 <nop,nop,timestamp 144090
145250,nop,nop,cc 6> (DF)

12:41:06.626818 cartman.xiphos.ca.1029 > ratbert.xiphos.ca.8888: . ack
1733429090 win 32920 <nop,nop,timestamp 145250 144090,nop,nop,cc 7> (DF)



INCLUDE FILE:

/* Common includes and defines for UDP, TCP, and T/TCP */

/* clients and servers */

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#define REQUEST 400 /* max size of request, in bytes */

#define REPLY 400 /* max size of reply, in bytes */

#define UDP_SERV_PORT 7777 /* UDP server's well-known port */

#define TCP_SERV_PORT 8888 /* TCP server's well-known port */

#define TTCP_SER_PORT 9999 /* T/TCP server's well-known port */

/* Following shortens all the type casts of pointer arguments */

#define SA struct sockaddr *

CLIENT:

int read_stream (int fd, char *ptr, int maxbytes)

{

int nleft, nread;

nleft = maxbytes;

while (nleft > 0) {

if ((nread = read(fd, ptr, nleft)) < 0)

return (nread); /* error return < 0 */

else if (nread == 0)

break; /* EOF, return #bytes read */

nleft -= nread;

ptr += nread;

}

return (maxbytes - nleft);

}

int main (int argc, char *argv[])

{

struct sockaddr_in serv;

struct hostent *host;

char request[REQUEST], reply[REPLY];

uint32_t ipAddr;

int sockfd, n;

int One = 1;

if (argc !=2) {

printf("usage: ttcpcli <IP address or name of server>\n");

exit(0);

}

if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {

printf("socket error\n");

exit(0);

}

memset(&serv, sizeof(serv), 0);

serv.sin_family = AF_INET;

serv.sin_port = htons(TCP_SERV_PORT);

if ((ipAddr = inet_addr(argv[1])) != -1) {

serv.sin_addr.s_addr = ipAddr;

}

else if ((host = gethostbyname(argv[1])) != NULL) {

bcopy((char *)host->h_addr, (char *)&serv.sin_addr, host->h_length);

}

else {

printf("unknown host\n");

exit(0);

}

/* form request */

strcpy(request, "This is a T/TCP payload");

setsockopt(sockfd, IPPROTO_TCP, TCP_NOPUSH, &One, sizeof (One));

if (sendto (sockfd, request, REQUEST, MSG_EOF, (SA)&serv, sizeof(serv)) !=
REQUEST) {

printf("sendto error\n");

exit(0);

}

if ((n = read_stream(sockfd, reply, REPLY)) < 0) {

printf("read error\n");

exit(0);

}

/* process "n" bytes of reply[] ... */

printf("received:%s\n", reply);

exit(0);

}



SERVER:

int read_stream (int fd, char *ptr, int maxbytes)

{

int nleft, nread;

nleft = maxbytes;

while (nleft > 0) {

if ((nread = read(fd, ptr, nleft)) < 0)

return (nread); /* error return < 0 */

else if (nread == 0)

break; /* EOF, return #bytes read */

nleft -= nread;

ptr += nread;

}

return (maxbytes - nleft);

}



int main ()

{

struct sockaddr_in serv, cli;

char request[REQUEST], reply[REPLY];

int listenfd, sockfd, n, clilen;

if ((listenfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {

printf("socket error\n");

exit(0);

}

memset(&serv, sizeof(serv), 0);

serv.sin_family = AF_INET;

serv.sin_port = htons(TCP_SERV_PORT);

serv.sin_addr.s_addr = htonl(INADDR_ANY);

if (bind(listenfd, (SA)&serv, sizeof(serv)) < 0) {

printf("bind error\n");

exit(0);

}

if (listen(listenfd, SOMAXCONN) < 0) {

printf("listen error\n");

exit(0);

}

for(;;) {

clilen = sizeof(cli);

if ((sockfd = accept(listenfd, (SA)&cli, &clilen)) < 0) {

printf("accept error\n");

exit(0);

}

if ((n = read_stream(sockfd, request, REQUEST)) < 0) {

printf("read error\n");

exit(0);

}

/* process "n" bytes of request[] and create reply[] ... */

printf("recevied:%s\n", request);

strcpy(reply, "Server response");

if (send(sockfd, reply, REPLY, MSG_EOF) != REPLY) {

printf("send error\n");

exit(0);

}

close(sockfd);

}

}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?JCEDLMKGMLLELHAJNIHJCEBJDGAA.kfl>