ObjFW  Check-in [2fc4580a5f]

Overview
Comment:utils/ofatalkcfg: Make the code more portable

This makes it work on macOS 10.5.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2fc4580a5f7dccc5a9a7326cb3c1c02ef3366f5661681bd0aa8218ba9fd26402
User & Date: js on 2023-04-12 08:37:12
Other Links: manifest | tags
Context
2023-04-12
08:54
tests/OFMatrix4x4Tests.m: Fix a typo check-in: 5ee5247264 user: js tags: trunk
08:37
utils/ofatalkcfg: Make the code more portable check-in: 2fc4580a5f user: js tags: trunk
07:47
utils/ofatalkcfg: Add default phase and range check-in: a143f67237 user: js tags: trunk
Changes

Modified utils/ofatalkcfg/OFATalkCfg.m from [54a3258015] to [6fea0d2a72].

12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64


65


66
67

68

69
70
71
72
73
74
75
76
77
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>

#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#include "unistd.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFOptionsParser.h"
#import "OFSocket.h"
#import "OFStdIOStream.h"

#import "OFInvalidFormatException.h"








@interface OFATalkCfg: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(OFATalkCfg)

static void
configureInterface(OFString *interface, uint16_t network, uint8_t node,
    uint8_t phase, uint16_t rangeStart, uint16_t rangeEnd)
{
	struct ifreq request = { 0 };
	struct sockaddr_at *sat;
#ifdef OF_LINUX
	struct atalk_netrange *nr;
#else
	struct netrange *nr;
#endif
	int sock;

	if (interface.UTF8StringLength > IFNAMSIZ) {
		[OFStdErr writeFormat: @"%@: Interface name too long!\n",
				       [OFApplication programName]];
		[OFApplication terminateWithStatus: 1];
	}


	strncpy(request.ifr_name, interface.UTF8String, IFNAMSIZ);
	sat = (struct sockaddr_at *)&request.ifr_addr;
	sat->sat_family = AF_APPLETALK;
	sat->sat_net = OFToBigEndian16(network);
	sat->sat_node = node;


	nr = (__typeof__(nr))(void *)sat->sat_zero;


	nr->nr_phase = phase;
	nr->nr_firstnet = OFToBigEndian16(rangeStart);

	nr->nr_lastnet = OFToBigEndian16(rangeEnd);


	if ((sock = socket(AF_APPLETALK, SOCK_DGRAM, 0)) < 0) {
		int errNo = OFSocketErrNo();

		[OFStdErr writeFormat: @"%@: Failed to create socket: %@\n",
				       [OFApplication programName],
				       OFStrError(errNo)];

#ifdef OF_LINUX







<
<
<
<
<
<
<









>
>
>
>
>
>
>










|

<
<
<
<
<








>





>
>
|
>
>
|
|
>
|
>

|







12
13
14
15
16
17
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
43
44
45
46





47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>







#include "unistd.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFOptionsParser.h"
#import "OFSocket.h"
#import "OFStdIOStream.h"

#import "OFInvalidFormatException.h"

#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif

@interface OFATalkCfg: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(OFATalkCfg)

static void
configureInterface(OFString *interface, uint16_t network, uint8_t node,
    uint8_t phase, uint16_t rangeStart, uint16_t rangeEnd)
{
	struct ifreq request;
	struct sockaddr_at *sat;





	int sock;

	if (interface.UTF8StringLength > IFNAMSIZ) {
		[OFStdErr writeFormat: @"%@: Interface name too long!\n",
				       [OFApplication programName]];
		[OFApplication terminateWithStatus: 1];
	}

	memset(&request, 0, sizeof(request));
	strncpy(request.ifr_name, interface.UTF8String, IFNAMSIZ);
	sat = (struct sockaddr_at *)&request.ifr_addr;
	sat->sat_family = AF_APPLETALK;
	sat->sat_net = OFToBigEndian16(network);
	sat->sat_node = node;
	/*
	 * The netrange is hidden in sat_zero and different OSes use different
	 * struct names for it, so the portable way is setting sat_zero
	 * directly.
	 */
	sat->sat_zero[0] = phase;
	sat->sat_zero[2] = rangeStart >> 8;
	sat->sat_zero[3] = rangeStart & 0xFF;
	sat->sat_zero[4] = rangeEnd >> 8;
	sat->sat_zero[5] = rangeEnd & 0xFF;

	if ((sock = socket(AF_APPLETALK, SOCK_RAW, 0)) < 0) {
		int errNo = OFSocketErrNo();

		[OFStdErr writeFormat: @"%@: Failed to create socket: %@\n",
				       [OFApplication programName],
				       OFStrError(errNo)];

#ifdef OF_LINUX