RE: mDNS Service Discovery and Text Record access
RE: mDNS Service Discovery and Text Record access
- Subject: RE: mDNS Service Discovery and Text Record access
- From: "Jamie Wood" <email@hidden>
- Date: Wed, 18 Apr 2007 15:22:54 -0700
Hi Alexander,
I think your problem is that hostUrl is declared as an array of pointers to
characters, not as an array of characters. Try this:
char hostUrl[valueLength+1];
Hope that helps,
Jamie
From: Alexander Hartner <email@hidden>
To: email@hidden
Subject: mDNS Service Discovery and Text Record access
Date: Wed, 18 Apr 2007 23:16:16 +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)
{
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
<< smime.p7s >>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_________________________________________________________________
Mortgage rates near historic lows. Refinance $200,000 loan for as low as
$771/month*
https://www2.nextag.com/goto.jsp?product=100000035&url=/st.jsp&tm=y&search=mortgage_text_links_88_h27f8&disc=y&vers=689&s=4056&p=5117
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden