From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Ammar Faizi <[email protected]>, Yonle <[email protected]>
Subject: [PATCH gwhttpd 1/2] gwhttpd: Explicitly set sa_family before bind()
Date: Sun, 26 Jun 2022 09:45:30 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Yonle reported that he is getting an error on bind():
Address family not supported by protocol
This doesn't mean that Yonle's device doesn't support IPv4, but it's
because we don't explicitly set the sa_family to AF_INET. This will
happen to work just fine only on a platform where `AF_INET == 0` since
we have a prior memset() call that zeroes the whole struct sockaddr_in.
On platforms that have `AF_INET != 0`, this will break. Fix this by
simply setting the `saddr.sa_family` to AF_INET at initialization.
Fixes: https://github.com/ammarfaizi2/gwhttpd/issues/1
Link: https://t.me/GNUWeeb/627604
Reported-by: Yonle <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
gwhttpd.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/gwhttpd.cpp b/gwhttpd.cpp
index 4ec3fe3..d038939 100644
--- a/gwhttpd.cpp
+++ b/gwhttpd.cpp
@@ -142,6 +142,7 @@ static int init_socket(struct server_state *state, const char *addr,
}
memset(&saddr, 0, sizeof(saddr));
+ saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
saddr.sin_addr.s_addr = inet_addr(addr);
--
Ammar Faizi
next prev parent reply other threads:[~2022-06-26 2:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-26 2:45 [PATCH gwhttpd 0/2] Two gwhttpd fixes Ammar Faizi
2022-06-26 2:45 ` Ammar Faizi [this message]
2022-06-26 2:45 ` [PATCH gwhttpd 2/2] gwhttpd: Fix `EBADF` errors at destruction Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox