193 |
193 |
|
194 |
194 |
/* IPv4 */
|
195 |
195 |
if (uc->ip.ss_family == AF_INET) {
|
196 |
|
#if defined(PLATFORM_DARWIN)
|
197 |
|
struct ip_mreq m;
|
198 |
|
#else
|
199 |
|
struct ip_mreqn m;
|
200 |
|
#endif
|
201 |
|
memset(&m, 0, sizeof(m));
|
|
196 |
memset(&uc->mreg4, 0, sizeof(uc->mreg4));
|
202 |
197 |
|
203 |
198 |
/* Bind */
|
204 |
199 |
if (bind(fd, (struct sockaddr *)&uc->ip, sizeof(struct sockaddr_in)) == -1) {
|
... | ... | |
210 |
205 |
|
211 |
206 |
if (uc->multicast) {
|
212 |
207 |
/* Join group */
|
213 |
|
m.imr_multiaddr = IP_AS_V4(uc->ip, addr);
|
|
208 |
uc->mreg4.imr_multiaddr = IP_AS_V4(uc->ip, addr);
|
214 |
209 |
#if !defined(PLATFORM_DARWIN)
|
215 |
|
m.imr_address.s_addr = 0;
|
216 |
|
m.imr_ifindex = ifindex;
|
|
210 |
uc->mreg4.imr_address.s_addr = 0;
|
|
211 |
uc->mreg4.imr_ifindex = ifindex;
|
217 |
212 |
#else
|
218 |
|
if (udp_get_ifaddr(fd, ifname, &m.imr_interface) == -1) {
|
|
213 |
if (udp_get_ifaddr(fd, ifname, &uc->mreg4.imr_interface) == -1) {
|
219 |
214 |
tvherror(subsystem, "%s - cannot find ip address for interface %s [e=%s]",
|
220 |
215 |
name, ifname, strerror(errno));
|
221 |
216 |
goto error;
|
222 |
217 |
}
|
223 |
218 |
#endif
|
224 |
219 |
|
225 |
|
if (setsockopt(fd, udp_get_solip(), IP_ADD_MEMBERSHIP, &m, sizeof(m))) {
|
226 |
|
inet_ntop(AF_INET, &m.imr_multiaddr, buf, sizeof(buf));
|
|
220 |
if (setsockopt(fd, udp_get_solip(), IP_ADD_MEMBERSHIP, &uc->mreg4, sizeof(uc->mreg4))) {
|
|
221 |
inet_ntop(AF_INET, &uc->mreg4.imr_multiaddr, buf, sizeof(buf));
|
227 |
222 |
tvhwarn(subsystem, "%s - cannot join %s [%s]",
|
228 |
223 |
name, buf, strerror(errno));
|
229 |
224 |
}
|
... | ... | |
403 |
398 |
{
|
404 |
399 |
if (uc == NULL || uc == UDP_FATAL_ERROR)
|
405 |
400 |
return;
|
406 |
|
if (uc->fd >= 0)
|
|
401 |
if (uc->fd >= 0) {
|
|
402 |
if (uc->multicast) {
|
|
403 |
if (setsockopt(uc->fd, udp_get_solip(), IP_DROP_MEMBERSHIP, &uc->mreg4, sizeof (uc->mreg4)) < 0 ) {
|
|
404 |
tvhwarn(uc->subsystem, "cannot leave multicast group: %s", strerror(errno));
|
|
405 |
}
|
|
406 |
}
|
407 |
407 |
close(uc->fd);
|
|
408 |
}
|
408 |
409 |
free(uc->host);
|
409 |
410 |
free(uc->ifname);
|
410 |
411 |
free(uc->subsystem);
|