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: Ognyan Kulev
Subject: Re: Bug#187391: PortingIssues sockaddr_un
Date: Sun, 13 Apr 2003 16:19:53 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030327 Debian/1.3-4

Robert Millan wrote:
On Mon, Apr 07, 2003 at 04:48:07PM +0300, Ognyan Kulev wrote:
>
SUN_LEN macro is not defined in The Single UNIX Specification Version 3 (see sys/un.h manpage).

we're talking about Glibc, which may or may not adhere to standards, but
has its own way of doing this.

Yes, what I had written was _portability_ issue but not _porting_ issue. I've removed SUN_LEN definition from the page.

this is wrong, there is no garantee that "/path/to/socket" isn't longer
than 108 chars, then su.sun_path would overflow.

Now I've made it clear in the page that this example is about constant C string that one is sure to be of length no longer than 100.

according to the Glibc docs, sun_path is not defined by SUN_LEN, but
has a fixed length of 108 chars.

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").

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

#define FN_MAX  300

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

int
main (void)
{
  char filename[FN_MAX];
  int sock;
  struct sockaddr_un *su;
  int i;

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

  strcpy (filename, "/tmp/");
  for (i = 0; i < 200; i++)
    strcat (filename, "x");
  printf ("%s\n", filename);

  su = alloca (offsetof (struct sockaddr_un, sun_path)
               + strlen (filename) + 1);
  su->sun_family = AF_LOCAL;
  strcpy (su->sun_path, filename);
  if (bind (sock, (struct sockaddr *)su, SUN_LEN (su)))
    fatal ("bind");

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

  return EXIT_SUCCESS;
}

Regards
--
Ognyan Kulev <ogi@fmi.uni-sofia.bg>, "\"Programmer\""





reply via email to

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