[Mono-list] Anyone suggest a clean way to do the following in Mono..??

Andrew Tierney andrew at castlesoft.com.au
Tue Jul 22 10:57:21 EDT 2008


Hi All,

Anyone suggest a clean solution to the following ??

I would like to wrap WinPCap and LibpCap and at runtime select the right 
one to call based on Platform. (Win/Linux)

Initially I thought about 2 classes, and an interface to define a contract..

Then I ran into the problem of DLLImport/static and Interfaces... (oh 
and one routine uses a delegate callback for an argument).

I don't really want to duplicate the wrapper routines for both 
platforms. And GetprocAddr/Delegate seems a little messy..

Any ideas GREATLY appreciated.

Regards
Andrew
  
=============================================================================

namespace WinPCap
{
    class Windows
    {
        private const string pCapLib = "wpcap.dll";

        [DllImport(pCapLib)]
        internal static extern  void pcap_breakloop(IntPtr ph);

        [DllImport(pCapLib)]
        internal static extern  void pcap_close(IntPtr adaptHandle);

        etc
   }
}


namespace WinPCap
{
    class Linux
    {
        private const string pCapLib = "libpcap.so";

        [DllImport(pCapLib)]
        internal static extern  void pcap_breakloop(IntPtr ph);

        [DllImport(pCapLib)]
        internal static extern  void pcap_close(IntPtr adaptHandle);

        etc
   }
}




More information about the Mono-list mailing list