mDNS Service Discovery and Text Record access
mDNS Service Discovery and Text Record access
- Subject: mDNS Service Discovery and Text Record access
- From: Alexander Hartner <email@hidden>
- Date: Wed, 18 Apr 2007 23:20:14 +0100
I am trying to discover a service published via mDNS. This is my call
back function. My problem is that I have so far not been able to
access the TextRecords attributes. It seems that the size of the
string is behaving very oddly.
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)
{
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);
}
}
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 Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden