From d09a51da28b4d486711ec8b9bd36acb387e73f6d Mon Sep 17 00:00:00 2001 From: Ognyan Kulev Date: Sun, 6 Apr 2003 14:51:00 +0000 Subject: none --- Distrib/PortingIssues.mdwn | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'Distrib') diff --git a/Distrib/PortingIssues.mdwn b/Distrib/PortingIssues.mdwn index 2361d064..fb66791f 100644 --- a/Distrib/PortingIssues.mdwn +++ b/Distrib/PortingIssues.mdwn @@ -75,6 +75,7 @@ Fixed code: ... #ifdef MAXHOSTNAMELEN + gethostname(localhost, sizeof(localhost)); #else localhost = xgethostname(); @@ -164,32 +165,34 @@ See [a simple fix for TIOCFLUSH in telnet](http://mail.gnu.org/archive/html/bug- The following declaration: - sockaddr_un sun = { AF_UNIX, "" }; + sockaddr_un sun = { AF_UNIX, "/path/to/socket" }; won't work on GNU/Hurd. The Glibc API requires that the second parameter of a `sockaddr_un` struct is array of chars, but NOT pointer to array of chars. Glibc wants a nul-terminated string of chars there, so we have to copy them directly into the `sun_path` address. An example: - sockaddr_un sa; + sockaddr_un su; /* AF_LOCAL is the canonical flag in Glibc. Use AF_UNIX if you want compatibility. */ - sa.sun_family = AF_LOCAL; + su.sun_family = AF_LOCAL; /* Copy the string into sun_path. It must be - no longer than 108 characters. */ - strcpy (sa.sun_path, "/path/to/socket"); + no longer than approximately 100 characters. */ + strcpy (su.sun_path, "/path/to/socket"); + /* Use `SUN_LEN (su)' in socket functions. */ If you have pointer to array of characters as file name, you'd better use the following code: - strncpy (sa.sun_path, filename, sizeof (sa.sun_path)); - sa.sun_path[sizeof (sa.sun_path) - 1] = '\0'; + strncpy (su.sun_path, filename, sizeof (su.sun_path)); + /* Use `sizeof (su)' in socket functions. */ -If you expect file name longer than 108 characters, use the following code: +If you expect file name longer than approximately 100 characters, use the following code: /* `offsetof', `alloca' and `AF_LOCAL' may not be available everywhere. */ - socklen_t sa_len = offsetof (struct sockaddr_un, sun_path) + socklen_t su_len = offsetof (struct sockaddr_un, sun_path) + strlen (filename) + 1; - struct sockaddr_un *sa = alloca (sa_len); - sa->sun_family = AF_LOCAL; - strcpy (sa->sun_path, filename); + struct sockaddr_un *su = alloca (su_len); + su->sun_family = AF_LOCAL; + strcpy (su->sun_path, filename); + /* Use `SUN_LEN (su)' in socket functions. */ NOTE: the current API is subject to change, see the notes in Glibc's docs ("info libc" and search for `sockaddr_un`) and [Debian bug #187391](http://bugs.debian.org/187391). -- cgit v1.2.3