3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
29
struct hostent *gethostbyname_r(const char *name, struct hostent *result, char *buffer, int buflen, int *h_errnop);
30
struct hostent *gethostbyaddr_r(const char *name, size_t size, int type,
31
struct hostent *result, char *buffer, int buflen, int *h_errnop);
37
ink_gethostbyname_r(char *hostname, ink_gethostbyname_r_data * data)
39
#ifdef RENTRENT_GETHOSTBYNAME
40
struct hostent *r = gethostbyname(hostname);
45
#else //RENTRENT_GETHOSTBYNAME
46
#if GETHOSTBYNAME_R_GLIBC2
48
struct hostent *addrp = NULL;
49
int res = gethostbyname_r(hostname, &data->ent, data->buf,
50
INK_GETHOSTBYNAME_R_DATA_SIZE, &addrp,
52
struct hostent *r = NULL;
57
struct hostent *r = gethostbyname_r(hostname, &data->ent, data->buf,
58
INK_GETHOSTBYNAME_R_DATA_SIZE,
66
ink_gethostbyaddr_r(char *ip, int len, int type, ink_gethostbyaddr_r_data * data)
68
#if GETHOSTBYNAME_R_GLIBC2
69
struct hostent *r = NULL;
70
struct hostent *addrp = NULL;
71
int res = gethostbyaddr_r((char *) ip, len, type, &data->ent, data->buf,
72
INK_GETHOSTBYNAME_R_DATA_SIZE, &addrp,
77
#ifdef RENTRENT_GETHOSTBYADDR
78
struct hostent *r = gethostbyaddr((const void *) ip, len, type);
81
struct hostent *r = gethostbyaddr_r((char *) ip, len, type, &data->ent,
83
INK_GETHOSTBYNAME_R_DATA_SIZE,
91
host_to_ip(char *hostname)
95
he = gethostbyname(hostname);
99
return *(unsigned int *) he->h_addr;
103
ink_inet_addr(const char *s)
106
uint8_t *pc = (uint8_t *) s;
118
if (*++pc == 'x' || *pc == 'X')
123
// handle hex, octal, decimal
126
if (ParseRules::is_digit(*pc)) {
127
u[n] = u[n] * base + (*pc++ - '0');
130
if (base == 16 && ParseRules::is_hex(*pc)) {
131
u[n] = u[n] * 16 + ParseRules::ink_tolower(*pc++) - 'a' + 10;
144
if (*pc && !ParseRules::is_wslfcr(*pc))
145
return htonl((uint32_t) - 1);
151
if (u[0] > 0xff || u[1] > 0xffffff)
152
return htonl((uint32_t) - 1);
153
return htonl((u[0] << 24) | u[1]);
155
if (u[0] > 0xff || u[1] > 0xff || u[2] > 0xffff)
156
return htonl((uint32_t) - 1);
157
return htonl((u[0] << 24) | (u[1] << 16) | u[2]);
159
if (u[0] > 0xff || u[1] > 0xff || u[2] > 0xff || u[3] > 0xff)
160
return htonl((uint32_t) - 1);
161
return htonl((u[0] << 24) | (u[1] << 16) | (u[2] << 8) | u[3]);
163
return htonl((uint32_t) - 1);
166
const char *ink_inet_ntop(const struct sockaddr *addr, char *dst, size_t size)
168
void *address = NULL;
170
switch (addr->sa_family) {
172
address = &((struct sockaddr_in *)addr)->sin_addr;
175
address = &((struct sockaddr_in6 *)addr)->sin6_addr;
179
return inet_ntop(addr->sa_family, address, dst, size);
182
uint16_t ink_inet_port(const struct sockaddr *addr)
186
switch (addr->sa_family) {
188
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
191
port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port);