Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Sep 2001 10:30:56 -0700 (PDT)
From:      Brad Knotwell <knotwell@ix.netcom.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/30634: kevent.data value incorrect for UDP sockets
Message-ID:  <200109171730.f8HHUub00713@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         30634
>Category:       kern
>Synopsis:       kevent.data value incorrect for UDP sockets
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 17 10:40:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Brad Knotwell
>Release:        4.2
>Organization:
home
>Environment:
FreeBSD freebsd 4.2-RELEASE FreeBSD 4.2-RELEASE #3: Thu Jul 19
     root@freebsd:/usr/src/sys/compile/ALPHA-SVR  i386

>Description:
When kevent returns a read event for a UDP socket, the data field (AKA the number of bytes to be read) is 16 bytes too long.

NOTE:  the problem exists in 4.3 release as well.

>How-To-Repeat:
1)  Compile up the following discard server 
2)  Run nc -u 127.0.0.1 6060
3)  Send data to netcat and watch the server's output

It should be consistently off by sixteen bytes.  NOTE:  this may be a documentation bug and "the number of bytes in the socket buffer" needs to be explained further.   

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/event.h>

/* loopback discardserver on port 6060 */
int main(void)
{
    int queue,sock;
    struct sockaddr_in saddr;
    struct kevent evt;

    memset(&saddr,0,sizeof(struct sockaddr_in));
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(6060);
    saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    memset(&evt,0,sizeof(struct kevent));
    evt.filter = EVFILT_READ;
    evt.flags =  EV_ADD;

    if(((queue = kqueue()) == -1) ||
       ((evt.ident = (sock = socket(AF_INET,SOCK_DGRAM,0))) == -1) ||
       (bind(sock,(struct sockaddr *)&saddr,sizeof saddr)) ||
       (kevent(queue,&evt,1,NULL,0,NULL)))
        return(fprintf(stderr,"bad setup\n"),EXIT_FAILURE);

    while(1){
        char *buf;

        if((kevent(queue,NULL,0,&evt,1,NULL) == -1) ||
           (!evt.data))
            break;

        if((buf = malloc(evt.data)) == NULL) continue;

        recv(sock,buf,evt.data,0);
        printf("size to read(%d) : data : %s\n",evt.data,buf);

        free(buf);
    }

    return(EXIT_SUCCESS);
}

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200109171730.f8HHUub00713>