Hi Roger,

Thanks for the work you've done on getting this to compile for windows! 
There are a couple of other windows wonks on the mailing list - and I'd
love to hear what they have to say as well.

On 03/06/2013 04:03 PM, Roger Massey wrote:
> Hi Alan,
>
>
> Attached is an export file. I see that I left my initials on some
> changes. I was labeling them at first, but there were so many I gave
> it up at some point. I should remove them.
>
> I might have some thoughts about the guide for windows - I will try to
> think about it soon. I would like to get something running and see
> what it takes.
>
> We went to Machu Piccu in Feb with my older sister and bother-in-law.
> I need to make a dvd for them of our pictures. I don't know how I ever
> had time for a job.
Welcome back to the land of the North!  Hope you had a great time!

And Welcome back to the project.  Great to have you back!

So, below is the export file you sent - along with some comments... 
It's an impressive amount of work...

I have a few suggestions for things that need doing before it will fit
in as well as it should...


> # HG changeset patch
> # User Roger Massey <[email protected]>
> # Date 1362607384 25200
> # Node ID 06ed870b1f0c1698ab9c4ed2d1dca1b9ca3ed071
> # Parent  1e7e4bfc54705e995efdb5ba77dd6f30ac019086
> Changes for windows
>
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c CMakeLists.txt
> --- a/CMakeLists.txt    Sun Mar 03 23:45:41 2013 -0700
> +++ b/CMakeLists.txt    Wed Mar 06 15:03:04 2013 -0700
> @@ -248,8 +248,10 @@
>      endif (GOOD_GCC_FLAGS_WORK)
>    ENDIF(CMAKE_COMPILER_IS_GNUCC)
>  endif("${CMAKE_C_COMPILER}" MATCHES ".*/ccc-analyze")
> +if(NOT WIN32)
>  set (CMAKE_EXE_LINKER_FLAGS "-Wl,-Bsymbolic-functions -Wl,-z,relro -z
> now")
>  set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic-functions -Wl,-z,relro
> -z now")
> +endif(NOT WIN32)
I should probably make these flags contingent on the compiler being gcc
or clang.  That's probably the better fix for this.

>  set (CMAKE_POSITION_INDEPENDENT_CODE ON)
>  
>  #
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/cmalib.c
> --- a/clientlib/cmalib.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/cmalib.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -38,7 +38,7 @@
>   * Keep in mind the entire packet needs to fit in a UDP packet (< 64K).
>   * The port, hbtime, deadtime, and warntime parameters apply to all
> given addresses.
>   */
> -FrameSet*
> +WINEXPORT FrameSet*
>  create_sendexpecthb(ConfigContext* config    ///<[in] Provides
> deadtime, port, etc.
>          ,   guint16 msgtype        ///<[in] message type to create
>          ,   NetAddr* addrs        ///<[in/out] Addresses to include
> @@ -87,7 +87,7 @@
>  /// the SETCONFIG message.  We ignore frames in the ConfigContext
> (shouldn't be any).
>  /// We are effectively a "friend" function to the ConfigContext
> object - either that
>  /// or we cheated in order to iterate through its hash tables ;-)
> -FrameSet*
> +WINEXPORT FrameSet*
>  create_setconfig(ConfigContext * cfg)
>  {
>      FrameSet*    fs = frameset_new(FRAMESETTYPE_SETCONFIG);
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/fsprotocol.c
> --- a/clientlib/fsprotocol.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/fsprotocol.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -401,6 +401,9 @@
>          _fsproto_fsa(fspe, FSPROTO_REQSHUTDOWN, NULL);
>      }else if (DEBUG > 0) {
>          char    suffix[16];

> +#ifdef WIN32
> +#define snprintf _snprintf
> +#endif
>          snprintf(suffix, sizeof(suffix), "/%d", qid);
>          DUMP("_fsprotocol_closeconn: Could not locate connection",
> &destaddr->baseclass, suffix);
>      }
We should just change to g_snprintf - they're already done this porting
work.  [I just did that]

> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/jsondiscovery.c
> --- a/clientlib/jsondiscovery.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/jsondiscovery.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -20,8 +20,11 @@
>   *  You should have received a copy of the GNU General Public License
>   *  along with the Assimilation Project software.  If not, see
> http://www.gnu.org/licenses/
>   */
> -
OK.  I need to test for unistd.h being present - and then say #ifdef
HAVE_UNISTD_H or something similar.  That's the better approach.  I now
know how to make cmake do that.

> +//rhm
> +#ifndef WIN32
>  #include <unistd.h>
> +//rhm
> +#endif
>  #include <memory.h>
>  #include <projectcommon.h>
>  #define DISCOVERY_SUBCLASS
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/misc.c
> --- a/clientlib/misc.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/misc.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -24,14 +24,22 @@
>  
>  #include <projectcommon.h>
>  #include <stdlib.h>
> +//rhm
Ditto...
> +#ifndef WIN32
>  #include <unistd.h>
> +//rhm
> +#endif
>  #include <errno.h>
>  #include <string.h>
>  #include <fcntl.h>
>  #include <sys/types.h>
>  #include <sys/stat.h>
Two more to check for...
> +#ifndef WIN32
>  #include <sys/time.h>
>  #include <sys/resource.h>
> +#else
One thing that's important -- I use this call to test to see if the
process exists without terminating it as well.  Will this API be able to
do this?
> +int __declspec(dllimport)  __stdcall   TerminateProcess(void *
> hProcess,unsigned int uExitCode);
> +#endif
>  #include <signal.h>
>  #include <misc.h>
>  
> @@ -40,8 +48,7 @@
>  const char *    assim_syslogid = "assim"; /// Should be overridden
> with the name to appear in the logs
>  FSTATIC void catch_pid_signal(int signum);
>  
> -
> -

I'm having trouble following this diff.  Can you explain this?

> +#ifndef WIN32
>  /// Make us into a proper daemon.
>  void
>  daemonize_me(    gboolean stay_in_foreground,    ///<[in] TRUE to not
> make a background job
> @@ -125,11 +132,30 @@
>          close(j);
>      }
>  }
> +#else
> +void
> +daemonize_me(    gboolean stay_in_foreground,    ///<[in] TRUE to not
> make a background job
> +        const char* dirtorunin,        ///<[in] Directory to cd to or
> NULL for default (/)
> +        const char* pidfile)        ///<[in] Pathname of pidfile or
> NULL for no pidfile
> +{
> +    if (pidfile) {
> +        if (are_we_already_running(pidfile, NULL) == PID_RUNNING) {
> +            g_message("Already running.");
> +            exit(0);
> +        }
> +    }
> +            // Exit if we can't create the requested pidfile
> +    if (!create_pid_file(pidfile)) {
> +        exit(1);
> +    }
> +}
> +#endif
>  
How do you log in Windows?  We ought to provide a syslog replacement
which interfaces with the Windows syslog capability - not just throwing
things out to stdout/stderr...

>  static gboolean    syslog_opened = FALSE;
>  void
>  assimilation_openlog(const char* logname)
>  {
> +#ifndef WIN32
>      const int    syslog_options = LOG_PID|LOG_NDELAY;
>      const int    syslog_facility = LOG_DAEMON;
>  
> @@ -149,6 +175,7 @@
>      g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL);
>      openlog(assim_syslogid, syslog_options, syslog_facility);
>      syslog_opened = TRUE;
> +#endif
>  }
>  void
>  assimilation_logger(const gchar *log_domain,    ///< What domain are
> we logging to?
> @@ -156,6 +183,16 @@
>              const gchar *message,    ///< What should we log
>              gpointer ignored)        ///< Ignored
>  {
> +#ifdef WIN32
> +#define LOG_INFO 6
> +#define LOG_DEBUG 7
> +#define LOG_NOTICE 5
> +#define LOG_WARNING 4
> +#define LOG_ERR 3
> +#define LOG_CRIT 2
> +#define LOG_ALERT 1
> +#define LOG_EMERG 0
> +#endif
>      int        syslogprio = LOG_INFO;
>      const char *    prefix = "INFO:";
>  
> @@ -187,9 +224,11 @@
>          syslogprio = LOG_EMERG; // Or maybe LOG_CRIT ?
>          prefix = "EMERG";
>      }
> +#ifndef WIN32
>      syslog(syslogprio, "%s:%s %s", prefix
>      ,    log_domain == NULL ? "" : log_domain
>      ,    message);
> +#endif
>      fprintf(stderr, "%s: %s:%s %s\n", assim_syslogid, prefix
>      ,    log_domain == NULL ? "" : log_domain
>      ,    message);
> @@ -243,7 +282,12 @@
>          *pidarg = pid;
>      }
>      // Is it still running?
> -    if (kill(pid, 0) < 0 && errno != EPERM) {
> +#ifdef WIN32
> +    if(TerminateProcess((void *)pid, 0) == 0)
> +#else
> +    if (kill(pid, 0) < 0 && errno != EPERM)
> +#endif
> +    {
>          g_debug("%s.%d: PID %d is not running", __FUNCTION__,
> __LINE__, pid);
>          return PID_DEAD;
>      }
> @@ -260,6 +304,9 @@
>      }else{
>          ourexecmd = ourexepath;
>      }
> +#if _MSC_VER
> +#define snprintf _snprintf
> +#endif
Same as before - we should use g_snprintf()...
>      snprintf(pidexename, sizeof(pidexename), PROCOTHEREXE, pid);
>  
>      // What is the pathname of the executable that holds the pid lock?
> @@ -295,8 +342,11 @@
>      char        pidbuf[16];
>      GError*        errptr = NULL;
>      PidRunningStat    pstat;
> +//    int pid;
>     
> -
> +#if _MSC_VER
> +#define getpid _getpid
> +#endif
>      g_debug("%s.%d: Creating pid file %s for pid %d", __FUNCTION__,
> __LINE__, pidfile, getpid());
>      pstat = are_we_already_running(pidfile, NULL);
>      if (PID_RUNNING == pstat) {
> @@ -343,7 +393,14 @@
>  
>      pidstat = are_we_already_running(pidfile, &service_pid);
>      if (pidstat == PID_RUNNING) {
> +#ifndef WIN32
>          return kill((pid_t)service_pid, signal);
> +#else
> +        if(TerminateProcess(service_pid, signal) != 0) {
> +            unlink(pidfile);
> +            return(-1);
> +        }
> +#endif
>      }
>      unlink(pidfile);    // No harm in removing it...
>      return 0;
> @@ -351,16 +408,22 @@
>  
>  static const char *    saved_pidfile = NULL;
>  void
> -rmpid_and_exit_on_signal(const char * pidfile, int signal)
> +rmpid_and_exit_on_signal(const char * pidfile, int sig)
I take it you can't have a variable the same as a function in MS C?
>  {
This should also be HAVE_SIGACTION - which we can test.  Some really old
versions of UNIX don't have sigaction (although they're pretty old...)
> +#ifndef WIN32
>      struct sigaction    sigact;
> +#endif
>  
>      if (pidfile != NULL) {
>          saved_pidfile = pidfile;
>      }
> +#ifndef WIN32
>          memset(&sigact, 0,  sizeof(sigact));
>          sigact.sa_handler = catch_pid_signal;
> -        sigaction(signal, &sigact, NULL);
> +        sigaction(sig, &sigact, NULL);
> +#else
> +    signal(sig, catch_pid_signal);
> +#endif
>  }
>  FSTATIC void
>  catch_pid_signal(int unused_signum)
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/nanoprobe.c
> --- a/clientlib/nanoprobe.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/nanoprobe.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -22,7 +22,11 @@
>   *  along with the Assimilation Project software.  If not, see
> http://www.gnu.org/licenses/
>   *
>   */
> +//rhm
> +#ifndef WIN32
>  #include <sys/utsname.h>
> +//rhm
> +#endif
>  #include <projectcommon.h>
>  #include <string.h>
>  #include <frameset.h>
> @@ -54,9 +58,9 @@
>  void (*nanoprobe_heartbeat_agent)(HbListener*)            = NULL;
>  void (*nanoprobe_warntime_agent)(HbListener*, guint64 howlate)    = NULL;
>  void (*nanoprobe_comealive_agent)(HbListener*, guint64 howlate)    =
> NULL;
> -NanoHbStats        nano_hbstats = {0U, 0U, 0U, 0U, 0U};
> +WINEXPORT NanoHbStats        nano_hbstats = {0U, 0U, 0U, 0U, 0U};
>  gboolean        nano_connected = FALSE;
> -int            errcount = 0;
> +WINEXPORT int            errcount = 0;
>  GMainLoop*        mainloop = NULL;
>  
>  FSTATIC void        nanoobey_sendexpecthb(AuthListener*, FrameSet*
> fs, NetAddr*);
> @@ -849,7 +853,12 @@
>      ConfigContext*    context = cruft->context;
>      NetAddr*    cmainit = context->getaddr(context, CONFIGNAME_CMAINIT);
>      const char *        jsontext;
> +//rhm
> +    gchar*        sysname;
> +#ifndef WIN32
>      struct utsname    un;    // System name, etc.
> +//rhm
> +#endif
>  
>      if (nano_shutting_down) {
>          return FALSE;
> @@ -867,11 +876,25 @@
>          return FALSE;
>      }
>      fs = frameset_new(FRAMESETTYPE_STARTUP);
> -
> +//rhm
> +#ifndef WIN32
>      uname(&un);
> +    sysname = g_strdup(un.nodename);
> +//rhm
> +#else
> +    #define W_CNAME_SIZE 1026
> +    {
> +    char cname[W_CNAME_SIZE + 2] = "";
> +    DWORD lsize = W_CNAME_SIZE;
> +    GetComputerName(cname, &lsize);
> +    sysname = g_strdup(cname);
> +    }
> +    //rhm
> +#endif
We should do something prettier for this than using uname raw.  Create a
function which has two versions - probably?  I didn't see anything in
glib for this -- too bad :-(
Put these two versions in the misc.c file...  proj_get_sysname() or
assim_get_sysname() or something...

>      // Put in the system name
>      usf = cstringframe_new(FRAMETYPE_HOSTNAME, 0);
> -    usf->baseclass.setvalue(&usf->baseclass, strdup(un.nodename),
> strlen(un.nodename)+1
> +//rhm
> +    usf->baseclass.setvalue(&usf->baseclass, strdup(sysname),
> strlen(sysname)+1
>      ,            frame_default_valuefinalize);
>      frameset_append_frame(fs, &usf->baseclass);
>      UNREF2(usf);
> @@ -889,8 +912,9 @@
>      // That's because the reply is typically from a different address
>      // which would confuse the blazes out of the reliable comm code.
>      cruft->iosource->sendaframeset(cruft->iosource, cmainit, fs);
> +//rhm
>      DEBUGMSG("%s.%d: Sent initial STARTUP frameset for %s."
> -    ,    __FUNCTION__, __LINE__, un.nodename);
> +    ,    __FUNCTION__, __LINE__, sysname);
>      UNREF(fs);
>      return TRUE;
>  }
> @@ -1040,13 +1064,27 @@
Same comment as before.
>  WINEXPORT gboolean
>  nano_initiate_shutdown(void)
>  {
> +//rhm
> +    gchar*        sysname;
> +#ifndef WIN32
>      struct utsname    un;    // System name, etc.
>      uname(&un);
> +    sysname = g_strdup(un.nodename);
> +#else
> +    #define W_CNAME_SIZE 1026
> +    {
> +    char cname[W_CNAME_SIZE + 2] = "";
> +    DWORD lsize = W_CNAME_SIZE;
> +    GetComputerName(cname, &lsize);
> +    sysname = g_strdup(cname);
> +    }
> +    //rhm
> +#endif
>  
>      if (nano_connected) {
>          FsProtocol*    proto = CASTTOCLASS(ReliableUDP,
> nanotransport->_netio)->_protocol;
>          DEBUGMSG("Sending HBSHUTDOWN to CMA");
> -        nanoprobe_report_upstream(FRAMESETTYPE_HBSHUTDOWN, NULL,
> un.nodename, 0);
> +        nanoprobe_report_upstream(FRAMESETTYPE_HBSHUTDOWN, NULL,
> sysname, 0);
>          // Initiate connection shutdown.
>          // This process will wait for all our output to be ACKed.
>          // It also has an ACK timer, so it won't wait forever...
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/netio.c
> --- a/clientlib/netio.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/netio.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -25,13 +25,27 @@
>  #include <projectcommon.h>
>  #include <errno.h>
>  #include <memory.h>
> +//rhm
> +#ifndef WIN32
>  #include <unistd.h>
> +//rhm
> +#endif
>  #include <stdlib.h>
>  #include <fcntl.h>
>  #include <sys/types.h>
Sad to say --- This looks really necessary ;-)
>  #ifdef _MSC_VER
>  #    include <winsock2.h>
>  #    include <ws2tcpip.h>
> +//rhm
> +#define s6_addr16 s6_words
> +#define __in6_u u
> +struct ip_mreqn {
> +                      struct in_addr imr_multiaddr; /* IP multicast group
> +                                                       address */
> +                      struct in_addr imr_address;   /* IP address of
> local
> +                                                       interface */
> +                      int            imr_ifindex;   /* interface index */
> +                  };
>  #else
>  #    include <sys/socket.h>
>  #    include <netinet/in.h>
> @@ -590,7 +604,9 @@
>          FREE(msgbuf); msgbuf = NULL;
>          return NULL;
>      }
> -       
> +#ifdef WIN32
> +#define __u6_addr8 Byte
> +#endif
>      if (memcmp(srcaddr->sin6_addr.__in6_u.__u6_addr8, v4any, 
> sizeof(v4any)) == 0) {
>          //const guint8 localhost[16] = CONST_IPV6_LOOPBACK;
>          const guint8 localhost[16] = {CONST_IPV6_IPV4SPACE, 127, 0,
> 0, 1};
> @@ -671,8 +687,11 @@
>  
>  
>  #ifdef IPV6_V6ONLY
> +//rhm
> +#ifndef WIN32
>  #    include <netdb.h>
>  #    include <unistd.h>
> +#endif
>  
>  /// Return TRUE if our OS supports dual ipv4/ipv6 sockets.  That is,
>  /// can a single socket receive and send both ipv4 and ipv6 packets?
> @@ -691,7 +710,11 @@
>          return retval;
>      }
>      proto = getprotobyname("ipv6");
#ifndef HAVE_ENDPROTOENT
> +#ifndef WIN32
>      endprotoent();
> +#else
> +#define close closesocket
> +#endif
>      g_return_val_if_fail(proto != NULL, FALSE);
>     
>      sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c clientlib/pcap_GSource.c
> --- a/clientlib/pcap_GSource.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/clientlib/pcap_GSource.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -41,7 +41,11 @@
>   */
>  
>  #include <memory.h>
> +//rhm
Similar to previous comments HAVE_SYS_UTSNAME_H
Or eliminated by our new call :-D.
> +#ifndef WIN32
>  #include <sys/utsname.h>
> +//rhm
> +#endif
>  #include <projectcommon.h>
>  #include <proj_classes.h>
>  #include <pcap_min.h>
> @@ -50,6 +54,11 @@
>  #include <addrframe.h>
>  #include <cstringframe.h>
>  #include <frametypes.h>
> +//rhm
> +#ifdef WIN32
> +#include <Windows.h>
> +//rhm
> +#endif
>  
>  ///@defgroup GSource_Pcap GSource_Pcap class
>  /// Class representing a pcap GSource object - for capturing packets
> in the g_main_loop paradigm.
> @@ -248,11 +257,24 @@
>      const guint8*    bpkt = (const guint8*) pkt;
>      gsize        pktlen = ((const guint8*)pktend-bpkt);
>      guint8*        cppkt = MALLOC0(pktlen);
> +//rhm
> +    gchar*        sysname;
> +#ifndef WIN32
>      struct utsname    un;
> -    gchar*        sysname;
> +   
>  
>      g_return_val_if_fail(uname(&un) >= 0 , NULL);
>      sysname = g_strdup(un.nodename);
> +//rhm
> +#else

