mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-11 05:33:56 +00:00
Fix #60
This commit is contained in:
parent
083106339c
commit
3eff00bbc8
18
httplib.h
18
httplib.h
@ -592,20 +592,18 @@ inline bool is_connection_error()
|
|||||||
|
|
||||||
inline std::string get_remote_addr(socket_t sock) {
|
inline std::string get_remote_addr(socket_t sock) {
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
char ipstr[INET6_ADDRSTRLEN];
|
|
||||||
socklen_t len = sizeof(addr);
|
socklen_t len = sizeof(addr);
|
||||||
getpeername(sock, (struct sockaddr*)&addr, &len);
|
|
||||||
|
|
||||||
// deal with both IPv4 and IPv6:
|
if (!getpeername(sock, (struct sockaddr*)&addr, &len)) {
|
||||||
if (addr.ss_family == AF_INET) {
|
char ipstr[NI_MAXHOST];
|
||||||
auto s = (struct sockaddr_in *)&addr;
|
|
||||||
inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof(ipstr));
|
if (!getnameinfo((struct sockaddr*)&addr, len,
|
||||||
} else { // AF_INET6
|
ipstr, sizeof(ipstr), nullptr, 0, NI_NUMERICHOST)) {
|
||||||
auto s = (struct sockaddr_in6 *)&addr;
|
return ipstr;
|
||||||
inet_ntop(AF_INET6, &s->sin6_addr, ipstr, sizeof(ipstr));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipstr;
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_file(const std::string& path)
|
inline bool is_file(const std::string& path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user