mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +00:00
LibC: inet_pton() should return 1 on success, 0 or -1 on failure.
This commit is contained in:
parent
d080f6e8dd
commit
d03505bc29
3 changed files with 7 additions and 3 deletions
|
@ -29,7 +29,7 @@ int inet_pton(int af, const char* src, void* dst)
|
||||||
int count = sscanf(src, "%u.%u.%u.%u", &a, &b, &c, &d);
|
int count = sscanf(src, "%u.%u.%u.%u", &a, &b, &c, &d);
|
||||||
if (count != 4) {
|
if (count != 4) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
|
@ -45,7 +45,7 @@ int inet_pton(int af, const char* src, void* dst)
|
||||||
u.c = c;
|
u.c = c;
|
||||||
u.d = d;
|
u.d = d;
|
||||||
*(uint32_t*)dst = u.l;
|
*(uint32_t*)dst = u.l;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_addr_t inet_addr(const char* str)
|
in_addr_t inet_addr(const char* str)
|
||||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
||||||
dst_addr.sin_family = AF_INET;
|
dst_addr.sin_family = AF_INET;
|
||||||
dst_addr.sin_port = htons(80);
|
dst_addr.sin_port = htons(80);
|
||||||
rc = inet_pton(AF_INET, addr_str, &dst_addr.sin_addr);
|
rc = inet_pton(AF_INET, addr_str, &dst_addr.sin_addr);
|
||||||
if (rc < 0) {
|
if (rc <= 0) {
|
||||||
perror("inet_pton");
|
perror("inet_pton");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ int main(int argc, char** argv)
|
||||||
dst_addr.sin_family = AF_INET;
|
dst_addr.sin_family = AF_INET;
|
||||||
dst_addr.sin_port = htons(8080);
|
dst_addr.sin_port = htons(8080);
|
||||||
rc = inet_pton(AF_INET, addr_str, &dst_addr.sin_addr);
|
rc = inet_pton(AF_INET, addr_str, &dst_addr.sin_addr);
|
||||||
|
if (rc <= 0) {
|
||||||
|
perror("inet_pton");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
const char* msg = "Test message";
|
const char* msg = "Test message";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue