std C/C++ patch #3

David Scott Page page at cs.utexas.edu
Thu Apr 25 16:43:41 EDT 2002


Hi,

This mail includes two unrelated patches (motivated by my laziness:
one file is modified by both patches).

1) The first replaces an include of sys/ioctl.h with sys/ioccom.h for
Solaris. Solaris sys/ioctl.h is a tty related header, and if the
BSD_COMP portion is included (for the "usual" ioctl definitions), a
raft of errors arises from macro redefinitions.  The simple solution
is to include sys/ioccom.h instead, which contains the expected ioctl
utility macros. This probably applies to all SVR4 hosts, but I'm not
sure what to define.

2) The second patches three instances where current click collides
with the "linkage is part of type" standard. All three cases arise
from passing pointers to functions having C++ linkage to C library
routines (i.e., callbacks).  The first case (fromdevice) is messy,
because the original callback function is declared as a private static
(class) member in order to get access to private parts of
FromDevice. Thus the C linkage wrapper function must be declared in
the header and made a friend.

In the second and third case, the callbacks could be simply converted
into C linkage functions in an anonymous namespace.

Please let me know if you have any comments or questions.

--
Scott Page

------------------------------- 8< ----------------------------------------
diff -Naur click-stdC++.2/elements/userlevel/fromdevice.cc click-stdC++.3/elements/userlevel/fromdevice.cc
--- click-stdC++.2/elements/userlevel/fromdevice.cc	Fri Apr  5 21:01:15 2002
+++ click-stdC++.3/elements/userlevel/fromdevice.cc	Thu Apr 25 17:14:45 2002
@@ -25,8 +25,11 @@
 #include <click/packet_anno.hh>
 #include <unistd.h>
 #include <fcntl.h>
-
+#if defined( __sun )		// Solaris
+#include <sys/ioccom.h>
+#else
 #include <sys/ioctl.h>
+#endif
 
 #if FROMDEVICE_LINUX
 # include <sys/socket.h>
@@ -303,6 +306,14 @@
     else
 	p->kill();
 }
+
+extern "C"  void
+FromDevice__get_packet(u_char* clientdata,
+		       const struct pcap_pkthdr* pkthdr,
+		       const u_char* data)
+{
+    FromDevice::get_packet(clientdata, pkthdr, data) ;
+}
 #endif
 
 void
@@ -310,7 +321,7 @@
 {
 #ifdef FROMDEVICE_PCAP
     // Read and push() at most one packet.
-    pcap_dispatch(_pcap, 1, FromDevice::get_packet, (u_char *) this);
+    pcap_dispatch(_pcap, 1, FromDevice__get_packet, (u_char *) this);
 #endif
 #ifdef FROMDEVICE_LINUX
     struct sockaddr_ll sa;
diff -Naur click-stdC++.2/elements/userlevel/fromdevice.hh click-stdC++.3/elements/userlevel/fromdevice.hh
--- click-stdC++.2/elements/userlevel/fromdevice.hh	Fri Apr  5 21:01:15 2002
+++ click-stdC++.3/elements/userlevel/fromdevice.hh	Thu Apr 25 17:14:45 2002
@@ -92,6 +92,13 @@
 }
 #endif
 
+#if FROMDEVICE_PCAP
+extern "C" void
+FromDevice__get_packet(u_char* clientdata,
+		       const struct pcap_pkthdr* pkthdr,
+		       const u_char* data) ;
+#endif
+
 class FromDevice : public Element { public:
 
   enum ConfigurePhase {
@@ -136,6 +143,10 @@
   unsigned char *_packetbuf;
 #endif
 #if FROMDEVICE_PCAP
+  friend void 
+  FromDevice__get_packet(u_char* clientdata,
+			  const struct pcap_pkthdr* pkthdr,
+			  const u_char* data) ;
   pcap_t* _pcap;
   static void get_packet(u_char *, const struct pcap_pkthdr *,
 			 const u_char *);
diff -Naur click-stdC++.2/tools/lib/elementt.cc click-stdC++.3/tools/lib/elementt.cc
--- click-stdC++.2/tools/lib/elementt.cc	Mon Dec 31 19:14:39 2001
+++ click-stdC++.3/tools/lib/elementt.cc	Thu Apr 25 17:24:26 2002
@@ -83,15 +83,17 @@
     return size;
 }
 
-int
-PortT::sorter(const void *av, const void *bv)
-{
-    const PortT *a = (const PortT *)av, *b = (const PortT *)bv;
-    if (a->elt == b->elt)
-	return a->port - b->port;
-    else
-	return a->elt->idx() - b->elt->idx();
-}
+namespace {
+    extern "C" int
+    sorter(const void *av, const void *bv)
+    {
+	const PortT *a = (const PortT *)av, *b = (const PortT *)bv;
+	if (a->elt == b->elt)
+	    return a->port - b->port;
+	else
+	    return a->elt->idx() - b->elt->idx();
+    }
+} // anonymous
 
 void
 PortT::sort(Vector<PortT> &v)
diff -Naur click-stdC++.2/tools/lib/elementt.hh click-stdC++.3/tools/lib/elementt.hh
--- click-stdC++.2/tools/lib/elementt.hh	Wed Jan  2 21:22:17 2002
+++ click-stdC++.3/tools/lib/elementt.hh	Thu Apr 25 17:23:01 2002
@@ -88,7 +88,6 @@
     String unparse_input() const;
     String unparse_output() const;
     
-    static int sorter(const void *, const void *);
     static void sort(Vector<PortT> &);
 
 };
diff -Naur click-stdC++.2/userlevel/click.cc click-stdC++.3/userlevel/click.cc
--- click-stdC++.2/userlevel/click.cc	Fri Jan 11 07:42:37 2002
+++ click-stdC++.3/userlevel/click.cc	Thu Apr 25 17:29:22 2002
@@ -123,14 +123,16 @@
 static ErrorHandler *errh;
 static bool started = 0;
 
-static void
-catch_sigint(int)
-{
-  signal(SIGINT, SIG_DFL);
-  if (!started)
-    kill(getpid(), SIGINT);
-  router->please_stop_driver();
-}
+namespace {
+  extern "C" void
+  catch_sigint(int)
+  {
+    signal(SIGINT, SIG_DFL);
+    if (!started)
+      kill(getpid(), SIGINT);
+    router->please_stop_driver();
+  }
+} // anonymous
 
 
 // functions for packages



More information about the click mailing list