003 File Manager
Current Path:
/usr/src/lib/libc/net
usr
/
src
/
lib
/
libc
/
net
/
📁
..
📄
Makefile.inc
(5.08 KB)
📄
Symbol.map
(2.8 KB)
📄
base64.c
(10.39 KB)
📄
byteorder.3
(2.74 KB)
📄
ether_addr.c
(5.68 KB)
📄
ethers.3
(5.85 KB)
📄
eui64.3
(6.37 KB)
📄
eui64.c
(8.3 KB)
📄
gai_strerror.3
(2.49 KB)
📄
gai_strerror.c
(3.98 KB)
📄
getaddrinfo.3
(12.12 KB)
📄
getaddrinfo.c
(70.2 KB)
📄
gethostbydns.c
(19.1 KB)
📄
gethostbyht.c
(9.04 KB)
📄
gethostbyname.3
(8.74 KB)
📄
gethostbynis.c
(6.94 KB)
📄
gethostnamadr.c
(17.01 KB)
📄
getifaddrs.3
(4.24 KB)
📄
getifaddrs.c
(8.57 KB)
📄
getifmaddrs.3
(3 KB)
📄
getifmaddrs.c
(4.79 KB)
📄
getipnodebyname.3
(10.04 KB)
📄
getnameinfo.3
(7.6 KB)
📄
getnameinfo.c
(13.68 KB)
📄
getnetbydns.c
(12 KB)
📄
getnetbyht.c
(7.18 KB)
📄
getnetbynis.c
(6.09 KB)
📄
getnetent.3
(4.36 KB)
📄
getnetnamadr.c
(10.46 KB)
📄
getproto.c
(3.87 KB)
📄
getprotoent.3
(3.78 KB)
📄
getprotoent.c
(12.22 KB)
📄
getprotoname.c
(4.25 KB)
📄
getservent.3
(4.13 KB)
📄
getservent.c
(29.69 KB)
📄
hesiod.3
(4.19 KB)
📄
hesiod.c
(12.17 KB)
📄
hosts
(1.01 KB)
📄
hosts.equiv
(53 B)
📄
if_indextoname.3
(3.94 KB)
📄
if_indextoname.c
(2.94 KB)
📄
if_nameindex.c
(4.21 KB)
📄
if_nametoindex.c
(2.84 KB)
📄
inet.3
(7.76 KB)
📄
inet6_opt_init.3
(9.07 KB)
📄
inet6_option_space.3
(2.18 KB)
📄
inet6_rth_space.3
(6.86 KB)
📄
inet6_rthdr_space.3
(2.22 KB)
📄
inet_net.3
(5.01 KB)
📄
ip6opt.c
(15.36 KB)
📄
linkaddr.3
(3.94 KB)
📄
linkaddr.c
(4.44 KB)
📄
map_v4v6.c
(3.93 KB)
📄
name6.c
(28.18 KB)
📄
netdb_private.h
(5.2 KB)
📄
networks
(310 B)
📄
nscache.c
(10.91 KB)
📄
nscachedcli.c
(14.18 KB)
📄
nsdispatch.3
(6.25 KB)
📄
nsdispatch.c
(20.3 KB)
📄
nslexer.l
(3.01 KB)
📄
nsparser.y
(3.91 KB)
📄
nss_backends.h
(2.04 KB)
📄
nss_compat.c
(7.93 KB)
📄
nsswitch.conf
(272 B)
📄
ntoh.c
(1.75 KB)
📄
protocols
(6.24 KB)
📄
rcmd.3
(8.14 KB)
📄
rcmd.c
(18.57 KB)
📄
rcmdsh.3
(3.23 KB)
📄
rcmdsh.c
(4.95 KB)
📄
recv.c
(2.22 KB)
📄
res_config.h
(299 B)
📄
resolver.3
(11.43 KB)
📄
rthdr.c
(9.7 KB)
📄
sctp_bindx.3
(3.47 KB)
📄
sctp_connectx.3
(3.44 KB)
📄
sctp_freepaddrs.3
(2.26 KB)
📄
sctp_getaddrlen.3
(2.82 KB)
📄
sctp_getassocid.3
(2.44 KB)
📄
sctp_getpaddrs.3
(3.11 KB)
📄
sctp_opt_info.3
(3.55 KB)
📄
sctp_recvmsg.3
(8.43 KB)
📄
sctp_send.3
(11.12 KB)
📄
sctp_sendmsg.3
(10.45 KB)
📄
sctp_sys_calls.c
(30.35 KB)
📄
send.c
(2.23 KB)
📄
sockatmark.3
(3.26 KB)
📄
sockatmark.c
(1.59 KB)
📄
sourcefilter.3
(6.38 KB)
📄
sourcefilter.c
(9.71 KB)
📄
vars.c
(2.07 KB)
Editing: sourcefilter.c
/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2007-2009 Bruce Simpson. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include "namespace.h" #include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if_dl.h> #include <net/if.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/ip_var.h> #include <assert.h> #include <errno.h> #include <ifaddrs.h> #include <stdlib.h> #include <string.h> #include "un-namespace.h" /* * Advanced (Full-state) multicast group membership APIs [RFC3678] * Currently this module assumes IPv4 support (INET) in the base system. */ #ifndef INET #define INET #endif union sockunion { struct sockaddr_storage ss; struct sockaddr sa; struct sockaddr_dl sdl; #ifdef INET struct sockaddr_in sin; #endif #ifdef INET6 struct sockaddr_in6 sin6; #endif }; typedef union sockunion sockunion_t; #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif /* * Internal: Map an IPv4 unicast address to an interface index. * This is quite inefficient so it is recommended applications use * the newer, more portable, protocol independent API. */ static uint32_t __inaddr_to_index(in_addr_t ifaddr) { struct ifaddrs *ifa; struct ifaddrs *ifaddrs; char *ifname; int ifindex; sockunion_t *psu; if (getifaddrs(&ifaddrs) < 0) return (0); ifindex = 0; ifname = NULL; /* * Pass #1: Find the ifaddr entry corresponding to the * supplied IPv4 address. We should really use the ifindex * consistently for matches, however it is not available to * us on this pass. */ for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { psu = (sockunion_t *)ifa->ifa_addr; if (psu && psu->ss.ss_family == AF_INET && psu->sin.sin_addr.s_addr == ifaddr) { ifname = ifa->ifa_name; break; } } if (ifname == NULL) goto out; /* * Pass #2: Find the index of the interface matching the name * we obtained from looking up the IPv4 ifaddr in pass #1. * There must be a better way of doing this. */ for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { psu = (sockunion_t *)ifa->ifa_addr; if (psu && psu->ss.ss_family == AF_LINK && strcmp(ifa->ifa_name, ifname) == 0) { ifindex = LLINDEX(&psu->sdl); break; } } assert(ifindex != 0); out: freeifaddrs(ifaddrs); return (ifindex); } /* * Set IPv4 source filter list in use on socket. * * Stubbed to setsourcefilter(). Performs conversion of structures which * may be inefficient; applications are encouraged to use the * protocol-independent API. */ int setipv4sourcefilter(int s, struct in_addr interface, struct in_addr group, uint32_t fmode, uint32_t numsrc, struct in_addr *slist) { #ifdef INET sockunion_t tmpgroup; struct in_addr *pina; sockunion_t *psu, *tmpslist; int err; size_t i; uint32_t ifindex; assert(s != -1); tmpslist = NULL; if (!IN_MULTICAST(ntohl(group.s_addr)) || (fmode != MCAST_INCLUDE && fmode != MCAST_EXCLUDE)) { errno = EINVAL; return (-1); } ifindex = __inaddr_to_index(interface.s_addr); if (ifindex == 0) { errno = EADDRNOTAVAIL; return (-1); } memset(&tmpgroup, 0, sizeof(sockunion_t)); tmpgroup.sin.sin_family = AF_INET; tmpgroup.sin.sin_len = sizeof(struct sockaddr_in); tmpgroup.sin.sin_addr = group; if (numsrc != 0 || slist != NULL) { tmpslist = calloc(numsrc, sizeof(sockunion_t)); if (tmpslist == NULL) { errno = ENOMEM; return (-1); } pina = slist; psu = tmpslist; for (i = 0; i < numsrc; i++, pina++, psu++) { psu->sin.sin_family = AF_INET; psu->sin.sin_len = sizeof(struct sockaddr_in); psu->sin.sin_addr = *pina; } } err = setsourcefilter(s, ifindex, (struct sockaddr *)&tmpgroup, sizeof(struct sockaddr_in), fmode, numsrc, (struct sockaddr_storage *)tmpslist); if (tmpslist != NULL) free(tmpslist); return (err); #else /* !INET */ return (EAFNOSUPPORT); #endif /* INET */ } /* * Get IPv4 source filter list in use on socket. * * Stubbed to getsourcefilter(). Performs conversion of structures which * may be inefficient; applications are encouraged to use the * protocol-independent API. * An slist of NULL may be used for guessing the required buffer size. */ int getipv4sourcefilter(int s, struct in_addr interface, struct in_addr group, uint32_t *fmode, uint32_t *numsrc, struct in_addr *slist) { sockunion_t *psu, *tmpslist; sockunion_t tmpgroup; struct in_addr *pina; int err; size_t i; uint32_t ifindex, onumsrc; assert(s != -1); assert(fmode != NULL); assert(numsrc != NULL); onumsrc = *numsrc; *numsrc = 0; tmpslist = NULL; if (!IN_MULTICAST(ntohl(group.s_addr)) || (onumsrc != 0 && slist == NULL)) { errno = EINVAL; return (-1); } ifindex = __inaddr_to_index(interface.s_addr); if (ifindex == 0) { errno = EADDRNOTAVAIL; return (-1); } memset(&tmpgroup, 0, sizeof(sockunion_t)); tmpgroup.sin.sin_family = AF_INET; tmpgroup.sin.sin_len = sizeof(struct sockaddr_in); tmpgroup.sin.sin_addr = group; if (onumsrc != 0 || slist != NULL) { tmpslist = calloc(onumsrc, sizeof(sockunion_t)); if (tmpslist == NULL) { errno = ENOMEM; return (-1); } } err = getsourcefilter(s, ifindex, (struct sockaddr *)&tmpgroup, sizeof(struct sockaddr_in), fmode, numsrc, (struct sockaddr_storage *)tmpslist); if (tmpslist != NULL && *numsrc != 0) { pina = slist; psu = tmpslist; for (i = 0; i < MIN(onumsrc, *numsrc); i++, psu++) { if (psu->ss.ss_family != AF_INET) continue; *pina++ = psu->sin.sin_addr; } free(tmpslist); } return (err); } /* * Set protocol-independent source filter list in use on socket. */ int setsourcefilter(int s, uint32_t interface, struct sockaddr *group, socklen_t grouplen, uint32_t fmode, uint32_t numsrc, struct sockaddr_storage *slist) { struct __msfilterreq msfr; sockunion_t *psu; int level, optname; if (fmode != MCAST_INCLUDE && fmode != MCAST_EXCLUDE) { errno = EINVAL; return (-1); } psu = (sockunion_t *)group; switch (psu->ss.ss_family) { #ifdef INET case AF_INET: if ((grouplen != sizeof(struct sockaddr_in) || !IN_MULTICAST(ntohl(psu->sin.sin_addr.s_addr)))) { errno = EINVAL; return (-1); } level = IPPROTO_IP; optname = IP_MSFILTER; break; #endif #ifdef INET6 case AF_INET6: if (grouplen != sizeof(struct sockaddr_in6) || !IN6_IS_ADDR_MULTICAST(&psu->sin6.sin6_addr)) { errno = EINVAL; return (-1); } level = IPPROTO_IPV6; optname = IPV6_MSFILTER; break; #endif default: errno = EAFNOSUPPORT; return (-1); } memset(&msfr, 0, sizeof(msfr)); msfr.msfr_ifindex = interface; msfr.msfr_fmode = fmode; msfr.msfr_nsrcs = numsrc; memcpy(&msfr.msfr_group, &psu->ss, psu->ss.ss_len); msfr.msfr_srcs = slist; /* pointer */ return (_setsockopt(s, level, optname, &msfr, sizeof(msfr))); } /* * Get protocol-independent source filter list in use on socket. * An slist of NULL may be used for guessing the required buffer size. */ int getsourcefilter(int s, uint32_t interface, struct sockaddr *group, socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc, struct sockaddr_storage *slist) { struct __msfilterreq msfr; sockunion_t *psu; socklen_t optlen; int err, level, nsrcs, optname; if (interface == 0 || group == NULL || numsrc == NULL || fmode == NULL) { errno = EINVAL; return (-1); } nsrcs = *numsrc; *numsrc = 0; *fmode = 0; psu = (sockunion_t *)group; switch (psu->ss.ss_family) { #ifdef INET case AF_INET: if ((grouplen != sizeof(struct sockaddr_in) || !IN_MULTICAST(ntohl(psu->sin.sin_addr.s_addr)))) { errno = EINVAL; return (-1); } level = IPPROTO_IP; optname = IP_MSFILTER; break; #endif #ifdef INET6 case AF_INET6: if (grouplen != sizeof(struct sockaddr_in6) || !IN6_IS_ADDR_MULTICAST(&psu->sin6.sin6_addr)) { errno = EINVAL; return (-1); } level = IPPROTO_IPV6; optname = IPV6_MSFILTER; break; #endif default: errno = EAFNOSUPPORT; return (-1); break; } optlen = sizeof(struct __msfilterreq); memset(&msfr, 0, optlen); msfr.msfr_ifindex = interface; msfr.msfr_fmode = 0; msfr.msfr_nsrcs = nsrcs; memcpy(&msfr.msfr_group, &psu->ss, psu->ss.ss_len); /* * msfr_srcs is a pointer to a vector of sockaddr_storage. It * may be NULL. The kernel will always return the total number * of filter entries for the group in msfr.msfr_nsrcs. */ msfr.msfr_srcs = slist; err = _getsockopt(s, level, optname, &msfr, &optlen); if (err == 0) { *numsrc = msfr.msfr_nsrcs; *fmode = msfr.msfr_fmode; } return (err); }
Upload File
Create Folder