Add function to parse IPv4 addresses
PR #2807 <https://github.com/Genymobile/scrcpy/pull/2807> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
ba547e3895
commit
52e5181c84
2 changed files with 19 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
# include <ws2tcpip.h>
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
typedef SOCKET sc_raw_socket;
|
typedef SOCKET sc_raw_socket;
|
||||||
#else
|
#else
|
||||||
|
@ -225,3 +226,15 @@ net_close(sc_socket socket) {
|
||||||
return !close(raw_sock);
|
return !close(raw_sock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
net_parse_ipv4(const char *s, uint32_t *ipv4) {
|
||||||
|
struct in_addr addr;
|
||||||
|
if (!inet_pton(AF_INET, s, &addr)) {
|
||||||
|
LOGE("Invalid IPv4 address: %s", s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ipv4 = ntohl(addr.s_addr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -68,4 +68,10 @@ net_interrupt(sc_socket socket);
|
||||||
bool
|
bool
|
||||||
net_close(sc_socket socket);
|
net_close(sc_socket socket);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse `ip` "xxx.xxx.xxx.xxx" to an IPv4 host representation
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
net_parse_ipv4(const char *ip, uint32_t *ipv4);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue