Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Feb 2010 14:25:03 GMT
From:      Axel Dörfler <axeld@pinc-software.de>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   standards/144231: bind/connect/sendto too strict about sockaddr length
Message-ID:  <201002231425.o1NEP3wQ077938@www.freebsd.org>
Resent-Message-ID: <201002231430.o1NEU1sq093182@freefall.freebsd.org>

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

>Number:         144231
>Category:       standards
>Synopsis:       bind/connect/sendto too strict about sockaddr length
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 23 14:30:01 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Axel Dörfler
>Release:        8.0-RELEASE
>Organization:
>Environment:
i386
>Description:
bind(), connect(), and sendto() all have a socklen_t argument specifying the size of the sockaddr buffer passed in.

However, with IPv4 at least, passing any other value than 16 (sizeof(sockaddr)) will result in EINVAL.

There is no reason why this restriction is there, and it's quite unhandy when dealing with the sockaddr_storage structure.

(I have not compiled the test program, but it should be able to reproduce the problem)

>How-To-Repeat:
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>

int
main()
{
  sockaddr_storage buffer;
  ((sockaddr_in*)&buffer)->sa_family = AF_INET;
  ((sockaddr_in*)&buffer)->sa_addr.s_addr = INADDR_ANY;
  ((sockaddr_in*)&buffer)->sa_port = 0;

  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (bind(fd, &buffer, sizeof(buffer)) != 0)
    perror("bind");

  return 0;
}

>Fix:


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



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