bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#187391: PortingIssues sockaddr_un


From: Niels Möller
Subject: Re: Bug#187391: PortingIssues sockaddr_un
Date: 13 Apr 2003 22:07:32 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Ognyan Kulev <ogi@fmi.uni-sofia.bg> writes:

> I hope that the following example will convince you that in GNU/Hurd
> you are not limited to 108 characters.  It works on the Hurd, but
> fails on GNU/Linux with "Invalid argument").

Interesting, I didn't know linux had this silly limit. I've tried with
the below test program, which avoids the use of SUN_LEN, and which
demonstrates that NUL-termination is redundant, and that length up to
108 works fine. Tested on linux, where ./a.out 107 and ./a.out 108
works fine, but ./a.out 109 resultes in "bind: Invalid argument".

/Niels

----8<-------
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>

void
fatal (const char *where)
{
   perror (where);
   exit (EXIT_FAILURE);
}

int
main (int argc, char **argv)
{
   int sock;
   struct sockaddr_un *su;
   int length;
   socklen_t size;

   if (argc < 2)
     length = 200;
   else
     length = atoi(argv[1]);

   sock = socket (PF_LOCAL, SOCK_DGRAM, 0);
   if (sock < 0)
     fatal ("socket");

   size = offsetof (struct sockaddr_un, sun_path) + length;
   su = alloca (size + 1); /* One extra for the non-NUL termination */

   memcpy(su->sun_path, "/tmp/", 5);
   memset(su->sun_path + 5, 'x', length - 5);
   su->sun_path[length] = 'a'; /* No NUL-termination */

   su->sun_family = AF_LOCAL;

   if (bind (sock, (struct sockaddr *)su, size))
     fatal ("bind");

   if (close (sock))
     fatal ("close");

   return EXIT_SUCCESS;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]