X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-sflow.c;h=deebd82681d01f7f73eea4136974a47e9e62db5d;hb=7685b7a9e5b3f6db6832e52e111000ff36d3acb4;hp=cba01b9e66dee7fd1a876b835bafadbc2a12e0ea;hpb=85606e05b691be7c2f2d4bcf0e91170b71ec8fbb;p=sliver-openvswitch.git diff --git a/tests/test-sflow.c b/tests/test-sflow.c index cba01b9e6..deebd8268 100644 --- a/tests/test-sflow.c +++ b/tests/test-sflow.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc. * Copyright (c) 2013 InMon Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,7 +44,6 @@ static unixctl_cb_func test_sflow_exit; /* Datagram. */ #define SFLOW_VERSION_5 5 #define SFLOW_MIN_LEN 36 -#define SFLOW_MAX_AGENTIP_STRLEN 64 /* Sample tag numbers. */ #define SFLOW_FLOW_SAMPLE 1 @@ -82,7 +81,7 @@ struct sflow_xdr { /* Agent. */ struct sflow_addr agentAddr; - char agentIPStr[SFLOW_MAX_AGENTIP_STRLEN]; + char agentIPStr[INET6_ADDRSTRLEN + 2]; uint32_t subAgentId; uint32_t uptime_mS; @@ -325,14 +324,12 @@ process_datagram(struct sflow_xdr *x) /* Store the agent address as a string. */ if (x->agentAddr.type == SFLOW_ADDRTYPE_IP6) { - snprintf(x->agentIPStr, SFLOW_MAX_AGENTIP_STRLEN, - "%04x:%04x:%04x:%04x", - x->agentAddr.a.ip6[0], - x->agentAddr.a.ip6[1], - x->agentAddr.a.ip6[2], - x->agentAddr.a.ip6[3]); + char ipstr[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, (const void *) &x->agentAddr.a.ip6, + ipstr, INET6_ADDRSTRLEN); + snprintf(x->agentIPStr, sizeof x->agentIPStr, "[%s]", ipstr); } else { - snprintf(x->agentIPStr, SFLOW_MAX_AGENTIP_STRLEN, + snprintf(x->agentIPStr, sizeof x->agentIPStr, IP_FMT, IP_ARGS(x->agentAddr.a.ip4)); }