[191] in linux-net channel archive
UDP read problem
daemon@ATHENA.MIT.EDU (Kenneth Wong)
Tue Apr 11 03:40:41 1995
Date: Tue, 11 Apr 1995 14:19:45 +0800 (HKT)
From: Kenneth Wong <ypwong@ie.cuhk.hk>
To: linux-net@vger.rutgers.edu
I found that if a process sends continually, the receiving end sometimes will
be said to have read more that what it asks for, though the extra bytes
are not filled into the given buffer, just discarded.
The above happens with 1.2.0 on loopback (I still can't compile higher
versions, since the NCR SCSI files cannot be assembled, with perl4 or perl5).
Also, I just tried this on Solaris 2.3 and it is ok.
Is there anything wrong? I am new to this, so maybe there is an option
that I missed or something. Any suggestions appreciated.
PS the following codes sends 9000 bytes continually and the other end
gets 256 bytes each time, but is told it has 9000. The buffer in th
received buffer suggests that the bytes after the first 256 are dropped.
Kenneth Wong, Year 4/4, Information Engineering, The Chinese University of HK
Email: ypwong@ie.cuhk.hk WWW: <a href=http://www.ie.cuhk.hk/~ypwong/>here</a>
--cli.c--
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/inet.h>
void
main ()
{
struct sockaddr_in cli, serv;
int sock, out;
char buf[9000];
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr ("127.0.0.1");
serv.sin_port = htons (1505);
if ((sock = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
exit (1);
cli.sin_family = AF_INET;
cli.sin_addr.s_addr = htonl (INADDR_ANY);
cli.sin_port = htons (0);
memset (buf, '!', 256);
memset (buf + 256, 'x', 9000 - 256);
if (bind (sock, (struct sockaddr *) &cli, sizeof (cli)) < 0)
exit (1);
for (;;)
out = sendto (sock, buf, 9000, 0, (struct sockaddr *) &serv, sizeof (serv));
close (sock);
}
--ser.c--
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/inet.h>
void
main ()
{
struct sockaddr_in serv;
int sock, out = 0;
char buf[9000];
memset (&serv, 0, sizeof (serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr ("127.0.0.1");
serv.sin_port = htons (1505);
if ((sock = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
perror ("socket");
if (bind (sock, (struct sockaddr *) &serv, sizeof (serv)) < 0)
perror ("bind");
for (;;)
{
out = read (sock, buf, 256);
printf ("out=%d,%c\n", out, buf[0]);
}
close (sock);
}