Hi ,
We are developing an iOS application for ipad that uses bonjour for conneting with other devices and couchbaseListener for replications with peer databases. We have observed that whenever [nsnetservice addresses] returns IPV6 address ,replication is not suuccesful.We have tried encoding IPV6 last two components sayfe80::68c8:cfff:fef9:3856 as 254.249.56.86 and using the same in the url but still replications fail.
We get the IPV4 address only when bluetooth is switched on randomly i.e 1 out of 5 times.In other cases ,Peer-Peer Wifi and Infrastructure Wifi only IPV6 address is returned.
In addition to that, [NSNetService addresses] returns only one address from the array.
Is it possible in some proper way to convert IPV6 address to IPV4 address and use the same or else retrieve the IPV4 address?
Please find the code used for converting to Ip address below.
char addressBuffer[INET6_ADDRSTRLEN];
for (NSData *data in self.addresses) {
memset(addressBuffer, 0, INET6_ADDRSTRLEN);
typedef union {
struct sockaddr sa;
struct sockaddr_in ipv4;
struct sockaddr_in6 ipv6;
} ip_socket_address;
ip_socket_address *socketAddress = (ip_socket_address *)[data bytes];
if (socketAddress && (socketAddress->sa.sa_family == AF_INET || socketAddress->sa.sa_family == AF_INET6))
{
const char *addressStr = inet_ntop(
socketAddress->sa.sa_family,
(socketAddress->sa.sa_family == AF_INET ? (void *)&(socketAddress->ipv4.sin_addr) : (void *)&(socketAddress->ipv6.sin6_addr)),
addressBuffer,
sizeof(addressBuffer));
int port = ntohs(socketAddress->sa.sa_family == AF_INET ? socketAddress->ipv4.sin_port : socketAddress->ipv6.sin6_port);
if (addressStr && port)
{
NSLog(@"Found service at %s:%d", addressStr, port);
}
}
Please help .
Thanks & Regards
Lakshminarayana Achar B R
Tata Consultancy Services
Cell:- 9940021554
Mailto: email@hidden
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Consulting
____________________________________________