Project

General

Profile

Feature #248 ยป tvheadend_ipv6.patch

patch 2 - add a minor correction - Steven VS -, 2010-07-25 20:27

View differences:

src/iptv_input.c (working copy)
186 186
{
187 187
  pthread_t tid;
188 188
  int fd;
189
  char straddr[INET6_ADDRSTRLEN];
189 190
  struct ip_mreqn m;
191
  struct ipv6_mreq m6;
190 192
  struct sockaddr_in sin;
193
  struct sockaddr_in6 sin6;
191 194
  struct ifreq ifr;
192 195
  struct epoll_event ev;
193 196

  
......
200 203
  }
201 204

  
202 205
  /* Now, open the real socket for UDP */
203

  
204
  fd = tvh_socket(AF_INET, SOCK_DGRAM, 0);
206
  if(t->tht_iptv_group.s_addr!=0) {
207
    fd = tvh_socket(AF_INET, SOCK_DGRAM, 0);
208
  
209
  }
210
  else {
211
    fd = tvh_socket(AF_INET6, SOCK_DGRAM, 0);
212
  }
205 213
  if(fd == -1) {
206 214
    tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot open socket", t->tht_identifier);
207 215
    return -1;
......
218 226
    return -1;
219 227
  }
220 228

  
221
  /* Bind to multicast group */
222
  memset(&sin, 0, sizeof(sin));
223
  sin.sin_family = AF_INET;
224
  sin.sin_port = htons(t->tht_iptv_port);
225
  sin.sin_addr.s_addr = t->tht_iptv_group.s_addr;
229
  /* Bind to IPv4 multicast group */
230
  if(t->tht_iptv_group.s_addr!=0) {
231
    memset(&sin, 0, sizeof(sin));
232
    sin.sin_family = AF_INET;
233
    sin.sin_port = htons(t->tht_iptv_port);
234
    sin.sin_addr.s_addr = t->tht_iptv_group.s_addr;
235
    if(bind(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
236
      tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot bind %s:%d -- %s",
237
           t->tht_identifier, inet_ntoa(sin.sin_addr), t->tht_iptv_port,
238
           strerror(errno));
239
      close(fd);
240
      return -1;
241
    }
242
    /* Join IPv4 group */
243
    memset(&m, 0, sizeof(m));
244
    m.imr_multiaddr.s_addr = t->tht_iptv_group.s_addr;
245
    m.imr_address.s_addr = 0;
246
    m.imr_ifindex = ifr.ifr_ifindex;
226 247

  
227
  if(bind(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
228
    tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot bind %s:%d -- %s", 
229
	   t->tht_identifier, inet_ntoa(sin.sin_addr), t->tht_iptv_port,
230
	   strerror(errno));
231
    close(fd);
232
    return -1;
248
      if(setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &m,
249
                sizeof(struct ip_mreqn)) == -1) {
250
      tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot join %s -- %s",
251
           t->tht_identifier, inet_ntoa(m.imr_multiaddr), strerror(errno));
252
      close(fd);
253
      return -1;
254
    }
255

  
233 256
  }
257
  else {
258
    /* Bind to IPv6 multicast group */
259
    memset(&sin6, 0, sizeof(sin6));
260
    sin6.sin6_family = AF_INET6;
261
    sin6.sin6_port = htons(t->tht_iptv_port);
262
    sin6.sin6_addr = t->tht_iptv_group6;
263
    if(bind(fd, (struct sockaddr *)&sin6, sizeof(sin6)) == -1) {
264
      inet_ntop(AF_INET6, &sin6.sin6_addr, straddr, sizeof(straddr));
265
      tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot bind %s:%d -- %s",
266
           t->tht_identifier, straddr, t->tht_iptv_port,
267
           strerror(errno));
268
      close(fd);
269
      return -1;
270
    }
271
    /* Join IPv6 group */
272
    memset(&m6, 0, sizeof(m6));
