It seems that the whole thing is confusing. To organize the story again. .. ..
My app sends data with a UDP limited broadcast address.
I will put the source code with your suggestion below.
Code Block #import <Foundation/Foundation.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <sys/types.h> |
#include <sys/time.h> |
//Send Data UDP |
(int) MSDPsendRequestPrnE { |
|
int fdsend; |
struct sockaddrin addrsend; |
|
int yes = 1; |
|
unsigned int wifiInterface; |
|
wifiInterface = if_nametoindex("en0"); |
|
//socket |
if((fdsend = socket(AFINET, SOCKDGRAM, 0)) < 0) { |
// NSLog(@"%@", @"sendRequestE:socketerror"); |
perror("socket"); |
return -1; |
} |
|
memset(&addrsend, 0, sizeof(addrsend)); |
addrsend.sinfamily = AFINET; |
addrsend.sinport = htons(kPrinterSearchTaskREQPORT ); //kPrinterSearchTaskREQPORT is Define Number 49111 |
addrsend.sinaddr.saddr = inetaddr("255.255.255.255"); |
//setsockopt |
if (setsockopt(fd_send, SOL_SOCKET, SO_BROADCAST, (char *)&yes, sizeof(yes))){ |
NSLog(@"%@", @"sendRequest_E:socket_opt_error0"); |
perror("setsocketpt"); |
} |
|
if ( setsockopt(fd_send, IPPROTO_IP, IP_BOUND_IF, (char *)&wifiInterface, sizeof(wifiInterface))){ |
NSLog(@"%@", @"sendRequest_E:socket_opt_error1"); |
perror("setsocketpt"); |
} |
//sendto |
if(sendto(fdsend, "DAT rE", 6, 0, |
(struct sockaddr *)&addrsend, sizeof(addrsend)) < 0) { |
perror("sendto");//<----This is Error occurs!!! |
} |
// NSLog(@"%@", @"sendRequestE:socketclose"); |
close(fdsend); |
|
|
return 0; |
} |
Xcode Log:
sendto: No route to host
sendto: No route to host
sendto: No route to host
sendto: No route to host
In iOS14, to support this process
I saw the URL of How to use multicast networking in your app.
Add multicast to ProvisionProfile and
Added "com.apple.developer.networking.multicast" entitlement in Xcode. It has been confirmed in the terminal.
I expected it to be normal. UDP Limited Broadcast Address Data Transmission by adding entitlement to Project with Provison Profile request and "com.apple.developer.networking.multicast"
motion
Is this correspondence wrong?
Please let me know if you still need it.