Opened 10 years ago

Closed 7 months ago

#4923 closed bug (fixed)

netcat cuts off ending of stream

Reported by: Adek336 Owned by: nobody
Priority: normal Milestone: R1
Component: Applications/Command Line Tools Version: R1/alpha1
Keywords: Cc: planche2k@…
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

On a computer running Linux

seq 1 100000 | nc -lp2222 -q1

On the Haiku computer

nc other-computer's-ip 2222 | less

and then go to line 99900 using the key sequence

:99900

Unfortunately, as we can see in less' output, Haiku's netcat is able to output only about 99850 lines out of the 100000 that have been sent.

If not reproducible, increase argument to seq.

If both instances of netcat are run on Linux boxen, all 100000 lines are output.

Change History (5)

comment:1 Changed 10 years ago by andreasf

Cc: planche2k@… added

comment:2 Changed 10 years ago by Adek336

Program writing hexadecimals to hostn:2345.

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


int
main()
{
	int    sock;
	struct sockaddr_in server;
	struct hostent *hp;

	sock = socket (PF_INET, SOCK_STREAM, 0);
	if (sock < 0)
		exit(1);

	const char *hostn = "192.168.1.100";
	hp = gethostbyname (hostn);
	if (hp == NULL)
		exit(1);

	server.sin_family = AF_INET;
	memcpy ((char *) &server.sin_addr, (char *) hp->h_addr, hp->h_length);
	server.sin_port = htons (2345);

	if (connect (sock, (struct sockaddr *) &server, sizeof server) < 0)
		exit(1);

	int u = 0;

	do
	{
		char line[1000];
		snprintf(line, 1000, "%07x\n", ++ u);

		size_t sent = 0;
		size_t to_send = strlen(line);
		while (sent < to_send)
		{
			int w = write(sock, line + sent, to_send - sent);
			if (w == 0)
				break;
			if (w == -1)
				break;
			int j;
			//for (j = sent; j < sent+w; ++j)
			//printf("%c", line[j]);
			sent += w;
		}
	}
	while (u < 0x01000000);

	close (sock);

	return 0;
}

Change hostn; compile the program under Haiku; run nc -lp2345 on a linux box; run the program under Haiku. We observe that netcat receives lines of seven digit, zero padded hexadecimals. After a while, netcat starts to print only the three least significant digits of the numbers it should receive. Does not happen if the client program is run on linux. Reproducible with Haiku, under VirtualBox, hrev34335 hybr2.

Additionally, if I create the file a.c with the contents of int main() { } and run the command while true; do gcc a.c; done in the background, the stream seems to get corrupted sooner.

comment:3 Changed 9 years ago by Adek336

Another test case: tested with hrev35350, VirtualBox 3.1, Haiku guest Linux host: start ssh server on Haiku. Try to connect to the ssh server from the host. Sometimes - not always - fails - either connection reset errors, or ssh_authentication errors.

comment:4 Changed 5 years ago by pulkomandy

Can't reproduce here, can you still make it happen?

comment:5 Changed 7 months ago by waddlesplash

Resolution: fixed
Status: newclosed

No reply in 4 years, assuming indeed fixed.

Note: See TracTickets for help on using tickets.