[ofa-general] RFC PATCHv2 IPv6 support in rping
Aleksey Senin
alekseys at voltaire.com
Thu Aug 14 02:00:22 PDT 2008
Differences between version 1
Using new code from Sean
Less complicated logic due to using getaddrinfo function
Using sockaddr_storage in rping_cb instead of sockaddr_in in order
to support IPv6
Return code of get_addr is return code of getaddrinfo function
Removed label out from get_addr function
Extended help to explaing using how to bind ANY address when using
IPv6
Signed-off-by: Aleksey Senin <alekseys at voltaire.com>
---
examples/rping.c | 29 ++++++++++++++++-------------
1 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/examples/rping.c b/examples/rping.c
index f5dd701..17782b2 100644
--- a/examples/rping.c
+++ b/examples/rping.c
@@ -143,7 +143,7 @@ struct rping_cb {
enum test_state state; /* used for cond/signalling */
sem_t sem;
- struct sockaddr_in sin;
+ struct sockaddr_storage sin;
uint16_t port; /* dst port in NBO */
int verbose; /* verbose logging */
int count; /* ping count */
@@ -728,8 +728,11 @@ static int rping_test_server(struct rping_cb *cb)
static int rping_bind_server(struct rping_cb *cb)
{
int ret;
+ if (cb->sin.ss_family == AF_INET)
+ ((struct sockaddr_in *)&cb->sin)->sin_port = cb->port;
+ else
+ ((struct sockaddr_in6 *)&cb->sin)->sin6_port = cb->port;
- cb->sin.sin_port = cb->port;
ret = rdma_bind_addr(cb->cm_id, (struct sockaddr *) &cb->sin);
if (ret) {
fprintf(stderr, "rdma_bind_addr error %d\n", ret);
@@ -991,8 +994,11 @@ static int rping_connect_client(struct rping_cb *cb)
static int rping_bind_client(struct rping_cb *cb)
{
int ret;
+ if (cb->sin.ss_family == AF_INET )
+ ((struct sockaddr_in *)&cb->sin)->sin_port = cb->port;
+ else
+ ((struct sockaddr_in6 *)&cb->sin)->sin6_port = cb->port;
- cb->sin.sin_port = cb->port;
ret = rdma_resolve_addr(cb->cm_id, NULL, (struct sockaddr *) &cb->sin, 2000);
if (ret) {
fprintf(stderr, "rdma_resolve_addr error %d\n", ret);
@@ -1055,7 +1061,7 @@ err1:
return ret;
}
-static int get_addr(char *dst, struct sockaddr_in *addr)
+static int get_addr(char *dst, struct sockaddr *addr)
{
struct addrinfo *res;
int ret;
@@ -1066,13 +1072,10 @@ static int get_addr(char *dst, struct sockaddr_in *addr)
return ret;
}
- if (res->ai_family != PF_INET) {
- ret = -1;
- goto out;
+ if (res->ai_family == PF_INET || res->ai_family == PF_INET6 ) {
+ *(struct sockaddr_storage *)addr =
+ *(struct sockaddr_storage *)res->ai_addr;
}
-
- *addr = *(struct sockaddr_in *) res->ai_addr;
-out:
freeaddrinfo(res);
return ret;
}
@@ -1084,7 +1087,7 @@ static void usage(char *name)
printf("%s -c [-vVd] [-S size] [-C count] -a addr [-p port]\n",
basename(name));
printf("\t-c\t\tclient side\n");
- printf("\t-s\t\tserver side\n");
+ printf("\t-s\t\tserver side. To bind any address with IPv6 use -a ::0 argument\n");
printf("\t-v\t\tdisplay ping data to stdout\n");
printf("\t-V\t\tvalidate ping data\n");
printf("\t-d\t\tdebug printfs\n");
@@ -1110,7 +1113,7 @@ int main(int argc, char *argv[])
cb->server = -1;
cb->state = IDLE;
cb->size = 64;
- cb->sin.sin_family = PF_INET;
+ cb->sin.ss_family = PF_INET;
cb->port = htons(7174);
sem_init(&cb->sem, 0, 0);
@@ -1118,7 +1121,7 @@ int main(int argc, char *argv[])
while ((op=getopt(argc, argv, "a:Pp:C:S:t:scvVd")) != -1) {
switch (op) {
case 'a':
- ret = get_addr(optarg, &cb->sin);
+ ret = get_addr(optarg, (struct sockaddr *) &cb->sin);
break;
case 'P':
persistent_server = 1;
--
1.5.6.dirty
More information about the general
mailing list