1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

wol: portability

https://github.com/warmcat/libwebsockets/issues/3048
This commit is contained in:
Andy Green 2024-01-13 08:53:13 +00:00
parent 43df4901ee
commit 49bfef2ecd
3 changed files with 7 additions and 6 deletions

View file

@ -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>

View file

@ -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);

View file

@ -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);