Definitely need to make a proj_get_sysname() function as noted before...

> +#define W_CNAME_SIZE 1026
> +    gchar cname[W_CNAME_SIZE + 2] = "";
> +    DWORD lsize = W_CNAME_SIZE;
> +    GetComputerName(cname, &lsize);
> +    sysname = g_strdup(cname);
> +//rhm
> +#endif
> +   
>      g_return_val_if_fail(NULL != sysname, NULL);
>      g_return_val_if_fail(fsysname != NULL, NULL);
>      g_return_val_if_fail(timeframe != NULL, NULL);
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/cmalib.h
> --- a/include/cmalib.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/cmalib.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -28,6 +28,6 @@
>  #include <frameset.h>
>  
>  
> -FrameSet* create_sendexpecthb(ConfigContext*, guint16 msgtype,
> NetAddr* addrs, int addrcount);
> -FrameSet* create_setconfig(ConfigContext * cfg);
> +WINEXPORT FrameSet* create_sendexpecthb(ConfigContext*, guint16
> msgtype, NetAddr* addrs, int addrcount);
> +WINEXPORT FrameSet* create_setconfig(ConfigContext * cfg);
>  #endif /* _CMALIB_H */
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/compressframe.h
> --- a/include/compressframe.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/compressframe.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -36,7 +36,7 @@
>  };
>  
>  CompressFrame* compressframe_new(guint16 frame_type, guint16
> compression_method);
> -Frame* compressframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +WINEXPORT Frame* compressframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
>  
>  ///@}
>  
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/cryptframe.h
> --- a/include/cryptframe.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/cryptframe.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -37,7 +37,7 @@
>  };
>  
>  CryptFrame* cryptframe_new(guint16 frame_type, guint16
> encryption_method, void* encryption_info);
> -Frame* cryptframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +WINEXPORT Frame* cryptframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
>  
>  ///@}
>  
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/misc.h
> --- a/include/misc.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/misc.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -23,7 +23,9 @@
>   */
>  #ifndef _MISC_H
>  #include <projectcommon.h>
> +#ifndef WIN32
>  #include <syslog.h>
> +#endif
>  #include <stdio.h>
>  
>  #define STD_PID_DIR    "/var/run"
> @@ -39,15 +41,15 @@
>  } PidRunningStat;
>  
>  /** Make a daemon process out of this process*/
> -void daemonize_me(gboolean stay_in_foreground    ///< TRUE == don't fork
> +WINEXPORT void daemonize_me(gboolean stay_in_foreground    ///< TRUE
> == don't fork
>  ,          const char * dirtorunin    ///< Directory to cd to before
> running
>  ,          const char* pidfile);        ///< pathname of pid file, or
> NULL
> -void assimilation_openlog(const char* logname);                ///<
> Open logs in our style (syslog)
> -PidRunningStat are_we_already_running(const char * pidfile, int*
> pid);    ///< Determine service status
> -guint        pidrunningstat_to_status(PidRunningStat);        ///<
> Convert PidRunningStat to an exit code for status
> -gboolean    create_pid_file(const char * pidfile);            ///<
> Create pid file - return TRUE on success
> -void        remove_pid_file(const char * pidfile);            ///<
> Remove pid file we created (if we created one)
> -int        kill_pid_service(const char * pidfile, int signal);   
> ///< Issue given signal to the pidfile-indicated running process
> +WINEXPORT void assimilation_openlog(const char* logname);           
>     ///< Open logs in our style (syslog)
> +WINEXPORT PidRunningStat are_we_already_running(const char * pidfile,
> int* pid);    ///< Determine service status
> +WINEXPORT guint        pidrunningstat_to_status(PidRunningStat);   
>     ///< Convert PidRunningStat to an exit code for status
> +WINEXPORT gboolean    create_pid_file(const char * pidfile);       
>     ///< Create pid file - return TRUE on success
> +WINEXPORT void        remove_pid_file(const char * pidfile);       
>     ///< Remove pid file we created (if we created one)
> +WINEXPORT int        kill_pid_service(const char * pidfile, int
> signal);    ///< Issue given signal to the pidfile-indicated running
> process
>  void        rmpid_and_exit_on_signal(const char * pidfile, int
> signal);    ///< Issue given signal to the pidfile-indicated running
> process
>  #endif /* MISC_H */
>  ///@}
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/nanoprobe.h
> --- a/include/nanoprobe.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/nanoprobe.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -36,18 +36,18 @@
>      guint    comealive_count;
>      guint    martian_count;
>  };
> -extern NanoHbStats    nano_hbstats;
> +WINEXPORT extern NanoHbStats    nano_hbstats;
>  extern gboolean        nano_connected;
>  
> -void                nano_start_full(const char *initdiscoverpath,
> guint discover_interval
> +WINEXPORT void                nano_start_full(const char
> *initdiscoverpath, guint discover_interval
>  ,                        NetGSource* io, ConfigContext* config);
> -void                nano_shutdown(gboolean statreport);
> +WINEXPORT void                nano_shutdown(gboolean statreport);
>  WINEXPORT PacketDecoder*    nano_packet_decoder(void);
>  WINEXPORT gboolean        nano_initiate_shutdown(void);
>  WINEXPORT void            nanoprobe_report_upstream(guint16
> reporttype, NetAddr* who, const char * sysname, guint64 howlate);
>  extern const char *        procname;    ///< process name
> -extern int            errcount;    ///< error count
> -extern GMainLoop*        mainloop;
> +WINEXPORT extern int            errcount;    ///< error count
> +WINEXPORT extern GMainLoop*        mainloop;
>  extern gboolean            nano_shutting_down;
>  
>  // Override this if you want to set up a non-standard deadtime agent. */
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/nvpairframe.h
> --- a/include/nvpairframe.h    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/nvpairframe.h    Wed Mar 06 15:03:04 2013 -0700
> @@ -37,7 +37,7 @@
>  };
>  
>  NVpairFrame* nvpairframe_new(guint16 frame_type, gchar* name, gchar*
> value, gsize framesize);
> -Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +WINEXPORT Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
>  
>  ///@}
>  
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c include/projectcommon.h.in
> --- a/include/projectcommon.h.in    Sun Mar 03 23:45:41 2013 -0700
> +++ b/include/projectcommon.h.in    Wed Mar 06 15:03:04 2013 -0700
> @@ -79,6 +79,10 @@
>  #define    SHORT_LICENSE_STRING    "@LICENSE_SHORT@"
>  #define    LONG_LICENSE_STRING    "@LICENSE_LONG@"
>  
> +// the checks for these are not working in winxp

