*/
#include "amanda.h"
+#include "sockaddr-util.h"
#include "ndmpconnobj.h"
/*
*addrs = g_new0(DirectTCPAddr, naddrs+1);
for (i = 0; i < naddrs; i++) {
ndmp4_tcp_addr *na = &reply->connect_addr.ndmp4_addr_u.tcp_addr.tcp_addr_val[i];
- (*addrs)[i].ipv4 = na->ip_addr;
- (*addrs)[i].port = na->port;
+ (*addrs)[i].sin.sin_family = AF_INET;
+ (*addrs)[i].sin.sin_addr.s_addr = htonl(na->ip_addr);
+ SU_SET_PORT(addrs[i], na->port);
}
}
NDMP_FREE();
return TRUE;
}
+ndmp_connection_mover_connect(
+ NDMPConnection *self,
+ ndmp9_mover_mode mode,
+ DirectTCPAddr *addrs)
+{
+ unsigned int naddrs, i;
+ ndmp4_tcp_addr *na;
+
+ g_assert(!self->startup_err);
+
+ /* count addrs */
+ g_assert(addrs);
+ for (naddrs = 0; SU_GET_FAMILY(&addrs[naddrs]) != 0; naddrs++) ;
+
+ /* convert addrs to an ndmp4_tcp_addr */
+ na = g_new0(ndmp4_tcp_addr, naddrs);
+ for (i = 0; i < naddrs; i++) {
+ na[i].ip_addr = ntohl(addrs[i].sin.sin_addr.s_addr);
+ na[i].port = SU_GET_PORT(&addrs[i]);
+ }
+
+
+ NDMP_TRANS(self, ndmp4_mover_connect)
+ request->mode = mode;
+ request->addr.addr_type = NDMP4_ADDR_TCP;
+ request->addr.ndmp4_addr_u.tcp_addr.tcp_addr_len = naddrs;
+ request->addr.ndmp4_addr_u.tcp_addr.tcp_addr_val = na;
+ NDMP_CALL(self);
+ NDMP_FREE();
+ NDMP_END
+ return TRUE;
+}
+
gboolean
ndmp_connection_mover_abort(
NDMPConnection *self)
while (1) {
gboolean found = FALSE;
+ int fd;
+ SELECT_ARG_TYPE readset;
+ int nfound;
/* if any desired notifications have been received, then we're
* done */
return TRUE;
/* otherwise, wait for an incoming packet and handle it, then try
- * again */
+ * again. There's some select trickery here to avoid hogging the
+ * ndmlib_mutex - basically, we want to block as long as possible
+ * outside of the ndmlib_mutex critical section. This will also be
+ * useful to allow the wait to be aborted. */
+ fd = self->conn->chan.fd;
+ FD_ZERO(&readset);
+ FD_SET(fd, &readset);
+ nfound = select(fd+1, &readset, NULL, NULL, NULL);
+
+ /* fall on through, blind to any errors - presumably the same error
+ * condition will be caught by ndmconn_recv_nmb. */
+
g_static_mutex_lock(&ndmlib_mutex);
NDMOS_MACRO_ZEROFILL(&nmb);
nmb.protocol_version = NDMP4VER;