1 --- a/mcproxy/src/utils/mc_socket.cpp
2 +++ b/mcproxy/src/utils/mc_socket.cpp
7 +#if !defined(__GLIBC__) || defined(__UCLIBC__)
8 +#include "sourcefilter.cpp"
9 +#endif /* __GLIBC__ */
11 std::string ipAddrResolver(std::string ipAddr)
13 std::string str[][2] = {
15 +++ b/mcproxy/src/utils/sourcefilter.cpp
17 +/* Get source filter. Linux version.
18 + Copyright (C) 2004-2014 Free Software Foundation, Inc.
19 + This file is part of the GNU C Library.
20 + Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
22 + The GNU C Library is free software; you can redistribute it and/or
23 + modify it under the terms of the GNU Lesser General Public
24 + License as published by the Free Software Foundation; either
25 + version 2.1 of the License, or (at your option) any later version.
27 + The GNU C Library is distributed in the hope that it will be useful,
28 + but WITHOUT ANY WARRANTY; without even the implied warranty of
29 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 + Lesser General Public License for more details.
32 + You should have received a copy of the GNU Lesser General Public
33 + License along with the GNU C Library; if not, see
34 + <http://www.gnu.org/licenses/>. */
41 +#include <netinet/in.h>
42 +#include <netpacket/packet.h>
43 +#include <sys/param.h>
44 +#include <sys/socket.h>
53 + /* Sort the array according to importance of the protocols. Add
54 + more protocols when they become available. */
55 + { SOL_IP, AF_INET, sizeof (struct sockaddr_in) },
56 + { SOL_IPV6, AF_INET6, sizeof (struct sockaddr_in6) },
57 + { SOL_PACKET, AF_PACKET, sizeof (struct sockaddr_ll) }
59 +#define NSOL_MAP (sizeof (sol_map) / sizeof (sol_map[0]))
62 +/* Try to determine the socket level value. Ideally both side and
63 + family are set. But sometimes only the size is correct and the
64 + family value might be bogus. Loop over the array entries and look
65 + for a perfect match or the first match based on size. */
67 +__get_sol (int af, socklen_t len)
69 + int first_size_sol = -1;
71 + for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
73 + /* Just a test so that we make sure the special value used to
74 + signal the "we have so far no socket level value" is OK. */
75 + assert (sol_map[cnt].sol != -1);
77 + if (len == sol_map[cnt].size)
79 + /* The size matches, which is a requirement. If the family
80 + matches, too, we have a winner. Otherwise we remember the
81 + socket level value for this protocol if it is the first
83 + if (af == sol_map[cnt].af)
85 + return sol_map[cnt].sol;
87 + if (first_size_sol == -1)
88 + first_size_sol = sol_map[cnt].sol;
92 + return first_size_sol;
97 +getsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
98 + socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc,
99 + struct sockaddr_storage *slist)
101 + /* We have to create an struct ip_msfilter object which we can pass
103 + socklen_t needed = GROUP_FILTER_SIZE (*numsrc);
104 + struct group_filter *gf;
105 + gf = (struct group_filter *) malloc (needed);
109 + gf->gf_interface = interface;
110 + memcpy (&gf->gf_group, group, grouplen);
111 + gf->gf_numsrc = *numsrc;
113 + /* We need to provide the appropriate socket level value. */
115 + int sol = __get_sol (group->sa_family, grouplen);
123 + result = getsockopt (s, sol, MCAST_MSFILTER, gf, &needed);
125 + /* If successful, copy the results to the places the caller wants
129 + *fmode = gf->gf_fmode;
130 + memcpy (slist, gf->gf_slist,
131 + MIN (*numsrc, gf->gf_numsrc)
132 + * sizeof (struct sockaddr_storage));
133 + *numsrc = gf->gf_numsrc;
137 + int save_errno = errno;
139 + errno = save_errno;
146 +setsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
147 + socklen_t grouplen, uint32_t fmode, uint32_t numsrc,
148 + const struct sockaddr_storage *slist)
150 + /* We have to create an struct ip_msfilter object which we can pass
152 + size_t needed = GROUP_FILTER_SIZE (numsrc);
154 + struct group_filter *gf;
155 + gf = (struct group_filter *) malloc (needed);
159 + gf->gf_interface = interface;
160 + memcpy (&gf->gf_group, group, grouplen);
161 + gf->gf_fmode = fmode;
162 + gf->gf_numsrc = numsrc;
163 + memcpy (gf->gf_slist, slist, numsrc * sizeof (struct sockaddr_storage));
165 + /* We need to provide the appropriate socket level value. */
167 + int sol = __get_sol (group->sa_family, grouplen);
174 + result = setsockopt (s, sol, MCAST_MSFILTER, gf, needed);
176 + int save_errno = errno;
178 + errno = save_errno;