We need to figure out why and fix it.  Cmake seems to be more designed
more for Windows than UNIX systems - it ought to work...  My guess is we
need to tell it how to find the glib libraries ${GLIB2_LIBRARIES} or
something.  Can you research this some more?

> +#define HAVE_G_GET_REAL_TIME 1
> +#define HAVE_G_GET_MONOTONIC_TIME 1
> +
>  #ifndef HAVE_G_GET_REAL_TIME
>  WINEXPORT gint64 g_get_real_time(void);
>  #endif
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c nanoprobe/nanoprobe.c
> --- a/nanoprobe/nanoprobe.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/nanoprobe/nanoprobe.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -22,12 +22,16 @@
>   */
>  
>  #include <stdlib.h>
> +#ifndef WIN32
>  #include <unistd.h>
> +#endif
>  #include <string.h>
>  #include <signal.h>
>  #include <errno.h>
> +#ifndef WIN32
>  #include <getopt.h>
>  #include <sys/utsname.h>
> +#endif
>  #include <projectcommon.h>
>  #include <framesettypes.h>
>  #include <frameset.h>
> @@ -50,6 +54,35 @@
>  
>  #ifdef WIN32
>  #    undef HAS_FORK
> +const char *        procname = "nanoprobe";
> +#define WINIMPORT __declspec (dllimport)
> +WINIMPORT int errcount;
> +WINIMPORT GMainLoop*        mainloop;
> +WINIMPORT void        remove_pid_file(const char * pidfile);
> +WINIMPORT void daemonize_me(gboolean stay_in_foreground, const char *
> dirtorunin, const char* pidfile);
> +WINIMPORT PidRunningStat are_we_already_running(const char * pidfile,
> int* pid);
> +WINIMPORT int        kill_pid_service(const char * pidfile, int signal);

