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

Re: Porting Bind



 --- Roland McGrath <roland@frob.com> a écrit : 
> Please find the parts of the source code that are making these calls and
> give us some more detail about what they are doing.  This is a general
> request to anyone doing porting of miscellaneous code to the Hurd--posting
> that program's error output alone does not make it very easy for us to help
> you figure out the problem.

When I asked for advice aboutset sockopt(REUSEADDR) last time, I only pretended
to know if this option is working at this time in Hurd; anyway, I'll post
detailed information about this issue next time.      =) 

> setrlimit fails with ENOSYS with you try to set the hard limit (since we
> have no enforced limits).  Most programs only try to lower the soft limit,
> but named might have a good reason to want to set the hard limit (e.g. to
> constrain when a child process run under a non-root uid can do).
>
> Probably the right solution is to change setrlimit to claim success for
> setting hard limits in most cases.  But I'd like to see how this is used
> before deciding about that.

Thanks for your advice, it's very useful for me.    =)

> As to SO_REUSEADDR, that certainly ought to be there.  Please double-check

Yes, but as long as I prefer to do the easiest part first, I'll start fixing
the MAXHOSTNALELEN issue. To achieve this, I modified Neal's xgethostname.c to
add the hostnamecpy function; it copies a hostname to another string and
enforces hostname length limits. Is it correct? If so, is it fine to add it to
Neal's library, or is better to write it separately?  

cut here
------------------------------------------------------------------
--- /root/xgethostname/xgethostname/xgethostname.c	Fri Aug  3 04:04:40 2001+++
xgethostname.c	Sat Sep  1 14:22:40 2001
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
+#include <string.h>
 
 char *
 xgethostname (void)
@@ -102,6 +103,38 @@
 
   return buf;
 }
+
+
+int
+hostnamecpy (char *hostname, char **dest)
+{
+  int size = 0;
+  int maxlen = 0;
+  int hostnamelen = strlen (hostname);
+
+#ifdef MAXHOSTNAMELEN
+  size = MAXHOSTNAMELEN;
+  maxlen = 1;
+#else /* MAXHOSTNAMELEN */
+#ifdef _SC_HOST_NAME_MAX
+  size = sysconf (_SC_HOST_NAME_MAX);
+  maxlen = 1;
+#endif /* _SC_HOST_NAME_MAX */
+  if (size <= 0)
+    size = 255;
+#endif /* MAXHOSTNAMELEN */
+
+  if (maxlen && (hostnamelen > (size + 1)))
+    return ENAMETOOLONG;
+
+  *dest = malloc (hostnamelen + 1);
+  if (! dest)
+    return ENOMEM;
+
+  sprintf(*dest,"%s",hostname);
+  return 0;
+}
+
 
#ifdef WANT_TO_TEST_XGETHOSTNAME
#include <stdio.h>
------------------------------------------------------------------
cut here

This is the programs that checks hostnamecpy's function (sorry but again, I
can't send them as an attachment!):

cut here
------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "xgethostname.c"

int
main (int argc, char *argv[])
{
  char *hostname;
  int err;

  if (argc == 2)
    {
      err = hostnamecpy (argv[1],&hostname);
    }
  else
    {
      err = hostnamecpy ("",&hostname);
    }

  if (err)
    {
      switch (err) {

      case ENAMETOOLONG:
        printf("error: ENAMETOOLONG\n");
        break;
      case ENOMEM:
        printf("error: ENOMEM\n");
        break;
      default:
        printf("error: %d\n",err);
        break;
      }
    } else
    {
      printf("%s\n",hostname);
    }

  return 0;
}
------------------------------------------------------------------
cut here

When I ran this program and fed it with a parameter greater than 255
characters, I got an ENAMETOOLONG error. Hurd is supossed to be without limits,
isn't it? 
 
Thanks a lot in advance.      =)
 

=====
--------- 
|   |   |                    Cronos 
|   |   |            "No confies en nadie mayor de treinta" 
|   ----| 
|       |            Email: cronos1_mx@yahoo.com 
|       |            WWW:   http://www.geocities.com/cronos1_mx/
---------

___________________________________________________________
Do You Yahoo!? -- Un e-mail gratuit @yahoo.fr !
Yahoo! Courrier : http://fr.mail.yahoo.com



Reply to: