ObjFW  Diff

Differences From Artifact [444cb9ff29]:

To Artifact [de3749afa6]:


250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	}
# endif
#endif

	return ret;
}

void
of_address_to_string_and_port(struct sockaddr *address, socklen_t addressLength,
    OFString *__autoreleasing *host, uint16_t *port)
{
#ifdef HAVE_GETADDRINFO
	char hostCString[NI_MAXHOST];
	char portCString[NI_MAXSERV];

# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		int error;

		/* FIXME: Add NI_DGRAM for UDP? */
		if ((error = getnameinfo(address, addressLength, hostCString,
		    NI_MAXHOST, portCString, NI_MAXSERV,
		    NI_NUMERICHOST | NI_NUMERICSERV)) != 0)
			@throw [OFAddressTranslationFailedException
			    exceptionWithError: error];

		if (host != NULL)
			*host = [OFString stringWithUTF8String: hostCString];

		if (port != NULL) {
			char *endptr;
			long tmp;

			if ((tmp = strtol(portCString, &endptr, 10)) >
			    UINT16_MAX)
				@throw [OFOutOfRangeException exception];

			if (endptr != NULL && *endptr != '\0')
				@throw [OFAddressTranslationFailedException
				    exception];

			*port = (uint16_t)tmp;
		}
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#else
	char *hostCString;

	if (address->sa_family != AF_INET)
		@throw [OFInvalidArgumentException exception];

# if OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		if ((hostCString = inet_ntoa(
		    ((struct sockaddr_in *)(void *)address)->sin_addr)) == NULL)
			@throw [OFAddressTranslationFailedException
			    exceptionWithError: h_errno];

		if (host != NULL)
			*host = [OFString stringWithUTF8String: hostCString];

		if (port != NULL)
			*port = OF_BSWAP16_IF_LE(
			    ((struct sockaddr_in *)(void *)address)->sin_port);
# if OF_HAVE_THREADS
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#endif
}

void
of_resolver_free(of_resolver_result_t **results)
{
#ifdef HAVE_GETADDRINFO
	freeaddrinfo(results[0]->private_);
#else
	free(results[0]->address);







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







250
251
252
253
254
255
256














































































257
258
259
260
261
262
263
	}
# endif
#endif

	return ret;
}















































































void
of_resolver_free(of_resolver_result_t **results)
{
#ifdef HAVE_GETADDRINFO
	freeaddrinfo(results[0]->private_);
#else
	free(results[0]->address);