Subject: pkg/32374: wminet fails build on Darwin
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <scole@sdf.lonestar.org>
List: pkgsrc-bugs
Date: 12/23/2005 23:05:00
>Number:         32374
>Category:       pkg
>Synopsis:       wminet fails build on Darwin
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 23 23:05:00 +0000 2005
>Originator:     scole
>Release:        Darwin pkgsrc
>Organization:
>Environment:
Darwin goofy 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC  Power Macintosh powerpc
>Description:
wminet-1.2 fails build on Darwin:

===> Checking for vulnerabilities in wminet-1.2
=> Checksum SHA1 OK for wmnet-1.2.tar.gz.
=> Checksum RMD160 OK for wmnet-1.2.tar.gz.
===> Extracting for wminet-1.2
===> Required installed package xpkgwedge>=1.14: xpkgwedge-1.14 found
===> Required installed package x11-links>=0.25: x11-links-0.26 found
===> Patching for wminet-1.2
===> Applying pkgsrc patches for wminet-1.2
===> Overriding tools for wminet-1.2
===> Creating toolchain wrappers for wminet-1.2
===> Configuring for wminet-1.2
===> Building for wminet-1.2
gcc -pipe -c -O2 -I/Volumes/NetBSD/pkg/include -I/usr/X11R6/include -I/usr/X11R6/include -I/Volumes/NetBSD/pkg/include main.c -o main.o
gcc -pipe -c -O2 -I/Volumes/NetBSD/pkg/include -I/usr/X11R6/include -I/usr/X11R6/include -I/Volumes/NetBSD/pkg/include if.c -o if.o
if.c: In function `dereference':
if.c:196: error: structure has no member named `if_addrlist'
if.c: In function `ifInit':
if.c:280: error: structure has no member named `if_next'
*** Error code 1

Stop.
bmake: stopped in /Volumes/NetBSD/pkgsrc/net/wminet/work/wmnet-1.2
*** Error code 1

Stop.
bmake: stopped in /Volumes/NetBSD/pkgsrc/net/wminet
===> 
===> There was an error during the ``build'' phase.
===> Please investigate the following for more information:
===>      * log of the build
===>      * /Volumes/NetBSD/pkgsrc/net/wminet/work/.work.log
===> 
*** Error code 1



>How-To-Repeat:
cd .../pkgsrc/net/wminet && bmake
>Fix:
Here are updates to patch-aa and patch-ab files that allow wminet to compile, install and run.

  Also, I had to use sudo to run wminet.  For some reason, wminet wouldn't open /dev/kmem even if I did a
 chgrp kmem wminet
 chmod 2555 wminet

Do I need to be in the kmem group on Darwin for this setguid to work?

Thanks.

*****************
patch-aa
********
--- Makefile.orig       Thu Dec  3 08:33:58 1998
+++ Makefile    Fri Dec 23 15:36:25 2005
@@ -2,22 +2,21 @@
 #      Makefile,v 1.8 1998/12/03 15:33:58 rneswold Exp
 #
 
-PREFIX=/usr/local
-MANDIR=${PREFIX}/man
-BINDIR=${PREFIX}/bin
-
-LIBDIR = -L/usr/X11R6/lib -L/usr/local/lib
+LIBDIR  = -L${X11BASE}/lib -Wl,-R${X11BASE}/lib -L${LOCALBASE}/lib -Wl,-R${LOCAL
BASE}/lib
 LIBS = -lXpm -lXext -lX11 -lkvm
 OBJS = main.o if.o wmgeneral.o
-INCDIR = -I${X11BASE}/include
+INCDIR = -I${X11BASE}/include -I${LOCALBASE}/include
 
 .c.o :
-       cc -c -g -O1 -Wall ${INCDIR} $< -o $*.o
+       ${CC} -c ${CFLAGS} ${INCDIR} $< -o $*.o
+
+all :: wminet
 
-all :: wmnet
+wminet : $(OBJS)
+       ${CC} ${LDFLAGS} -o wminet $(OBJS) $(LIBDIR) $(LIBS) ${INCDIR}
 
-wmnet : $(OBJS)
-       cc -o wmnet $(OBJS) $(LIBDIR) $(LIBS) ${INCDIR}
+wminet.1 : wmnet.1
+       sed -e 's/wmnet/wminet/g' wmnet.1 > wminet.1
 
 main.o : wmnet-mask.xbm wmnet-master.xpm wmnet.h wmgeneral.h
 
@@ -26,12 +25,16 @@
 wmgeneral.o : wmgeneral.c wmgeneral.h
 
 clean :
-       rm -f $(OBJS) wmnet
+       rm -f $(OBJS) wminet
 
-install.man : wmnet.1
-       install -c -m 644 -o man -g man wmnet.1 ${MANDIR}/man1
+install.man : wminet.1
+       install -c -m 644 -o root -g wheel wminet.1 ${PREFIX}/man/man1
 