OK.  This getopt stuff looks like it isn't stuff you wrote.  I think
your email said something similar.  Can you look at converting this (and
some newer stuff I just did) to use glib's g_option...() code?

https://developer.gnome.org/glib/2.30/glib-Commandline-option-parser.html

We can't bring in outside code into the code base without getting into
legal trouble in the future.  There is also an LGPL version out there I
mentioned to you.  But I think using the glib code is a better way to go
- we already depend on it, and it seems like we should be able to make
it do what we want...

> +struct option {
> +    const char *name;
> +    int has_arg;
> +    int *flag;
> +    int val;
> +};
> +int optind=1, opterr=1, optopt=0;
> +char *optarg=0;
> +#define no_argument 0
> +#define required_argument 1
> +
> +int getopt_long(int argc, char * argv[], const char *shortopts,
> +                       const struct option *longopts, int *longind);
> +
> +int getopt_long_only(int argc, char * argv[], const char *shortopts,
> +                            const struct option *longopts, int *longind);
> +
> +int _getopt_internal(int argc, char * argv[], const char *shortopts,
> +                            const struct option *longopts, int *longind,
> +                            int long_only);
> +void ignore_signal(int signum);
>  #else
>  #    define    HAS_FORK
>  #endif
> @@ -111,6 +144,12 @@
>  }
>  
>  /// Signal reception function - signals stop by here...
> +#ifdef WIN32
> +FSTATIC void
> +ignore_signal(int signum) {
> +        return;
> +}
> +#endif
>  FSTATIC void
>  catch_a_signal(int signum)
>  {
> @@ -121,6 +160,7 @@
>          case SIGTERM:
>              sigterm = TRUE;
>              break;
> +#ifndef WIN32

Should make this #ifndef SIGHUP...

>          case SIGHUP:
>              sighup = TRUE;
>              break;
> @@ -132,6 +172,7 @@
>              proj_class_decr_debug(NULL);
>              sigusr2 = TRUE;
>              break;
> +#endif
>      }
>  }
>  
> @@ -186,13 +227,16 @@
>      Listener*        otherlistener;
>      ConfigContext*        config = configcontext_new(0);
>      PacketDecoder*        decoder = nano_packet_decoder();
> +#ifndef WIN32
>      struct sigaction    sigact;
> +#endif
>      const char *        cmaaddr = defaultCMAaddr;
>      const char *        localaddr = defaultlocaladdress;
>      gboolean        anyportpermitted = TRUE;
>      int            c;
>      int            mcast_ttl = 31;
>      gboolean        stay_in_foreground = FALSE;
> +
>      static struct option     long_options[] = {
>          {"bind",    required_argument,    0,    'b'},
>          {"cmaaddr",    required_argument,    0,    'c'},
> @@ -296,17 +340,29 @@
>      if (!netio_is_dual_ipv4v6_stack()) {
>          g_warning("This OS DOES NOT support dual ipv4/v6 sockets -
> this may not work!!");
>      }

This should be #ifndef HAVE_SIGACT - and we should figure out how to
make Cmake do that right...

> +#ifdef WIN32
> +    signal(SIGTERM, catch_a_signal);
> +#else
>      memset(&sigact, 0,  sizeof(sigact));
>      sigact.sa_handler = catch_a_signal;
>      sigaction(SIGTERM, &sigact, NULL);
> +#endif
>      if (stay_in_foreground) {
> +#ifdef WIN32
> +        signal(SIGINT, catch_a_signal);
> +#else
>          struct sigaction    oldact;
>          sigaction(SIGINT,  &sigact, &oldact); // Need to check to see
> if it's already blocked.
>          if (oldact.sa_handler == SIG_IGN) {
>              // OOPS - put it back like it was
>              sigaction(SIGINT, &oldact, NULL);
>          }
> +#endif
>      }else{
> +#ifdef WIN32
> +        signal(SIGINT, ignore_signal);
> +    }
> +#else
>          // Always ignore SIGINT when in the background
>          struct sigaction    ignoreme;
>          memset(&ignoreme, 0,  sizeof(ignoreme));
> @@ -315,6 +371,7 @@
>      }
>      sigaction(SIGUSR1, &sigact, NULL);
>      sigaction(SIGUSR2, &sigact, NULL);
> +#endif
>  
>      config->setframe(config, CONFIGNAME_OUTSIG, &signature->baseclass);
>  
> @@ -438,3 +495,260 @@
>          proj_class_finalize_sys(); /// Shut down object system to
> make valgrind happy :-D
>      return(errcount <= 127 ? errcount : 127);
>  }

