25 #ifdef HAVE_NETINET_IN_H 26 # include <netinet/in.h> 28 #ifdef HAVE_ARPA_INET_H 29 # include <arpa/inet.h> 34 #ifdef HAVE_SYS_IOCTL_H 35 # include <sys/ioctl.h> 40 #ifdef HAVE_SYS_SOCKIO_H 41 # include <sys/sockio.h> 69 if(sa->sa_family == AF_INET6) {
70 const struct sockaddr_in6 * sa6 = (
const struct sockaddr_in6 *)(
void *) sa;
71 const unsigned char *b = sa6->sin6_addr.s6_addr;
72 unsigned short w = (
unsigned short) ((b[0] << 8) | b[1]);
74 if((b[0] & 0xFE) == 0xFC)
82 w = b[1] | b[2] | b[3] | b[4] | b[5] | b[6] | b[7] | b[8] | b[9] |
83 b[10] | b[11] | b[12] | b[13] | b[14];
84 if(w || b[15] != 0x01)
97 #if defined(HAVE_GETIFADDRS) 103 struct ifaddrs *iface, *
head;
105 if(getifaddrs(&head) >= 0) {
106 for(iface = head; iface != NULL; iface = iface->ifa_next) {
118 unsigned int remote_scope_id,
const char *interf,
119 char *
buf,
int buf_size)
121 struct ifaddrs *iface, *
head;
128 #if !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) || \ 129 !defined(ENABLE_IPV6) 130 (void) remote_scope_id;
133 if(getifaddrs(&head) >= 0) {
134 for(iface = head; iface != NULL; iface = iface->ifa_next) {
135 if(iface->ifa_addr != NULL) {
136 if(iface->ifa_addr->sa_family == af) {
144 unsigned int scopeid = 0;
147 if(ifscope != remote_scope) {
157 &((
struct sockaddr_in6 *)(
void *)iface->ifa_addr)->sin6_addr;
158 #ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 160 scopeid = ((
struct sockaddr_in6 *)(
void *)iface->ifa_addr)
164 if(remote_scope_id && scopeid != remote_scope_id) {
172 snprintf(scope,
sizeof(scope),
"%%%u", scopeid);
177 &((
struct sockaddr_in *)(
void *)iface->ifa_addr)->sin_addr;
197 #elif defined(HAVE_IOCTL_SIOCGIFADDR) 204 return (
Curl_if2ip(AF_INET, 0 , 0, interf, buf,
sizeof(buf)) ==
209 unsigned int remote_scope_id,
const char *interf,
210 char *
buf,
int buf_size)
214 struct sockaddr_in *
s;
219 (void)remote_scope_id;
221 if(!interf || (af != AF_INET))
224 len = strlen(interf);
225 if(len >=
sizeof(req.ifr_name))
228 dummy = socket(AF_INET, SOCK_STREAM, 0);
232 memset(&req, 0,
sizeof(req));
233 memcpy(req.ifr_name, interf, len + 1);
234 req.ifr_addr.sa_family = AF_INET;
236 if(ioctl(dummy, SIOCGIFADDR, &req) < 0) {
244 s = (
struct sockaddr_in *)(
void *)&req.ifr_addr;
245 memcpy(&in, &s->sin_addr,
sizeof(in));
262 unsigned int remote_scope_id,
const char *interf,
263 char *
buf,
int buf_size)
267 (void) remote_scope_id;
bool Curl_if_is_interface_name(const char *interf)
unsigned int Curl_ipv6_scope(const struct sockaddr *sa)
#define IPV6_SCOPE_NODELOCAL
#define IPV6_SCOPE_UNIQUELOCAL
#define IPV6_SCOPE_SITELOCAL
#define strcasecompare(a, b)
UNITTEST_START int result
char * Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
memcpy(filename, filename1, strlen(filename1))
#define IPV6_SCOPE_GLOBAL
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope, unsigned int remote_scope_id, const char *interf, char *buf, int buf_size)
TFSIMD_FORCE_INLINE const tfScalar & w() const
#define IPV6_SCOPE_LINKLOCAL
struct curl_llist_element * head
case 1: list has >1 element, removing head : 1: list size will be decremented by one 2: head will be ...