nicer formatting
[tridge/junkcode.git] / igmp / chan_scan.c
1 #define _GNU_SOURCE
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <emcast/libemcast.h>
6
7
8 static int check_channel(int c)
9 {
10         char *url;
11         Emcast *emcast;
12         int fd, ret;
13         fd_set rfds;
14         struct timeval tv;
15
16         asprintf(&url,"239.193.0.%d:8208", c);
17
18         ret = emcast_new(&emcast, url);
19
20         fd = emcast_join(emcast, url);
21
22         FD_ZERO(&rfds);
23         FD_SET(fd, &rfds);
24
25         tv.tv_sec = 1;
26         tv.tv_usec = 0;
27
28         ret = select(fd+1, &rfds, NULL, NULL, &tv);
29
30         emcast_leave(emcast);
31
32         if (ret == 1) {
33                 return 1;
34         }
35
36
37         free(url);
38
39         return 0;
40 }
41
42 int main(void)
43 {
44         int i;
45
46         for (i=0;i<255;i++) {
47                 printf("checking %d\r", i);
48                 fflush(stdout);
49                 if (check_channel(i) || 
50                     check_channel(i) ||
51                     check_channel(i)) {
52                         printf("Active channel %d\n", i);
53                 }
54         }
55
56         return 0;
57 }