From 49bfef2ecd51b854b63e35d913849b6bb518a7f6 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 13 Jan 2024 08:53:13 +0000 Subject: [PATCH] wol: portability https://github.com/warmcat/libwebsockets/issues/3048 --- include/libwebsockets.h | 1 + lib/core-net/wol.c | 9 +++++---- .../raw/minimal-raw-wol/minimal-raw-wol.c | 3 +-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/libwebsockets.h b/include/libwebsockets.h index 379afc820..f2c813b17 100644 --- a/include/libwebsockets.h +++ b/include/libwebsockets.h @@ -47,6 +47,7 @@ extern "C" { #if defined(_WIN32) && !defined(ETHER_ADDR_LEN) #define ETHER_ADDR_LEN 6 #endif +#define LWS_ETHER_ADDR_LEN ETHER_ADDR_LEN #include #include diff --git a/lib/core-net/wol.c b/lib/core-net/wol.c index ae0b03736..8edada906 100644 --- a/lib/core-net/wol.c +++ b/lib/core-net/wol.c @@ -57,9 +57,9 @@ lws_wol(struct lws_context *ctx, const char *ip_or_NULL, uint8_t *mac_6_bytes) addr.sin_family = AF_INET; addr.sin_port = htons(9); - if (!inet_aton(ip_or_NULL ? ip_or_NULL : "255.255.255.255", - &addr.sin_addr)) { - lwsl_cx_err(ctx, "failed to convert broadcast ads, errno %d\n", + if (!inet_pton(AF_INET, ip_or_NULL ? ip_or_NULL : "255.255.255.255", + &addr.sin_addr)) { + lwsl_cx_err(ctx, "failed to convert to ipv4 broadcast ads, errno %d\n", errno); goto bail; } @@ -68,7 +68,8 @@ lws_wol(struct lws_context *ctx, const char *ip_or_NULL, uint8_t *mac_6_bytes) mac_6_bytes[0], mac_6_bytes[1], mac_6_bytes[2], mac_6_bytes[3], mac_6_bytes[4], mac_6_bytes[5], ip_or_NULL ? ip_or_NULL : ""); - if (sendto(fd, pkt, sizeof(pkt), 0, (struct sockaddr *)&addr, + /* arg2 is normally const void *, on mingw it's const char * */ + if (sendto(fd, (const char *)pkt, sizeof(pkt), 0, (struct sockaddr *)&addr, sizeof(addr)) < 0) { lwsl_cx_err(ctx, "failed to sendto broadcast ads, errno %d\n", errno); diff --git a/minimal-examples-lowlevel/raw/minimal-raw-wol/minimal-raw-wol.c b/minimal-examples-lowlevel/raw/minimal-raw-wol/minimal-raw-wol.c index 8a9eca670..a2f8b793d 100644 --- a/minimal-examples-lowlevel/raw/minimal-raw-wol/minimal-raw-wol.c +++ b/minimal-examples-lowlevel/raw/minimal-raw-wol/minimal-raw-wol.c @@ -10,14 +10,13 @@ */ #include -#include int main(int argc, const char **argv) { struct lws_context_creation_info info; struct lws_context *ctx; const char *p, *ip = NULL; - uint8_t mac[ETHER_ADDR_LEN]; + uint8_t mac[LWS_ETHER_ADDR_LEN]; int ret = 1; memset(&info, 0, sizeof info);