I've deleted the getopt replacement- because it contains code from
outside... Let's just go with the glib stuff.  I'd avoided it because it
seemed a bit complex...


> diff -r 1e7e4bfc5470 -r 06ed870b1f0c testcode/CMakeLists.txt
> --- a/testcode/CMakeLists.txt    Sun Mar 03 23:45:41 2013 -0700
> +++ b/testcode/CMakeLists.txt    Wed Mar 06 15:03:04 2013 -0700
> @@ -29,6 +29,7 @@
>  
>    target_link_libraries(filetest  ${CLIENTLIB} ${SERVERLIB}
> ${PCAP_LIB} ${GLIB_LIB})
>    target_link_libraries(mainlooptest ${CLIENTLIB} ${SERVERLIB}
> ${PCAP_LIB} ${GLIB_LIB})
> +  target_link_libraries(pinger ${CLIENTLIB} ${SERVERLIB} ${PCAP_LIB}
> ${GLIB_LIB})
>  
>  ELSE(WIN32)
>    target_link_libraries (filetest ${CLIENTLIB} ${SERVERLIB} -lpcap )
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c testcode/pcap+mainloop.c
> --- a/testcode/pcap+mainloop.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/testcode/pcap+mainloop.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -61,7 +61,14 @@
>  int        expected_dead_count = 1;
>  gint64        maxpkts  = G_MAXINT64;
>  gint64        pktcount = 0;
> +#ifdef WIN32
> +#define WINIMPORT __declspec( dllimport )
Let's put the WINIMPORT into the projectcommon.h - something like this?

