ObjFW  Check-in [d4ea9e536c]

Overview
Comment:+[OFSystemInfo networkInterface]: Fix some BSDs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d4ea9e536c22135ce79743218d2742bfe5f7ef97c7b94c40ee5356e9779cdc8d
User & Date: js on 2023-06-08 21:03:12
Other Links: manifest | tags
Context
2023-06-08
21:17
+[OFSystemInfo networkInterfaces]: Add IPX check-in: ce6b0f02cf user: js tags: trunk
21:03
+[OFSystemInfo networkInterface]: Fix some BSDs check-in: d4ea9e536c user: js tags: trunk
2023-06-06
23:42
+[OFSystemInfo networkInterfaces]: Windows support check-in: ca4632c14c user: js tags: trunk
Changes

Modified src/OFSystemInfo.m from [fabe0e6c7e] to [7301636c5f].

923
924
925
926
927
928
929


930
931
932
933
934
935
936
937

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964







965
966
967
968
969
970
971
	ifrs = malloc(128 * sizeof(struct ifreq));
	if (ifrs == NULL) {
		closesocket(sock);
		return false;
	}

	@try {


		memset(&ifc, 0, sizeof(ifc));
		ifc.ifc_buf = (void *)ifrs;
		ifc.ifc_len = 128 * sizeof(struct ifreq);
		if (ioctl(sock, SIOCGIFCONF, &ifc) < 0)
			return false;

		for (size_t i = 0; i < ifc.ifc_len / sizeof(struct ifreq);
		    i++) {

			OFString *name;
			OFMutableData *addresses;
			OFSocketAddress address;

			if (ifrs[i].ifr_addr.sa_family != family)
				continue;

			name = [OFString stringWithCString: ifrs[i].ifr_name
						  encoding: encoding];
			if ((interface = [ret objectForKey: name]) == nil) {
				interface = [OFMutableDictionary dictionary];
				[ret setObject: interface forKey: name];
			}

			addresses = [interface objectForKey: key];
			if (addresses == nil) {
				addresses = [OFMutableData
				    dataWithItemSize: sizeof(OFSocketAddress)];
				[interface setObject: addresses forKey: key];
			}

			memset(&address, 0, sizeof(address));
			address.family = addressFamily;
			memcpy(&address.sockaddr.in, &ifrs[i].ifr_addr,
			    sockaddrSize);

			[addresses addItem: &address];







		}
	} @finally {
		free(ifrs);
		closesocket(sock);
	}

	enumerator = [ret objectEnumerator];







>
>






|
|
>




|
|

|















|



>
>
>
>
>
>
>







923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
	ifrs = malloc(128 * sizeof(struct ifreq));
	if (ifrs == NULL) {
		closesocket(sock);
		return false;
	}

	@try {
		char *buffer;

		memset(&ifc, 0, sizeof(ifc));
		ifc.ifc_buf = (void *)ifrs;
		ifc.ifc_len = 128 * sizeof(struct ifreq);
		if (ioctl(sock, SIOCGIFCONF, &ifc) < 0)
			return false;

		buffer = ifc.ifc_buf;
		while (buffer < ifc.ifc_buf + ifc.ifc_len) {
			struct ifreq *current = (struct ifreq *)(void *)buffer;
			OFString *name;
			OFMutableData *addresses;
			OFSocketAddress address;

			if (current->ifr_addr.sa_family != family)
				goto next;

			name = [OFString stringWithCString: current->ifr_name
						  encoding: encoding];
			if ((interface = [ret objectForKey: name]) == nil) {
				interface = [OFMutableDictionary dictionary];
				[ret setObject: interface forKey: name];
			}

			addresses = [interface objectForKey: key];
			if (addresses == nil) {
				addresses = [OFMutableData
				    dataWithItemSize: sizeof(OFSocketAddress)];
				[interface setObject: addresses forKey: key];
			}

			memset(&address, 0, sizeof(address));
			address.family = addressFamily;
			memcpy(&address.sockaddr.in, &current->ifr_addr,
			    sockaddrSize);

			[addresses addItem: &address];

next:
#  ifdef _SIZEOF_ADDR_IFREQ
			buffer += _SIZEOF_ADDR_IFREQ(*current);
#  else
			buffer += sizeof(struct ifreq);
#  endif
		}
	} @finally {
		free(ifrs);
		closesocket(sock);
	}

	enumerator = [ret objectEnumerator];