SolidWallOfCode commented on a change in pull request #7821:
URL: https://github.com/apache/trafficserver/pull/7821#discussion_r633695685
##########
File path: src/tscore/ink_inet.cc
##########
@@ -463,6 +463,27 @@ IpAddr::toString(char *dest, size_t len) const
return dest;
}
+sockaddr *
+IpAddr::toSockAddr(sockaddr *dest) const
+{
+ if (AF_INET == _family) {
+ dest->sa_family = AF_INET;
+ ats_ip4_addr_cast(dest) = _addr._ip4;
+#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
+ dest->sin_len = sizeof(sockaddr_in);
+#endif
+ } else if (AF_INET6 == _family) {
+ dest->sa_family = AF_INET6;
+ ats_ip6_addr_cast(dest) = _addr._ip6;
+#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
+ dest->sin6_len = sizeof(sockaddr_in6);
+#endif
+ } else {
+ dest->sa_family = AF_UNSPEC;
Review comment:
Depends on whether you want to crash on use of an invalid instance. The
common use case will be something like
```
sockaddr_storage sa;
int result = bind(sock_fd, addr.toSockAddr(&sa), options);
```
Currently this will fail on an invalid `addr` and be indicated by `result`
having a error value. If instead `nullptr` was returned the invalid `addr`
would cause a crash. As a user of this, I'd prefer the former.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]