void resolveCallBack (DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const char *txtRecord, void *context )
{
if (errorCode == kDNSServiceErr_NoError)
{
NSLog(@"FULLNAME : %s \n",fullname);
NSLog(@"HOST : %s \n",hosttarget);
NSLog(@"PORT : %i \n",port);
NSLog(@"TXT : %s \n",txtRecord);
uint8_t valueLength;
const char * value = TXTRecordGetValuePtr(txtLen,txtRecord,"hostUrl",&valueLength);
NSLog(@"SIZE OF CHAR : %i \n",sizeof(char));
NSLog(@"URL : >%s< (%i)\n",value,valueLength);
char * hostUrl[valueLength+1];
bcopy(value,hostUrl, valueLength );
hostUrl[valueLength] = '\0';
NSLog(@"Host : >%s< \n",hostUrl);
}
else
{
NSLog(@"ResolveCallBack returned error : %d\n", errorCode);
}
}
I change the code above as follows:
bcopy(value,hostUrl, valueLength ); hostUrl[1] = '\0';
NSLog(@"Host : >%s< \n",hostUrl);
But what I ended up was 4 characters being printed. I know that the resulting string should be 34 characters long, but it seems that the index at which I insert the termination character is not set correctly. Index 1 resulted in character 4, index 2 in 8 etc. I though it must be a problem with the size of char, but sizeof return 1 byte and bcopy should copy bytes.
I tried to search on the web for an example of doing this, but didn't find anything useful. I am sure I am just doing something incredibly silly.
Any help is greatly appreciated.
Alex