ObjFW  Diff

Differences From Artifact [d4a188ba53]:

To Artifact [17b33daff7]:


18
19
20
21
22
23
24


25
26
27

28
29
30
31

32
33
34
35
36
37
38
#include "config.h"

#ifdef OF_NINTENDO_3DS
# include <malloc.h>  /* For memalign() */
#endif

#include <errno.h>



#import "OFException.h"  /* For some E* -> WSAE* defines */
#import "OFInvalidArgumentException.h"

#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"

#import "socket.h"

#ifdef OF_HAVE_THREADS
# include "threading.h"
#endif

#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>







>
>



>




>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "config.h"

#ifdef OF_NINTENDO_3DS
# include <malloc.h>  /* For memalign() */
#endif

#include <errno.h>

#import "OFLocalization.h"

#import "OFException.h"  /* For some E* -> WSAE* defines */
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"

#import "socket.h"
#import "socket_helpers.h"
#ifdef OF_HAVE_THREADS
# include "threading.h"
#endif

#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>
326
327
328
329
330
331
332




























































#endif
	default:
		@throw [OFInvalidArgumentException exception];
	}

	return hash;
}



































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#endif
	default:
		@throw [OFInvalidArgumentException exception];
	}

	return hash;
}

static of_socket_address_t
parseIPv4(OFString *IPv4, uint16_t port)
{
	void *pool = objc_autoreleasePoolPush();
	of_socket_address_t ret;
	struct sockaddr_in *sin = (struct sockaddr_in *)&ret.address;

	memset(&ret, '\0', sizeof(ret));
	ret.length = sizeof(struct sockaddr_in);

	sin->sin_family = AF_INET;
	sin->sin_port = OF_BSWAP16_IF_LE(port);

	if (inet_pton(AF_INET, [IPv4 cStringWithEncoding:
	    [OFLocalization encoding]], &sin->sin_addr) != 1)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);

	return ret;
}

#ifdef HAVE_IPV6
static of_socket_address_t
parseIPv6(OFString *IPv6, uint16_t port)
{
	void *pool = objc_autoreleasePoolPush();
	of_socket_address_t ret;
	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ret.address;

	memset(&ret, '\0', sizeof(ret));
	ret.length = sizeof(struct sockaddr_in6);

	sin6->sin6_family = AF_INET6;
	sin6->sin6_port = OF_BSWAP16_IF_LE(port);

	if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding:
	    [OFLocalization encoding]], &sin6->sin_addr6) != 1)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);

	return ret;
}
#endif

of_socket_address_t
of_socket_address_parse_ip(OFString *IP, uint16_t port)
{
#ifdef HAVE_IPV6
	@try {
		return parseIPv6(IP, port);
	} @catch (OFInvalidFormatException *e) {
#endif
		return parseIPv4(IP, port);
#ifdef HAVE_IPV6
	}
#endif
}