On Sun, Apr 23, 2006 at 09:28:19PM +0200, Otto Moerbeek wrote: > On Sun, 23 Apr 2006, Nick Guenther wrote: > > > On 4/23/06, Dave Feustel <[EMAIL PROTECTED]> wrote: > > > I have downloaded the source code accompanying > > > Stevens' book _Advanced Network Programming > > > - The Socket Programming API, vol 1, 3rd ed. > > > After uncompressing the tar ball, cd'ing to the source code > > > directory , running ./configure and attempting to gmake the source > > > in lib, I get a number of errors which seem to stem from failure > > > of the ./configure command to find many of the OpenBSD include files > > > related to sockets. This failure shows up in the file config.h, where > > > defines created during the configure process specify that OpenBSD > > > is missing many include files and socket-related structures. This results > > > in compile errors when socket structures are redefined during compilation. > > > I started to fix individual errors until I figured out that there was a > > > more > > > general problem in ./configure. I have looked at the shell script in > > > ./configure > > > but so far I have not figured out where the configure goes wrong. Is > > > there a > > > simple way to run or fix ./configure so that the config.h generated by > > > configure reflects the actual content of openbsd include files and > > > subsequent > > > compiles of Stevens' source work? > > > > Well, socket(2) shows that OpenBSD certainly has the full socket API > > (afterall, they were invented on BSD). My guess is that the book was > > designed for linux and no thought was given to users of other OSes. > > This shows that you don't know Stevens' books. Stevens books are among > the books to read if you want to learn how to write good POSIX > programs. Most of them were written before Linux became popular. > > For fun I tried to compile some of the programs mentioned, and the > programs I tested compiled fine, be it with some warnings about > usage of non-safe string functions. > > -Otto > > > So, to fix it, you should just have to redirect the socket includes to > > the proper place (i.e: > > #include <sys/types.h> > > #include <sys/socket.h> > > ) > > > > Also: Hi Dave! > > > > -Nick > >
Here's a patch that removes all(?) warnings/errors from the intro chapter if you followed the instructions in the readme... diff -ru unpv13e.orig/intro/byteorder.c unpv13e/intro/byteorder.c --- unpv13e.orig/intro/byteorder.c Thu Nov 14 04:33:33 2002 +++ unpv13e/intro/byteorder.c Tue Apr 18 04:39:40 2006 @@ -18,7 +18,7 @@ else printf("unknown\n"); } else - printf("sizeof(short) = %d\n", sizeof(short)); + printf("sizeof(short) = %zd\n", sizeof(short)); exit(0); } diff -ru unpv13e.orig/lib/error.c unpv13e/lib/error.c --- unpv13e.orig/lib/error.c Sat Sep 20 04:51:29 2003 +++ unpv13e/lib/error.c Tue Apr 18 04:25:36 2006 @@ -96,7 +96,7 @@ n = strlen(buf); if (errnoflag) snprintf(buf + n, MAXLINE - n, ": %s", strerror(errno_save)); - strcat(buf, "\n"); + strlcat(buf, "\n", MAXLINE + 1); if (daemon_proc) { syslog(level, buf); diff -ru unpv13e.orig/lib/sock_ntop.c unpv13e/lib/sock_ntop.c --- unpv13e.orig/lib/sock_ntop.c Mon Jul 28 06:26:32 2003 +++ unpv13e/lib/sock_ntop.c Tue Apr 18 04:36:21 2006 @@ -19,7 +19,7 @@ return(NULL); if (ntohs(sin->sin_port) != 0) { snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port)); - strcat(str, portstr); + strlcat(str, portstr, 128); } return(str); } @@ -34,7 +34,7 @@ return(NULL); if (ntohs(sin6->sin6_port) != 0) { snprintf(portstr, sizeof(portstr), "]:%d", ntohs(sin6->sin6_port)); - strcat(str, portstr); + strlcat(str, portstr, 128); return(str); } return (str + 1); @@ -48,7 +48,7 @@ /* OK to have no pathname bound to the socket: happens on every connect() unless client calls bind() first. */ if (unp->sun_path[0] == 0) - strcpy(str, "(no pathname bound)"); + strlcpy(str, "(no pathname bound)", 128); else snprintf(str, sizeof(str), "%s", unp->sun_path); return(str); diff -ru unpv13e.orig/lib/sock_ntop_host.c unpv13e/lib/sock_ntop_host.c --- unpv13e.orig/lib/sock_ntop_host.c Tue May 13 20:47:49 2003 +++ unpv13e/lib/sock_ntop_host.c Tue Apr 18 11:58:31 2006 @@ -35,7 +35,7 @@ /* OK to have no pathname bound to the socket: happens on every connect() unless client calls bind() first. */ if (unp->sun_path[0] == 0) - strcpy(str, "(no pathname bound)"); + strlcpy(str, "(no pathname bound)", 128); else snprintf(str, sizeof(str), "%s", unp->sun_path); return(str); diff -ru unpv13e.orig/libfree/inet_ntop.c unpv13e/libfree/inet_ntop.c --- unpv13e.orig/libfree/inet_ntop.c Thu Nov 14 04:33:35 2002 +++ unpv13e/libfree/inet_ntop.c Tue Apr 18 04:34:00 2006 @@ -91,12 +91,12 @@ static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; - sprintf(tmp, fmt, src[0], src[1], src[2], src[3]); + snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]); if (strlen(tmp) > size) { errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + strlcpy(dst, tmp, size); return (dst); } @@ -178,7 +178,7 @@ tp += strlen(tp); break; } - sprintf(tp, "%x", words[i]); + snprintf(tp, sizeof(tmp), "%x", words[i]); tp += strlen(tp); } /* Was it a trailing run of 0x00's? */ @@ -193,6 +193,6 @@ errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + strlcpy(dst, tmp, size); return (dst); } diff -ru unpv13e.orig/libroute/if_nameindex.c unpv13e/libroute/if_nameindex.c --- unpv13e.orig/libroute/if_nameindex.c Sun Apr 27 01:13:56 2003 +++ unpv13e/libroute/if_nameindex.c Tue Apr 18 04:17:48 2006 @@ -49,11 +49,12 @@ /* end if_nameindex */ /* include if_freenameindex */ +/* Provided by OpenBSD void if_freenameindex(struct if_nameindex *ptr) { free(ptr); -} +}*/ /* end if_freenameindex */ struct if_nameindex *