I received this email from a customer:
It's been over a year since I last touched the networking part of Battery Status, and I believe I copied most of it out of a sample project. I've been trying to track down a spot where a port is chosen... it appears to be done in the function that I've reproduced (in a condensed fashion - I took out a lot of error checking code) below:
Checking the documentation on all these functions, it seems that the port is automagically chosen (by Bonjour?) Which brings me to my question: what does my end user have to do to enable this code to work on their Mac?
I searched through System Preferences but nothing jumped out at me as relevant.
Im in the process of testing your software to make sure it meets our requirements. I have set two instances up and I can see our network is blocking the traffic from your tool.
Can I ask what protocol or ports your software uses??
I have tested it on my home network and it works brilliantly but I need to understand what is required to get the tool working in a corporate network.
It's been over a year since I last touched the networking part of Battery Status, and I believe I copied most of it out of a sample project. I've been trying to track down a spot where a port is chosen... it appears to be done in the function that I've reproduced (in a condensed fashion - I took out a lot of error checking code) below:
Code:
socklen_t namelen;
int fdForListening = socket(AF_INET6, SOCK_STREAM, 0);
struct sockaddr_in6 serverAddress6;
memset(&serverAddress6, 0, sizeof(serverAddress6));
serverAddress6.sin6_family = AF_INET6;
serverAddress6.sin6_len = sizeof(serverAddress6);
bind(fdForListening, (const struct sockaddr *) &serverAddress6, sizeof(serverAddress6));
namelen = sizeof(serverAddress6);
getsockname(fdForListening, (struct sockaddr *) &serverAddress6, &namelen);
chosenPort = ntohs(serverAddress6.sin6_port);
// checks an error code, repeats using IPv4 instead of IPv6 if the error is equal to EAFNOSUPPORT... omitting that because it's nearly identical code...
// Listen for connections on our socket, then create a CFSocket to route any connections to a run loop based callback.
listen(fdForListening, 5);
// Register our service with Bonjour.
CFSocketContext context = {0, self, NULL, NULL, NULL};
CFRunLoopSourceRef rls;
self->_listeningSocket = CFSocketCreateWithNative(NULL, fdForListening, kCFSocketAcceptCallBack, ListeningSocketCallback, &context);
fdForListening = -1; // so that the clean up code doesn't close it
rls = CFSocketCreateRunLoopSource(NULL, self->_listeningSocket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
CFRelease(rls);
[[NSNetService alloc] initWithDomain:@"" type:kServiceTypeBatteryStatus name:self.serviceName port:chosenPort]
Checking the documentation on all these functions, it seems that the port is automagically chosen (by Bonjour?) Which brings me to my question: what does my end user have to do to enable this code to work on their Mac?
I searched through System Preferences but nothing jumped out at me as relevant.
Last edited: