Eskimo asks:
Can you clarify this statement? 127.0.0.1 is the IPv4 localhost address. How are you getting that back from getifaddrs? And what are you doing with that address? A call to getifaddrs(&p) on macOS 10.15.7 is returning exactly 2 IPV4 addresses,
where (p->ifaaddr->safamily == AFINET)
Those 2 IPV4 addresses are:> 0.0.0.0
> 127.0.0.1
If I try a UDP broadcast to those 2 addresses, one at a time:
mysocket = socket(PFINET, SOCKDGRAM, 0);
setsockopt(mysocket, SOLSOCKET, SOBROADCAST,
(char *)&i, sizeof(i));
if ((p->ifaaddr) && p->ifaaddr->safamily == AFINET) {
strncpy(ipstr, inetntoa(bcastAddr.sinaddr), ADRSIZE);
bcastAddr.sinfamily = AFINET;
bcastAddr.sinport = htons(1024);
bcastAddr.sinaddr
= ((struct sockaddrin *)(p->ifabroadaddr))->sinaddr;
sendto(mysocket, (char *)data, 63, 0,
(const struct sockaddr *)&bcastAddr,
sizeof(bcastAddr));
The UDP broadcast to 127.0.0.1 is the one I see on my local network (UDP sniffer on a Raspberry Pi).
There is a device on the local network that responds to that UDP broadcast by replying with a UDP packet.
This code looks for the response after the above UDP broadcast:
b = recvfrom(mysocket, (char *)data, 1500, 0,
(struct sockaddr *)&recvAddr, &addrLen);
This code compiled using older versions (3 to 6 months ago) of Xcode receives a UDP response from that broadcast.
This code when compiled and run on older versions (maybe 6 months ago) of Catalina or Mohave receives a UDP response from that broadcast.
This code runs an a Raspberry Pi 4 running Buster, and receives a UDP response from that broadcast.
e.g. recvfrom() returns a positive number, and a valid recvAddr IP address for the responder.
The same code compiled with Xcode 12.0.1 and run on the current version of macOS 10.15.7 never receives any UDP data on that socket and port (1024).
The above is all clang compiled command-line C code on macOS.
But an identical new failure occurs inside an iOS Objective C app built for the current iOS with the latest Xcode SDK releases.
The UDP code used to work (receive a response) 6 months ago, both on the macOS Terminal command-line and inside an iOS app.
What changed? Is the UDP response firewalled? Or am I missing some new Network permission requirement?
Is the change in macOS and iOS (at the same time), or inside the Xcode SDK being used (stdlib, etc.)?