Comments (9)
@fra189 fwiw, if you're just looking to resolve mDNS services on your network (rather than advertise them), you may be able to avoid having to join the multicast group to get a response. You can send an mDNS query and request a unicast response by setting the unicast-response bit in the header. It doesn't guarantee a unicast response, but it generally should result in one (especially if you send QU queries periodically if you get no response).
See https://datatracker.ietf.org/doc/html/rfc6762#section-5.4
from libnx.
I think this is actually about library compatibility version, not about permissions.
This is untested and based on RE, but I think the line that causes EPERM is this one: https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/devices/socket.c#L65
If I am reading this permission check function right, the following require library version > 3:
IP_MULTICAST_IF
IP_MULTICAST_TTL
IP_MULTICAST_LOOP
IP_ADD_MEMBERSHIP
IP_DROP_MEMBERSHIP
IP_MULTICAST_VIF
I think BsdServiceType_System just causes an early return in the permission checking function, which bypasses the library compatibility check entirely.
from libnx.
What did you fill into addr
for IP_MULTICAST_IF
and mreq
for IP_ADD_MEMBERSHIP
?
from libnx.
Hi,
Thank you for answering.
So this is the part of the code:
#define MDNS_MULTICAST_ADDRESS "224.0.0.251"
#define MDNS_PORT 5353
int init(struct in_addr host) {
struct ip_mreq mreq;
struct sockaddr_in addr;
int sock;
char param;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0) {
return sock;
}
param = 32;
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (void*) ¶m, sizeof(param)) < 0) {
return -1;
}
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(MDNS_PORT);
addr.sin_addr.s_addr = INADDR_ANY;
if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
return -1;
}
memset(&mreq, 0, sizeof(mreq));
mreq.imr_multiaddr.s_addr = inet_addr(MDNS_MULTICAST_ADDRESS);
mreq.imr_interface.s_addr = host.s_addr;
if (setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (void*) &mreq.imr_interface.s_addr, sizeof(mreq.imr_interface.s_addr)) < 0) {
return -1;
}
if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void*) &mreq, sizeof(mreq)) < 0) {
return -1;
}
return sock;
}
.....
struct in_addr host;
const long ip = gethostid();
char ip_str[32] = {0};
inet_ntop(AF_INET, &ip, ip_str, sizeof(ip_str));
host.s_addr = inet_addr(ip_str);
int sock = init(host);
from libnx.
I get EPERM for every multicast-related socket option. It's possible the OS won't allow unprivileged multicast servers.
from libnx.
Thank you @cgutman
I can make a try with that.
from libnx.
I figured out how to join a multicast group, just pass in higher permissions when initializing the socket.
SocketInitConfig cfg = *(socketGetDefaultInitConfig());
cfg.bsd_service_type = BsdServiceType_Auto; // or BsdServiceType_System
socketInitialize(&cfg);
This can also be used to help create an 80 port HTTP service, hoping this comment would help someone ~
from libnx.
Thanks for the detailed explanation, I confirmed that after setting cfg.bsdsockets_version = 4;
, multicast is indeed working.
from libnx.
Fixed by libnx v4.5.0.
from libnx.
Related Issues (20)
- inet_pton() failure for 0.0.0.0
- Can't open file sys/lock.h HOT 1
- Linking errors with nwindowGetDefault() HOT 8
- Rotated/Normalized controller layouts using the pad abstraction API HOT 2
- Question: Home button HOT 3
- SL/SR buttons usage on hiddbg HOT 6
- Linear framebuffer crashes on certain dimensions HOT 2
- hidScanInput() was not declared in this scope HOT 6
- When i try to compile a .nro in devkitpro, i get this error: HOT 3
- web applet fails to connect to local server running on the switch HOT 17
- Question: Video HW Decoder HOT 9
- Nintendo HOT 1
- make a relase/how to compile it HOT 2
- ASCII Usage of "\" HOT 2
- Problem to print special chars in console mode HOT 4
- bool to pointer
- Wrong Github (sorry)
- Support: How to get a list of installed DLCs? HOT 2
- devkitPro on NixOS? HOT 1
- Support for HID Vibrations HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libnx.