273
    m6.ipv6mr_multiaddr = t->tht_iptv_group6;
274
    m6.ipv6mr_interface = ifr.ifr_ifindex;
234 275

  
235
  /* Join group */
236
  memset(&m, 0, sizeof(m));
237
  m.imr_multiaddr.s_addr = t->tht_iptv_group.s_addr;
238
  m.imr_address.s_addr = 0;
239
  m.imr_ifindex = ifr.ifr_ifindex;
240

  
241
  if(setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, 
242
		sizeof(struct ip_mreqn)) == -1) {
243
    tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot join %s -- %s", 
244
	   t->tht_identifier, inet_ntoa(m.imr_multiaddr), strerror(errno));
245
    close(fd);
246
    return -1;
276
    if(setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &m6,
277
                sizeof(struct ipv6_mreq)) == -1) {
278
      inet_ntop(AF_INET6, m6.ipv6mr_multiaddr.s6_addr, straddr, sizeof(straddr));
279
      tvhlog(LOG_ERR, "IPTV", "\"%s\" cannot join %s -- %s",
280
           t->tht_identifier, straddr, strerror(errno));
281
      close(fd);
282
      return -1;
283
    }
247 284
  }
248 285

  
286

  
249 287
  memset(&ev, 0, sizeof(ev));
250 288
  ev.events = EPOLLIN;
251 289
  ev.data.fd = fd;
