Introduce the "mt_debug" macro.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 19 Nov 2009 10:08:22 +0000 (11:08 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 19 Nov 2009 10:08:22 +0000 (11:08 +0100)
src/main.c

index c1a7aa3..3f844ab 100644 (file)
 
 #include "routeros_api.h"
 
 
 #include "routeros_api.h"
 
+#if 1
+# define mt_debug(...) fprintf (stdout, __VA_ARGS__)
+#else
+# define mt_debug(...) /**/
+#endif
 
 /* FIXME */
 char *strdup (const char *);
 
 /* FIXME */
 char *strdup (const char *);
@@ -300,6 +305,9 @@ static int send_command (mt_connection_t *c, /* {{{ */
        size_t i;
        int status;
 
        size_t i;
        int status;
 
+       /* FIXME: For debugging only */
+       memset (buffer, 0, sizeof (buffer));
+
        buffer_ptr = buffer;
        buffer_size = sizeof (buffer);
 
        buffer_ptr = buffer;
        buffer_size = sizeof (buffer);
 
@@ -529,6 +537,9 @@ static int create_socket (const char *node, const char *service) /* {{{ */
        struct addrinfo *ai_ptr;
        int status;
 
        struct addrinfo *ai_ptr;
        int status;
 
+       mt_debug ("create_socket (node = %s, service = %s);\n",
+                       node, service);
+
        memset (&ai_hint, 0, sizeof (ai_hint));
 #ifdef AI_ADDRCONFIG
        ai_hint.ai_flags |= AI_ADDRCONFIG;
        memset (&ai_hint, 0, sizeof (ai_hint));
 #ifdef AI_ADDRCONFIG
        ai_hint.ai_flags |= AI_ADDRCONFIG;
@@ -550,11 +561,15 @@ static int create_socket (const char *node, const char *service) /* {{{ */
                fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
                                ai_ptr->ai_protocol);
                if (fd < 0)
                fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
                                ai_ptr->ai_protocol);
                if (fd < 0)
+               {
+                       mt_debug ("create_socket: socket(2) failed.\n");
                        continue;
                        continue;
+               }
 
                status = connect (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
                if (status != 0)
                {
 
                status = connect (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
                if (status != 0)
                {
+                       mt_debug ("create_socket: connect(2) failed.\n");
                        close (fd);
                        continue;
                }
                        close (fd);
                        continue;
                }