ObjFW  Diff

Differences From Artifact [03983c4b06]:

To Artifact [5111ebd364]:


205
206
207
208
209
210
211
212

213
214

215
216
217

218
219
220
221

222
223
224



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250

251

252
253
254

255

256
257
258
259
260
261
262
205
206
207
208
209
210
211

212
213

214
215
216

217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239


240


241
242
243
244
245
246
247
248
249
250
251

252

253
254
255

256
257
258
259
260
261
262
263







-
+

-
+


-
+



-
+



+
+
+












-
-

-
-
+









+
-
+
-


+
-
+







		@throw [OFUnlockFailedException exception];
# endif
#endif

	return ret;
}

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

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

	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;
	}

	return [OFString stringWithUTF8String: host];
#else
	OFString *ret;
	char *host;
	char *hostCString;

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

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

	if ((hostCString = inet_ntoa(
	host = inet_ntoa(((struct sockaddr_in*)(void*)address)->sin_addr);
	    ((struct sockaddr_in*)(void*)address)->sin_addr)) == NULL)
	if (host == NULL)
		@throw [OFAddressTranslationFailedException exception];

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

	if (port != NULL)
		*port = OF_BSWAP16_IF_LE(
		    ((struct sockaddr_in*)(void*)address)->sin_port);

# if OF_HAVE_THREADS
	if (!of_mutex_unlock(&mutex))