Martin,
Here's the patch.
2011-12-09 00:22, Martin Sustrik skrev:
Hi Fredrik,
I've started to make a patch to be able to bind to a local ip address
when using zmq_connect / zmq_bind. I need this since I have a bunch of
ip addresses on the machines that I will use 0mq on.
It's only a few lines in tcp_connecter.cpp to be able to do this. Have
tested locally and verified with $netstat -tn to see that i actually
works. (The hole patchfile is only 31 lines).
Nice!
However, I don't have the knowledge for make the changes that's needed
to the api to add an additionally parameter for the functions
zmq_connect and zmq_bind.
What about using PGM-like format for the address:
zmq_connect (s, "tcp://eth0;192.168.0.111:5555");
Martin
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
--
//fredan
diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp
index 6bc1b2d..56ca814 100644
--- a/src/tcp_connecter.cpp
+++ b/src/tcp_connecter.cpp
@@ -208,6 +208,26 @@ int zmq::tcp_connecter_t::open ()
sizeof (int));
errno_assert (rc != SOCKET_ERROR);
#endif
+ if (0) {
+ /* Bind the client side of the socket to the requested
+ address. */
+ struct sockaddr_storage bind_ss;
+ struct sockaddr *bind_sa = (struct sockaddr *)&bind_ss;
+ struct sockaddr_in *sin = (struct sockaddr_in *)bind_sa;
+
+ memset (sin, '\0', sizeof(sin));
+
+ sin->sin_family = AF_INET;
+ sin->sin_port = htons (0);
+ struct in_addr addr;
+ //127.0.0.1 needs to be an parameter!
+ rc = inet_aton("127.0.0.1", &addr);
+ sin->sin_addr = addr;
+
+ errno_assert (rc == 1);
+
+ assert(bind (s, bind_sa, sizeof(struct sockaddr_in)) == 0);
+ }
// Connect to the remote peer.
rc = ::connect (s, (struct sockaddr*) &addr, addr_len);
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev