github-actions[bot] commented on code in PR #14063:
URL: https://github.com/apache/doris/pull/14063#discussion_r1103818977


##########
be/src/util/network_util.cpp:
##########
@@ -39,22 +39,38 @@
 namespace doris {
 
 InetAddress::InetAddress(struct sockaddr* addr) {
-    this->addr = *(struct sockaddr_in*)addr;
+    this->addr = *(struct sockaddr_storage*)addr;
 }
 
-bool InetAddress::is_address_v4() const {
-    return addr.sin_family == AF_INET;
+bool InetAddress::is_loopback() {
+    if (addr.ss_family == AF_INET) {
+        in_addr_t s_addr = ((struct sockaddr_in*)&addr)->sin_addr.s_addr;
+        return (ntohl(s_addr) & 0xFF000000) == 0x7F000000;
+    } else if (addr.ss_family == AF_INET6) {
+        struct in6_addr in6_addr = ((struct sockaddr_in6*)&addr)->sin6_addr;
+        return IN6_IS_ADDR_LOOPBACK(&in6_addr);
+    } else {
+        LOG(WARNING) << "unknown address family: " << addr.ss_family;
+        return false;
+    }
 }
 
-bool InetAddress::is_loopback_v4() {
-    in_addr_t s_addr = addr.sin_addr.s_addr;
-    return (ntohl(s_addr) & 0xFF000000) == 0x7F000000;
+std::string InetAddress::get_host_address() {
+    if (addr.ss_family == AF_INET) {
+        char addr_buf[INET_ADDRSTRLEN];
+        inet_ntop(AF_INET, &(((struct sockaddr_in*)&addr)->sin_addr), 
addr_buf, INET_ADDRSTRLEN);
+        return std::string(addr_buf);
+    } else if (addr.ss_family == AF_INET6) {
+        char addr_buf[INET6_ADDRSTRLEN];
+        inet_ntop(AF_INET6, &(((struct sockaddr_in6*)&addr)->sin6_addr), 
addr_buf,
+                  INET6_ADDRSTRLEN);
+        return std::string(addr_buf);
+    } else {
+        return std::string {"unknown address family: " + addr.ss_family};

Review Comment:
   warning: adding 'sa_family_t' (aka 'unsigned short') to a string does not 
append to the string [clang-diagnostic-string-plus-int]
   ```cpp
           return std::string {"unknown address family: " + addr.ss_family};
                                                          ^
   ```
   **be/src/util/network_util.cpp:68:** use array indexing to silence this 
warning
   ```cpp
           return std::string {"unknown address family: " + addr.ss_family};
                                                          ^
   ```
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to