This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: 1.3.13-2 & 1.3.14-1 problem on read() from dgram socket
- From: "Takashi Yano" <yano at crl dot hitachi dot co dot jp>
- To: <cygwin at cygwin dot com>
- Cc: <yano at crl dot hitachi dot co dot jp>
- Date: Fri, 1 Nov 2002 15:23:37 +0900
- Subject: Re: 1.3.13-2 & 1.3.14-1 problem on read() from dgram socket
- References: <4.3.1.2.20021031085716.01747658@pop.rcn.com>
To reproduce this problem, please try next test cases.
Thank you.
Test Case 1:
- Environment: cygwin 1.3.13-2 or 1.3.14-1 under Windows 2000 or XP
- Setup inetutils and start "CYGWIN inetd"
- Send udp packet to port 9 of localhost
- Result: System load will goes up to full load.
Test Case 2:
- Environment: cygwin 1.3.13-2 or 1.3.14-1 under Windows 2000 or XP
- Compile following source; "server.c"
- Execute "server" to wait for udp packets.
- Result: "server" cause an error on read(). ( Bad Address).
- Environment: cygwin 1.3.12-2 under Windows 2000 or XP
- Compile following source; "server.c" and "client.c"
- Execute "server" to wait for udp packets.
- Execute "client" to throw a udp packet.
- Result: "server" receives upd packet correctly.
---------------------------------------------------------------
/* server.c */
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define PORT 13000
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
#define USE_READ 1
char buf[BUFSIZ];
int main(int argc, char *argv[])
{
int skt_serv;
struct sockaddr_in sin;
/* Open Socket */
skt_serv = socket( PF_INET, SOCK_DGRAM, 0);
if ( skt_serv < 0 ) {
fprintf( stderr, "Cannot open SOCKET.\n");
exit(-1);
}
/* Setup socket */
memset( &sin, 0, sizeof( sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons( PORT);
if ( bind( skt_serv, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
fprintf( stderr, "Cannot bind SOCKET for port %d.\n", PORT);
shutdown( skt_serv, 2);
exit(-1);
}
/* Read Datagram */
for ( ;;) {
int len;
#ifdef USE_READ
len = read( skt_serv, buf, BUFSIZ); /* This call fails on
cygwin 1.3.13-2 & 1.3.14-1 */
#else
len = recv( skt_serv, buf, BUFSIZ, 0); /* works fine */
#endif
if (len < 0) {
#ifdef USE_READ
perror( "read()");
#else
perror( "recv()");
#endif
break;
}
printf("[%d bytes received]\n", len);
fwrite( buf, len, 1, stdout);
}
shutdown( skt_serv, 2);
return 0;
}
---------------------------------------------------------------
/* client.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define PORT 13000
#define TARGET_STR "127.0.0.1"
#define SEND_STR "TEST\n"
int main(int argc, char *argv[])
{
int skt_target;
struct sockaddr_in sin;
/* Open Socket */
skt_target = socket( PF_INET, SOCK_DGRAM, 0);
if ( skt_target < 0 ) {
fprintf( stderr, "Cannot open SOCKET.\n");
exit(-1);
}
/* Set Target Address */
memset( &sin, 0, sizeof( sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr( TARGET_STR);
sin.sin_port = htons( PORT);
/* Send UDP packet */
sendto( skt_target, SEND_STR, strlen(SEND_STR), 0,
(struct sockaddr*)&sin, sizeof(sin));
shutdown( skt_target, 2);
return 0;
}
---------------------------------------------------------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/