[ofa-general] librdmacm: rdma_bind_addr() doesn't return port
Aaron Fabbri (aafabbri)
aafabbri at cisco.com
Mon Jun 9 18:20:25 PDT 2008
>From the man page, and from this past discussion:
http://article.gmane.org/gmane.linux.drivers.openib/45444
I was under the impression that rdma_bind_addr(), called with a zero
port, would modify the caller's address with the assigned port.
However, this is not the case. As Roland and Sean pointed out to me,
rdma_get_src_port() can be used to get the assigned port, and this is
analogous to the regular socket bind() + getsockname() API.
Keeping with that convention, I recommend just changing the man page as
follows:
diff --git a/man/rdma_bind_addr.3 b/man/rdma_bind_addr.3
index 46c48a3..55d1b9c 100644
--- a/man/rdma_bind_addr.3
+++ b/man/rdma_bind_addr.3
@@ -22,8 +22,8 @@ to a specific port number, but it may also be called
on the active side
of a connection before calling rdma_resolve_addr to bind to a specific
address.
.P
-If used to bind to port 0, the rdma_cm will select an available port
-and return it to the user.
+If used to bind to port 0, the rdma_cm will select an available port,
which can
+be retrieved with rdma_get_src_port(3).
.SH "SEE ALSO"
rdma_create_id(3), rdma_listen(3), rdma_resolve_addr(3),
rdma_create_qp(3),
rdma_get_local_addr(3), rdma_get_src_port(3)
Another option would be to make rdma_bind_addr() return the effective
address (but just changing the man page is easier):
diff --git a/src/cma.c b/src/cma.c
index fc98c8f..2ec5ba5 100644
--- a/src/cma.c
+++ b/src/cma.c
@@ -531,7 +531,12 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct
sockaddr *addr)
if (ret != size)
return (ret > 0) ? -ENODATA : ret;
- return ucma_query_route(id);
+ ret = ucma_query_route(id);
+ if (ret)
+ return ret;
+
+ memcpy(addr, &id->route.addr.src_addr, addrlen);
+ return 0;
More information about the general
mailing list