]>
Commit | Line | Data |
---|---|---|
42cc2e53 | 1 | |
2 | /* | |
3 | * $Id: multicast.cc,v 1.1 1997/06/16 22:02:04 wessels Exp $ | |
4 | * | |
5 | * DEBUG: section 5 Socket Functions | |
6 | * AUTHOR: Martin Hamilton | |
7 | * | |
8 | * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ | |
9 | * -------------------------------------------------------- | |
10 | * | |
11 | * Squid is the result of efforts by numerous individuals from the | |
12 | * Internet community. Development is led by Duane Wessels of the | |
13 | * National Laboratory for Applied Network Research and funded by | |
14 | * the National Science Foundation. | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or modify | |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | * | |
30 | */ | |
31 | ||
32 | #include "squid.h" | |
33 | ||
34 | int | |
35 | mcastSetTtl(int fd, int mcast_ttl) | |
36 | { | |
37 | #ifdef IP_MULTICAST_TTL | |
38 | char ttl = (char) mcast_ttl; | |
39 | if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) | |
40 | debug(50, 1) ("comm_set_mcast_ttl: FD %d, TTL: %d: %s\n", | |
41 | fd, mcast_ttl, xstrerror()); | |
42 | #endif | |
43 | return 0; | |
44 | } | |
45 | ||
46 | void | |
47 | mcastJoinGroups(const ipcache_addrs * ia, void *data) | |
48 | { | |
49 | #ifdef IP_MULTICAST_TTL | |
50 | int fd = theInIcpConnection; | |
51 | struct ip_mreq mr; | |
52 | int i; | |
53 | int x; | |
54 | char c = 0; | |
55 | if (ia == NULL) { | |
56 | debug(5, 0) ("comm_join_mcast_groups: Unknown host\n"); | |
57 | return; | |
58 | } | |
59 | for (i = 0; i < (int) ia->count; i++) { | |
60 | debug(5, 10) ("Listening for ICP requests on %s\n", | |
61 | inet_ntoa(*(ia->in_addrs + i))); | |
62 | mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr; | |
63 | mr.imr_interface.s_addr = INADDR_ANY; | |
64 | x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, | |
65 | (char *) &mr, sizeof(struct ip_mreq)); | |
66 | if (x < 0) | |
67 | debug(5, 1) ("comm_join_mcast_groups: FD %d, [%s]\n", | |
68 | fd, inet_ntoa(*(ia->in_addrs + i))); | |
69 | x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1); | |
70 | if (x < 0) | |
71 | debug(5, 1) ("Can't disable multicast loopback: %s\n", xstrerror()); | |
72 | } | |
73 | #endif | |
74 | } | |
75 | ||
76 | void | |
77 | mcastJoinVizSock(void) | |
78 | { | |
79 | #if defined(IP_ADD_MEMBERSHIP) && defined(IP_MULTICAST_TTL) | |
80 | int x; | |
81 | if (Config.vizHack.addr.s_addr > inet_addr("224.0.0.0")) { | |
82 | struct ip_mreq mr; | |
83 | char ttl = (char) Config.vizHack.mcast_ttl; | |
84 | memset(&mr, '\0', sizeof(struct ip_mreq)); | |
85 | mr.imr_multiaddr.s_addr = Config.vizHack.addr.s_addr; | |
86 | mr.imr_interface.s_addr = INADDR_ANY; | |
87 | x = setsockopt(vizSock, | |
88 | IPPROTO_IP, | |
89 | IP_ADD_MEMBERSHIP, | |
90 | (char *) &mr, | |
91 | sizeof(struct ip_mreq)); | |
92 | if (x < 0) | |
93 | debug(50, 1) ("IP_ADD_MEMBERSHIP: FD %d, addr %s: %s\n", | |
94 | vizSock, inet_ntoa(Config.vizHack.addr), xstrerror()); | |
95 | x = setsockopt(vizSock, | |
96 | IPPROTO_IP, | |
97 | IP_MULTICAST_TTL, | |
98 | &ttl, | |
99 | sizeof(char)); | |
100 | if (x < 0) | |
101 | debug(50, 1) ("IP_MULTICAST_TTL: FD %d, TTL %d: %s\n", | |
102 | vizSock, Config.vizHack.mcast_ttl, xstrerror()); | |
103 | ttl = 0; | |
104 | x = sizeof(char); | |
105 | getsockopt(vizSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, &x); | |
106 | debug(1, 0) ("vizSock on FD %d, ttl=%d\n", vizSock, (int) ttl); | |
107 | } | |
108 | #else | |
109 | debug(1, 0) ("vizSock: Could not join multicast group\n"); | |
110 | #endif | |
111 | } |