#ifdef WIN32
#    define WINIMPORT __declspec( dllimport )
#else
#    define WINIMPORT   extern
#endif

Or maybe even make it GLOBALEXTERN or something more generic...

> +WINIMPORT GMainLoop*    mainloop;
> +WINIMPORT NanoHbStats    nano_hbstats;
> +WINIMPORT int            errcount;
> +#else
>  extern GMainLoop*    mainloop;
> +#endif
>  NetIO*        nettransport;
>  NetGSource*    netpkt;
>  NetAddr*    destaddr;
> diff -r 1e7e4bfc5470 -r 06ed870b1f0c testcode/pinger.c
> --- a/testcode/pinger.c    Sun Mar 03 23:45:41 2013 -0700
> +++ b/testcode/pinger.c    Wed Mar 06 15:03:04 2013 -0700
> @@ -45,6 +45,13 @@
>  #define RCVLOSS        0.05
>  #define XMITLOSS    0.05
>  
> +#ifdef WIN32
> +#define WINIMPORT __declspec(dllimport)
> +WINIMPORT Frame* cryptframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +WINIMPORT Frame* compressframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +WINEXPORT Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart,
> gconstpointer pktend);
> +#endif
> +
>  /*
>   *    You can either give us a list of addresses, or none.
>   *
>
Not quite sure I understand the WINIMPORT vs WINEXPORT.  Can you explain
it to those of us who are windows impaired?

Here's my summary of what I think I'll do to get ready for a revised set
of changes:

g_snprintf()    -- done
HAVE_UNISTD_H - done
HAVE_SYS_UTSNAME_H - done
HAVE_KILL - done
HAVE_UNAME - done
HAVE_SIGACTION - done
HAVE_ENDPROTOENT - done
HAVE_GETCOMPUTERNAME
proj_get_sysname() (at least for Unix-like systems)

Did I miss anything?  Does this seem reasonable?

    Thanks again for your efforts!  What a big chunk of work!

             

-- 
    Alan Robertson <[email protected]> - @OSSAlanR

"Openness is the foundation and preservative of friendship...  Let me claim 
from you at all times your undisguised opinions." - William Wilberforce
_______________________________________________
Assimilation mailing list - Discovery-Driven Monitoring
[email protected]
http://lists.community.tummy.com/cgi-bin/mailman/listinfo/assimilation
http://assimmon.org/

Reply via email to