Skip to content

Commit

Permalink
wol: portability
Browse files Browse the repository at this point in the history
  • Loading branch information
lws-team committed Jan 13, 2024
1 parent 43df490 commit 49bfef2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/libwebsockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>
#include <string.h>
Expand Down
9 changes: 5 additions & 4 deletions lib/core-net/wol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
*/

#include <libwebsockets.h>
#include <net/if.h>

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);
Expand Down

0 comments on commit 49bfef2

Please sign in to comment.