-install.bin : wmnet
-       install -s -c -m 2555 -o bin -g kmem wmnet ${BINDIR}
+install.bin : wminet
+.if ${OPSYS} == "Darwin"
+       install -s -c -m 2555 -o root -g kmem wminet ${PREFIX}/bin
+.else
+       install -s -c -m 2555 -o bin -g kmem wminet ${PREFIX}/bin
+.endif
 
 install : install.bin install.man
******************************************






************
* patch-ab
********************************************
--- if.c.orig   Fri Dec 23 13:12:55 2005
+++ if.c        Fri Dec 23 13:13:04 2005
@@ -12,12 +12,13 @@
 #include <unistd.h>
 #include <limits.h>
 #include <err.h>
+#include <errno.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#if (__FreeBSD_version >= 300003)
+#if (__FreeBSD_version >= 300003) || defined(__APPLE__)
 #include <net/if_var.h>
 #include <net/if_types.h>
 #endif
@@ -27,6 +28,13 @@
 #include <assert.h>
 #include "wmnet.h"
 
+/* On Darwin 7.9.0, these defines are in <net/if_var.h>, but
+   are defined only for ! __APPLE__ */
+#if defined(__APPLE__)
+#define        if_addrlist     if_addrhead
+#define        if_list         if_link 
+#endif
+
 #define        IF_STEP 10
 
 /*
@@ -89,7 +97,11 @@
                        if (!newData) {
                                size -= IF_STEP;
                                fprintf(stderr, "wmnet: Warning -- low memory; "
+#ifdef __NetBSD__
+                                               "ignoring %s interface\n", theData->if_xname);
+#else
                                                "ignoring %s interface\n", theData->if_name);
+#endif /* NetBSD */
                                return 0;
                        }
 
@@ -118,8 +130,12 @@
                ptr->flags = 0;
 
 #ifndef NDEBUG
+#ifdef __NetBSD__
+               printf("Added '%.*s' to list.\n", IFNAMSIZ, theData->if_xname);
+#else
                printf("Added '%.*s%d' to list.\n", IFNAMSIZ, theData->if_name,
                           theData->if_unit);
+#endif /* NetBSD */
 #endif
 
                // Bump the total.
@@ -161,6 +177,7 @@
                return &d;
        else if (sizeof(d) == kvm_read(kd, a, &d, sizeof(d))) {
 
+#ifndef __NetBSD__
                /* We've read the structure's data, but the 'name' field still
                   points to kernel memory. We transfer the name to a local
                   buffer, and then modify the pointer to point to our

@@ -178,22 +195,32 @@
                           to look at. While debugging, set these to NULL to trap
                           any attempts. */
 
+#endif /* !NetBSD */
                        d.if_softc = 0;
-#if (__FreeBSD_version >= 300003)
+#if (__FreeBSD_version >= 300003) || defined(__APPLE__)
                        d.if_addrhead.tqh_first = 0;
 #else
                        d.if_addrlist = 0;
 #endif
                        d.if_bpf = 0;
+#ifdef __NetBSD__
+                       d.if_addrlist.tqh_first = 0;
+#else
                        d.if_linkmib = 0;
                        d.if_poll_slowq = 0;
+#endif /* NetBSD */
 #endif
                        c = a;
                        return &d;
+#ifndef __NetBSD__
                } else
                        return 0;
+#endif /* !NetBSD */
        } else
+       {
+               perror("kvm_read");
                return 0;
+       }
 }
 
 /*------------------------------------------------------------------------------
@@ -233,6 +260,9 @@
                        { "" }
                };
 
+       if (setgid(getgid()) != 0) { perror("setgid"); return(0); }
+       if (setuid(getuid()) != 0) { perror("seguid"); return(0); }
+
                /* Try to pull the address for the global kernel variable,
                   ifnet. This variable is the root of the singly-linked list
                   of network interfaces. */
@@ -248,11 +278,15 @@
 
                                while (current) {
                                        addIfData(current);
-#if (__FreeBSD_version >= 300003)
+#if (__FreeBSD_version >= 300003) || defined(__APPLE__)
                                        current = (unsigned long) dereference(current)->if_link.tqe_next;
 #else
+#ifdef __NetBSD__
+                                       current = (unsigned long) dereference(current)->if_list.tqe_next;
+#else
                                        current = (unsigned long) dereference(current)->if_next;
 #endif
+#endif
                                }
 
                                /* Try to register our termination function. If it
@@ -309,7 +343,11 @@
                if (ptr) {
                        static char buffer[IFNAMSIZ + 1];
 
+#ifdef __NetBSD__
+                       sprintf(buffer, "%.*s", IFNAMSIZ - 1, ptr->if_xname);
+#else
                        sprintf(buffer, "%.*s%d", IFNAMSIZ - 1, ptr->if_name, ptr->if_unit);
+#endif /* NetBSD */
                        return buffer;
                }
        }