+ freeaddrinfo (ai_list);
+
+ return (-1);
+} /* }}} int create_socket */
+
+/*
+ * Public functions
+ */
+mt_connection_t *mt_connect (const char *node, const char *service, /* {{{ */
+ const char *username, const char *password)
+{
+ int fd;
+ mt_connection_t *c;
+
+ if ((node == NULL) || (username == NULL) || (password == NULL))
+ return (NULL);
+
+ fd = create_socket (node, (service != NULL) ? service : ROUTEROS_API_PORT);
+ if (fd < 0)
+ return (NULL);
+
+ c = malloc (sizeof (*c));
+ if (c == NULL)
+ {
+ close (fd);
+ return (NULL);
+ }
+ memset (c, 0, sizeof (*c));
+
+ c->fd = fd;
+
+ return (c);
+} /* }}} mt_connection_t *mt_connect */
+
+int mt_disconnect (mt_connection_t *c) /* {{{ */
+{
+ if (c == NULL)
+ return (EINVAL);
+
+ if (c->fd >= 0)
+ {
+ close (c->fd);
+ c->fd = -1;
+ }
+
+ free (c);
+
+ return (0);
+} /* }}} int mt_disconnect */
+
+int mt_query (mt_connection_t *c, /* {{{ */
+ const char *command,
+ size_t args_num, const char * const *args,
+ mt_reply_handler_t *handler, void *user_data)
+{
+ int status;
+ mt_reply_t *r;
+
+ status = send_command (c, command, args_num, args);