MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / anetResolve

Function anetResolve

src/anet.c:223–248  ·  view source on GitHub ↗

Resolve the hostname "host" and set the string representation of the * IP address into the buffer pointed by "ipbuf". * * If flags is set to ANET_IP_ONLY the function only resolves hostnames * that are actually already IPv4 or IPv6 addresses. This turns the function * into a validating / normalizing function. */

Source from the content-addressed store, hash-verified

221 * that are actually already IPv4 or IPv6 addresses. This turns the function
222 * into a validating / normalizing function. */
223int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len,
224 int flags)
225{
226 struct addrinfo hints, *info;
227 int rv;
228
229 memset(&hints,0,sizeof(hints));
230 if (flags & ANET_IP_ONLY) hints.ai_flags = AI_NUMERICHOST;
231 hints.ai_family = AF_UNSPEC;
232 hints.ai_socktype = SOCK_STREAM; /* specify socktype to avoid dups */
233
234 if ((rv = getaddrinfo(host, NULL, &hints, &info)) != 0) {
235 anetSetError(err, "%s", gai_strerror(rv));
236 return ANET_ERR;
237 }
238 if (info->ai_family == AF_INET) {
239 struct sockaddr_in *sa = (struct sockaddr_in *)info->ai_addr;
240 inet_ntop(AF_INET, &(sa->sin_addr), ipbuf, ipbuf_len);
241 } else {
242 struct sockaddr_in6 *sa = (struct sockaddr_in6 *)info->ai_addr;
243 inet_ntop(AF_INET6, &(sa->sin6_addr), ipbuf, ipbuf_len);
244 }
245
246 freeaddrinfo(info);
247 return ANET_OK;
248}
249
250static int anetSetReuseAddr(char *err, int fd) {
251 int yes = 1;

Callers 3

createSentinelAddrFunction · 0.85
sentinelCommandFunction · 0.85

Calls 1

anetSetErrorFunction · 0.85

Tested by

no test coverage detected