From 1a247a22f0226e713ff2026d95e9dc4121bd3433 Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Wed, 10 Oct 2018 15:46:24 +0800 Subject: [PATCH] add broadcast --- src/lan-client.c | 9 +++++++++ src/lan-play.h | 1 + src/main.c | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/lan-client.c b/src/lan-client.c index cac0081..cbbafe5 100644 --- a/src/lan-client.c +++ b/src/lan-client.c @@ -36,6 +36,15 @@ int lan_client_init(struct lan_play *lan_play) LLOG(LLOG_ERROR, "uv_udp_init %d", ret); } + if (lan_play->broadcast) { + struct sockaddr_in temp; + uv_ip4_addr("0.0.0.0", 11451, &temp); + ret = uv_udp_bind(client, (struct sockaddr *)&temp, 0); + if (ret != 0) { + LLOG(LLOG_ERROR, "uv_udp_bind %d", ret); + } + } + ret = uv_timer_init(loop, timer); if (ret != 0) { LLOG(LLOG_ERROR, "uv_timer_init %d", ret); diff --git a/src/lan-play.h b/src/lan-play.h index 41cd4ef..1b1ffde 100644 --- a/src/lan-play.h +++ b/src/lan-play.h @@ -45,6 +45,7 @@ struct lan_play { uv_udp_send_t client_send_req; // lan_client + bool broadcast; uv_udp_t client; uv_timer_t client_keepalive_timer; struct sockaddr_in server_addr; diff --git a/src/main.c b/src/main.c index 1f4b013..6024c22 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,8 @@ struct { int help; int version; + bool broadcast; + char *netif; char *netif_ipaddr; char *netif_netmask; @@ -161,6 +163,7 @@ int lan_play_init(struct lan_play *lan_play) lan_play->dev = NULL; lan_play->stop = false; + lan_play->broadcast = options.broadcast; init_pcap(lan_play, mac); @@ -202,6 +205,9 @@ int parse_arguments(int argc, char **argv) options.help = 0; options.version = 0; + options.broadcast = false; + + options.netif = NULL; options.netif_ipaddr = NULL; options.netif_netmask = NULL; @@ -251,6 +257,10 @@ int parse_arguments(int argc, char **argv) CHECK_PARAM(); options.netif = argv[i + 1]; i++; + } else if (!strcmp(arg, "--broadcast")) { + options.broadcast = true; + options.relay_server_addr = "255.255.255.255:11451"; + i++; } } @@ -283,6 +293,7 @@ void print_help(const char *name) " %s\n" " [--help]\n" " [--version]\n" + " [--broadcast]\n" // " [--netif-ipaddr ] default: 10.13.37.1\n" // " [--netif-netmask ] default: 255.255.0.0\n" " [--relay-server-addr ]\n"