mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Userland: Treat inet_pton returning 0 as an error
The POSIX man-page states that inet_pton returns 0 if the input is not a valid IPv4 dotted-decimal string or a valid IPv6 address string. This is also how it is implemented in SerenityOS. This means that we should treat a return value of 0 as an error to avoid using an invalid address (or 0.0.0.0).
This commit is contained in:
parent
f7667901ed
commit
d7797c8bf8
2 changed files with 2 additions and 2 deletions
|
@ -62,7 +62,7 @@ in_addr_t inet_addr(const char* str)
|
||||||
{
|
{
|
||||||
in_addr_t tmp {};
|
in_addr_t tmp {};
|
||||||
int rc = inet_pton(AF_INET, str, &tmp);
|
int rc = inet_pton(AF_INET, str, &tmp);
|
||||||
if (rc < 0)
|
if (rc <= 0)
|
||||||
return INADDR_NONE;
|
return INADDR_NONE;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ int main(int argc, char** argv)
|
||||||
sa.sin_port = htons(port);
|
sa.sin_port = htons(port);
|
||||||
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
if (target) {
|
if (target) {
|
||||||
if (inet_pton(AF_INET, target, &sa.sin_addr) < 0) {
|
if (inet_pton(AF_INET, target, &sa.sin_addr) <= 0) {
|
||||||
perror("inet_pton");
|
perror("inet_pton");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue