Opened 15 years ago

Closed 6 years ago

Last modified 5 years ago

#4923 closed bug (fixed)

netcat cuts off ending of stream

Reported by: Adek336 Owned by: nobody
Priority: normal Milestone: R1/beta2
Component: Applications/Command Line Tools Version: R1/alpha1
Keywords: Cc: planche2k@…
Blocked By: Blocking:
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 (6)

comment:1 by andreasf, 15 years ago

Cc: planche2k@… added

comment:2 by Adek336, 15 years ago

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 by Adek336, 15 years ago

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 by pulkomandy, 10 years ago

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

comment:5 by waddlesplash, 6 years ago

Resolution: fixed
Status: newclosed

No reply in 4 years, assuming indeed fixed.

comment:6 by nielx, 5 years ago

Milestone: R1R1/beta2

Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone

Note: See TracTickets for help on using tickets.