Skip to content

Commit 61a20e6

Browse files
committed
use pointer for C structure
1 parent 7375aa7 commit 61a20e6

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Span.h

+14-10
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class Endpoint
5858
with_service_name(service);
5959
with_addr(addr);
6060
}
61-
Endpoint(const std::string &service, const sockaddr_in &addr)
61+
Endpoint(const std::string &service, const sockaddr_in *addr)
6262
{
6363
with_service_name(service);
6464
with_addr(addr);
6565
}
66-
Endpoint(const std::string &service, const sockaddr_in6 &addr)
66+
Endpoint(const std::string &service, const sockaddr_in6 *addr)
6767
{
6868
with_service_name(service);
6969
with_addr(addr);
@@ -104,12 +104,12 @@ class Endpoint
104104
/**
105105
* \brief with IPv4 address
106106
*/
107-
inline Endpoint &with_addr(const struct sockaddr_in &addr);
107+
inline Endpoint &with_addr(const struct sockaddr_in *addr);
108108

109109
/**
110110
* \brief with IPv6 address
111111
*/
112-
inline Endpoint &with_addr(const struct sockaddr_in6 &addr);
112+
inline Endpoint &with_addr(const struct sockaddr_in6 *addr);
113113

114114
/**
115115
* \brief with IP address
@@ -1045,19 +1045,23 @@ Endpoint &Endpoint::with_service_name(const std::string &service_name)
10451045
return *this;
10461046
}
10471047

1048-
Endpoint &Endpoint::with_addr(const sockaddr_in &addr)
1048+
Endpoint &Endpoint::with_addr(const struct sockaddr_in *addr)
10491049
{
1050+
assert(addr);
1051+
10501052
m_host.__isset.ipv6 = 0;
1051-
m_host.__set_ipv4(addr.sin_addr.s_addr);
1052-
m_host.__set_port(addr.sin_port);
1053+
m_host.__set_ipv4(addr->sin_addr.s_addr);
1054+
m_host.__set_port(addr->sin_port);
10531055

10541056
return *this;
10551057
}
10561058

1057-
Endpoint &Endpoint::with_addr(const sockaddr_in6 &addr)
1059+
Endpoint &Endpoint::with_addr(const struct sockaddr_in6 *addr)
10581060
{
1059-
m_host.__set_ipv6(std::string(reinterpret_cast<const char *>(addr.sin6_addr.s6_addr), sizeof(addr.sin6_addr)));
1060-
m_host.__set_port(addr.sin6_port);
1061+
assert(addr);
1062+
1063+
m_host.__set_ipv6(std::string(reinterpret_cast<const char *>(addr->sin6_addr.s6_addr), sizeof(addr->sin6_addr)));
1064+
m_host.__set_port(addr->sin6_port);
10611065

10621066
return *this;
10631067
}

test/TestSpan.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ TEST(span, serialize_json)
240240
sockaddr_in addr;
241241
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
242242
addr.sin_port = 80;
243-
zipkin::Endpoint host("host", addr);
243+
zipkin::Endpoint host("host", &addr);
244244

245245
span.client_send(&host);
246246
span.annotate("bool", true, &host);
@@ -322,7 +322,7 @@ TEST(span, annotate_stream)
322322
sockaddr_in addr;
323323
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
324324
addr.sin_port = 80;
325-
zipkin::Endpoint host("host", addr);
325+
zipkin::Endpoint host("host", &addr);
326326

327327
span << zipkin::TraceKeys::CLIENT_SEND
328328
<< std::string("hello") << host

0 commit comments

Comments
 (0)