From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from integral2.. (unknown [125.160.108.65]) by gnuweeb.org (Postfix) with ESMTPSA id CBC3E7F949; Sun, 26 Jun 2022 02:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1656211545; bh=6YvBQRIMrVSVL8h3Hnh8tpcFVerTZCLg2qIqyUPqfZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P640xPwDKMyKerPDVU32Ih7Ag2nBdbBoUiWufF954uAvWp6Po5zuD9vKWWQ7SoXGs 3xnxquWkRW9zpQ+MgrY6WHTxwJjg528zfEa+jfB5NfkfchTVt6UHyKi+R8R2hGuI4w 0FSS7H2C3gP2DRp2Zy0WB3H9uCXAFE3DnfCe85N+ZCy5rFk1wvxt0dD7VPqRFJw1yZ QiM5SuHqiNAAOud/ZY1C2nNQyXS1NThtv+tijlDXwKCXdwE+/FPMboWrY1J/C4JJPR coGSKJxoFVvihMqz4q+ot4s3shWMrcSC7pZr+BYePjUWr3eRW8pK5Uu/DUS02ffqrj xnH9Uk3pmx2jw== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Yonle Subject: [PATCH gwhttpd 1/2] gwhttpd: Explicitly set sa_family before bind() Date: Sun, 26 Jun 2022 09:45:30 +0700 Message-Id: <20220626024531.657451-2-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220626024531.657451-1-ammarfaizi2@gnuweeb.org> References: <20220626024531.657451-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 Signed-off-by: Ammar Faizi --- 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