......
301 339
{
302 340
  htsmsg_t *m = htsmsg_create_map();
303 341
  char abuf[INET_ADDRSTRLEN];
342
  char abuf6[INET6_ADDRSTRLEN];
304 343

  
305 344
  lock_assert(&global_lock);
306 345

  
......
312 351
  if(t->tht_iptv_iface)
313 352
    htsmsg_add_str(m, "interface", t->tht_iptv_iface);
314 353

  
315
  if(t->tht_iptv_group.s_addr) {
354
  if(t->tht_iptv_group.s_addr!= 0) {
316 355
    inet_ntop(AF_INET, &t->tht_iptv_group, abuf, sizeof(abuf));
317 356
    htsmsg_add_str(m, "group", abuf);
318 357
  }
319

  
358
  if(IN6_IS_ADDR_MULTICAST(t->tht_iptv_group6.s6_addr) ) {
359
    inet_ntop(AF_INET6, &t->tht_iptv_group6, abuf6, sizeof(abuf6));
360
    htsmsg_add_str(m, "group", abuf6);
361
  }
320 362
  if(t->tht_ch != NULL) {
321 363
    htsmsg_add_str(m, "channelname", t->tht_ch->ch_name);
322 364
    htsmsg_add_u32(m, "mapped", 1);
......
340 382
iptv_transport_quality(th_transport_t *t)
341 383
{
342 384
  if(t->tht_iptv_iface == NULL || 
343
     t->tht_iptv_group.s_addr == 0 ||
385
     (t->tht_iptv_group.s_addr == 0 && t->tht_iptv_group6.s6_addr == 0) ||
344 386
     t->tht_iptv_port == 0)
345 387
    return 0;
346 388

  
......
354 396
static void
355 397
iptv_transport_setsourceinfo(th_transport_t *t, struct source_info *si)
356 398
{
399
  char straddr[INET6_ADDRSTRLEN];
357 400
  memset(si, 0, sizeof(struct source_info));
358 401

  
359 402
  si->si_adapter = t->tht_iptv_iface ? strdup(t->tht_iptv_iface) : NULL;
360
  si->si_mux = strdup(inet_ntoa(t->tht_iptv_group));
403
  if(t->tht_iptv_group.s_addr != 0) {
404
    si->si_mux = strdup(inet_ntoa(t->tht_iptv_group));
405
  }
406
  else {
407
    inet_ntop(AF_INET6, &t->tht_iptv_group6, straddr, sizeof(straddr));
408
    si->si_mux = strdup(straddr);
409
  }
361 410
}
362 411

  
363 412

  
......
453 502

  
454 503
    tvh_str_update(&t->tht_iptv_iface, htsmsg_get_str(c, "interface"));
455 504

  
456
    if((s = htsmsg_get_str(c, "group")) != NULL)
457
      inet_pton(AF_INET, s, &t->tht_iptv_group.s_addr);
505
    if((s = htsmsg_get_str(c, "group")) != NULL){
506
      if (!inet_pton(AF_INET, s, &t->tht_iptv_group.s_addr)) {
507
         inet_pton(AF_INET6, s, &t->tht_iptv_group6.s6_addr);
508
      }
509
    }
458 510
    
459 511
    if(!htsmsg_get_u32(c, "port", &u32))
460 512
      t->tht_iptv_port = u32;
src/webui/extjs.c (working copy)
1191 1191
    }
1192 1192

  
1193 1193
    if((s = htsmsg_get_str(c, "group")) != NULL) {
1194
      inet_pton(AF_INET, s, &t->tht_iptv_group.s_addr);
1194
      if(!inet_pton(AF_INET, s, &t->tht_iptv_group.s_addr)){
1195
      	inet_pton(AF_INET6, s, &t->tht_iptv_group6.s6_addr);
1196
      }
1195 1197
      save = 1;
1196 1198
    }
1197 1199
    
......
1212 1214
{
1213 1215
  htsmsg_t *r = htsmsg_create_map();
1214 1216
  char abuf[INET_ADDRSTRLEN];
1215

  
1217
  char abuf6[INET6_ADDRSTRLEN];
1216 1218
  htsmsg_add_str(r, "id", t->tht_identifier);
1217 1219

  
1218 1220
  htsmsg_add_str(r, "channelname", t->tht_ch ? t->tht_ch->ch_name : "");
1219 1221
  htsmsg_add_str(r, "interface", t->tht_iptv_iface ?: "");
1220 1222

  
1221
  inet_ntop(AF_INET, &t->tht_iptv_group, abuf, sizeof(abuf));
1222
  htsmsg_add_str(r, "group", t->tht_iptv_group.s_addr ? abuf : "");
1223
  if(t->tht_iptv_group.s_addr != 0){
1224
    inet_ntop(AF_INET, &t->tht_iptv_group, abuf, sizeof(abuf));
1225
    htsmsg_add_str(r, "group", t->tht_iptv_group.s_addr ? abuf : "");
1226
  }
1227
  else {
1228
    inet_ntop(AF_INET6, &t->tht_iptv_group6, abuf6, sizeof(abuf6));
1229
    htsmsg_add_str(r, "group", t->tht_iptv_group6.s6_addr ? abuf6 : "");
1230
  }
1223 1231

  
1224 1232
  htsmsg_add_u32(r, "port", t->tht_iptv_port);
1225 1233
  htsmsg_add_u32(r, "enabled", t->tht_enabled);
......
1256 1264
  in = entries != NULL ? htsmsg_json_deserialize(entries) : NULL;
1257 1265

  
1258 1266
  if(!strcmp(op, "get")) {
1259

  
1260 1267
    LIST_FOREACH(t, &iptv_all_transports, tht_group_link)
1261 1268
      count++;
1262 1269
    tvec = alloca(sizeof(th_transport_t *) * count);
......
1288 1295
  } else if(!strcmp(op, "delete")) {
1289 1296
    if(in != NULL)
1290 1297
      extjs_transport_delete(in);
1291

  
1298
    
1292 1299
    out = htsmsg_create_map();
1293 1300

  
1294 1301
  } else {
src/tvhead.h (working copy)
657 657
   */
658 658
  char *tht_iptv_iface;
659 659
  struct in_addr tht_iptv_group;
660
  struct in6_addr tht_iptv_group6;
660 661
  uint16_t tht_iptv_port;
661 662
  int tht_iptv_fd;
662 663

  
    (1-1/1)