MCPcopy Create free account
hub / github.com/RsyncProject/rsync / getaddr_info_name

Function getaddr_info_name

lib/getaddrinfo.c:209–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207 */
208
209static int getaddr_info_name(const char *node,
210 const char *service,
211 const struct addrinfo *hints,
212 struct addrinfo **res)
213{
214 struct addrinfo *listp = NULL, *prevp = NULL;
215 char **pptr = NULL;
216 int err;
217 struct hostent *hp = NULL;
218 unsigned short port = 0;
219
220 if (service) {
221 port = (unsigned short)atoi(service);
222 }
223
224 hp = gethostbyname(node);
225 err = check_hostent_err(hp);
226 if (err) {
227 return err;
228 }
229
230 for(pptr = hp->h_addr_list; *pptr; pptr++) {
231 struct in_addr ip = *(struct in_addr *)*pptr;
232 struct addrinfo *ai = alloc_entry(hints, ip, port);
233
234 if (!ai) {
235 freeaddrinfo(listp);
236 return EAI_MEMORY;
237 }
238
239 if (!listp) {
240 listp = ai;
241 prevp = ai;
242 ai->ai_canonname = SMB_STRDUP(hp->h_name);
243 if (!ai->ai_canonname) {
244 freeaddrinfo(listp);
245 return EAI_MEMORY;
246 }
247 } else {
248 prevp->ai_next = ai;
249 prevp = ai;
250 }
251 }
252 *res = listp;
253 return 0;
254}
255
256/*
257 * get address info for ipv4 sockets.

Callers 1

getaddrinfoFunction · 0.85

Calls 3

check_hostent_errFunction · 0.85
alloc_entryFunction · 0.85
freeaddrinfoFunction · 0.85

Tested by

no test coverage detected