Skip to content

Commit

Permalink
Merge pull request #4 from spacemeowx2/broadcast
Browse files Browse the repository at this point in the history
add broadcast mode
  • Loading branch information
spacemeowx2 committed Oct 10, 2018
2 parents 708eaf5 + 1a247a2 commit d91efe3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lan-client.c
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lan-play.h
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/main.c
Expand Up @@ -5,6 +5,8 @@ struct {
int help;
int version;

bool broadcast;

char *netif;
char *netif_ipaddr;
char *netif_netmask;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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++;
}
}

Expand Down Expand Up @@ -283,6 +293,7 @@ void print_help(const char *name)
" %s\n"
" [--help]\n"
" [--version]\n"
" [--broadcast]\n"
// " [--netif-ipaddr <ipaddr>] default: 10.13.37.1\n"
// " [--netif-netmask <ipnetmask>] default: 255.255.0.0\n"
" [--relay-server-addr <addr>]\n"
Expand Down

0 comments on commit d91efe3

Please sign in to comment.