Skip to content

Add support for UDP multicast #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for UDP multicast
This change extends the UDP audio device syntax to accept strings like

   udp:239.0.0.1:7355

This allows Direwolf to decode an audio stream sent to a multicast group address.
  • Loading branch information
MikePlayle committed Apr 1, 2019
commit fde780f110994342ea3452d3ebb000503071cb3f
38 changes: 36 additions & 2 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,23 @@ int audio_open (struct audio_s *pa)
return -1;
}

char mcaddr[20];
unsigned port = DEFAULT_UDP_AUDIO_PORT;
int is_multicast = 0;

if (sscanf(audio_in_name, "udp:%[0-9.]:%d", mcaddr, &port)==2) {
is_multicast = 1;
} else if (sscanf(audio_in_name, "udp:%d", &port)==1) {
is_multicast = 0;
} else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Couldn't parse address '%s'\n", audio_in_name);
return -1;
}

memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons((short)atoi(audio_in_name+4));
si_me.sin_port = htons(port);
si_me.sin_addr.s_addr = htonl(INADDR_ANY);

//Bind to the socket
Expand All @@ -396,7 +410,27 @@ int audio_open (struct audio_s *pa)
dw_printf ("Couldn't bind socket, errno %d\n", errno);
return -1;
}
}

if (is_multicast) {
struct ip_mreq mreq;

if(!inet_aton(mcaddr, &mreq.imr_multiaddr)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Couldn't parse multicast address %s\n", mcaddr);
return -1;
}

mreq.imr_interface.s_addr = htonl(INADDR_ANY);

if (setsockopt(adev[a].udp_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof(mreq))==-1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Couldn't add multicast group, errno %d\n", errno);
return -1;
}
}
}

adev[a].inbuf_size_in_bytes = SDR_UDP_BUF_MAXLEN;

break;
Expand Down