www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/11/01/01:24:15

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <007301c2816f$36d2c1d0$2a519085@crl.hitachi.co.jp>
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>
References: <4 DOT 3 DOT 1 DOT 2 DOT 20021031085716 DOT 01747658 AT pop DOT rcn DOT com>
Subject: Re: 1.3.13-2 & 1.3.14-1 problem on read() from dgram socket
Date: Fri, 1 Nov 2002 15:23:37 +0900
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019