1 Index: mcproxy-2017-08-24-93b5ace42268160ebbfff4c61818fb15fa2d9b99/mcproxy/src/utils/mc_socket.cpp
2 ===================================================================
3 --- mcproxy-2017-08-24-93b5ace42268160ebbfff4c61818fb15fa2d9b99.orig/mcproxy/src/utils/mc_socket.cpp
4 +++ mcproxy-2017-08-24-93b5ace42268160ebbfff4c61818fb15fa2d9b99/mcproxy/src/utils/mc_socket.cpp
10 +#include "sourcefilter.cpp"
11 +#endif /* __GLIBC__ */
13 std::string ipAddrResolver(std::string ipAddr)
15 std::string str[][2] = {
16 Index: mcproxy-2017-08-24-93b5ace42268160ebbfff4c61818fb15fa2d9b99/mcproxy/src/utils/sourcefilter.cpp
17 ===================================================================
19 +++ mcproxy-2017-08-24-93b5ace42268160ebbfff4c61818fb15fa2d9b99/mcproxy/src/utils/sourcefilter.cpp
21 +/* Get source filter. Linux version.
22 + Copyright (C) 2004-2014 Free Software Foundation, Inc.
23 + This file is part of the GNU C Library.
24 + Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
26 + The GNU C Library is free software; you can redistribute it and/or
27 + modify it under the terms of the GNU Lesser General Public
28 + License as published by the Free Software Foundation; either
29 + version 2.1 of the License, or (at your option) any later version.
31 + The GNU C Library is distributed in the hope that it will be useful,
32 + but WITHOUT ANY WARRANTY; without even the implied warranty of
33 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 + Lesser General Public License for more details.
36 + You should have received a copy of the GNU Lesser General Public
37 + License along with the GNU C Library; if not, see
38 + <http://www.gnu.org/licenses/>. */
45 +#include <netinet/in.h>
46 +#include <netpacket/packet.h>
47 +#include <sys/param.h>
48 +#include <sys/socket.h>
57 + /* Sort the array according to importance of the protocols. Add
58 + more protocols when they become available. */
59 + { SOL_IP, AF_INET, sizeof (struct sockaddr_in) },
60 + { SOL_IPV6, AF_INET6, sizeof (struct sockaddr_in6) },
61 + { SOL_PACKET, AF_PACKET, sizeof (struct sockaddr_ll) }
63 +#define NSOL_MAP (sizeof (sol_map) / sizeof (sol_map[0]))
66 +/* Try to determine the socket level value. Ideally both side and
67 + family are set. But sometimes only the size is correct and the
68 + family value might be bogus. Loop over the array entries and look
69 + for a perfect match or the first match based on size. */
71 +__get_sol (int af, socklen_t len)
73 + int first_size_sol = -1;
75 + for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
77 + /* Just a test so that we make sure the special value used to
78 + signal the "we have so far no socket level value" is OK. */
79 + assert (sol_map[cnt].sol != -1);
81 + if (len == sol_map[cnt].size)
83 + /* The size matches, which is a requirement. If the family
84 + matches, too, we have a winner. Otherwise we remember the
85 + socket level value for this protocol if it is the first
87 + if (af == sol_map[cnt].af)
89 + return sol_map[cnt].sol;
91 + if (first_size_sol == -1)
92 + first_size_sol = sol_map[cnt].sol;
96 + return first_size_sol;
101 +getsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
102 + socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc,
103 + struct sockaddr_storage *slist)
105 + /* We have to create an struct ip_msfilter object which we can pass
107 + socklen_t needed = GROUP_FILTER_SIZE (*numsrc);
108 + struct group_filter *gf;
109 + gf = (struct group_filter *) malloc (needed);
113 + gf->gf_interface = interface;
114 + memcpy (&gf->gf_group, group, grouplen);
115 + gf->gf_numsrc = *numsrc;
117 + /* We need to provide the appropriate socket level value. */
119 + int sol = __get_sol (group->sa_family, grouplen);
127 + result = getsockopt (s, sol, MCAST_MSFILTER, gf, &needed);
129 + /* If successful, copy the results to the places the caller wants
133 + *fmode = gf->gf_fmode;
134 + memcpy (slist, gf->gf_slist,
135 + MIN (*numsrc, gf->gf_numsrc)
136 + * sizeof (struct sockaddr_storage));
137 + *numsrc = gf->gf_numsrc;
141 + int save_errno = errno;
143 + errno = save_errno;
150 +setsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
151 + socklen_t grouplen, uint32_t fmode, uint32_t numsrc,
152 + const struct sockaddr_storage *slist)
154 + /* We have to create an struct ip_msfilter object which we can pass
156 + size_t needed = GROUP_FILTER_SIZE (numsrc);
158 + struct group_filter *gf;
159 + gf = (struct group_filter *) malloc (needed);
163 + gf->gf_interface = interface;
164 + memcpy (&gf->gf_group, group, grouplen);
165 + gf->gf_fmode = fmode;
166 + gf->gf_numsrc = numsrc;
167 + memcpy (gf->gf_slist, slist, numsrc * sizeof (struct sockaddr_storage));
169 + /* We need to provide the appropriate socket level value. */
171 + int sol = __get_sol (group->sa_family, grouplen);
178 + result = setsockopt (s, sol, MCAST_MSFILTER, gf, needed);
180 + int save_errno = errno;
182 + errno = save_errno;