I apologize for the thread title as I really don't know what this issue has to do with!
I have the following lines of code in the updated EthernetBonjour library :
Both "this->addServiceRecord" lines compile fine but as noted in the code only one of them works for the Teensy++2 and the other one for the Teensy 3.x. With "working" I mean actually registering a bonjour service so it shows up in the bonjour browser and such that I can ping the IP. When it does not work there is just no service registered and I cannot ping the IP.
The complete code for "addServiceRecord" looks like this:
Naturally I would like to make this work for both boards without any #defines.
I have the following lines of code in the updated EthernetBonjour library :
Code:
int EthernetBonjourClass::addServiceRecord(const char* name, uint16_t port,
MDNSServiceProtocol_t proto)
{
return this->addServiceRecord(name, port, proto, ""); //works for Teensy 2 (8-bit Atmel)
// return this->addServiceRecord(name, port, proto, NULL); //works for Teensy 3 (32-bit Arm Cortex)
}
Both "this->addServiceRecord" lines compile fine but as noted in the code only one of them works for the Teensy++2 and the other one for the Teensy 3.x. With "working" I mean actually registering a bonjour service so it shows up in the bonjour browser and such that I can ping the IP. When it does not work there is just no service registered and I cannot ping the IP.
The complete code for "addServiceRecord" looks like this:
Code:
// return values:
// 1 on success
// 0 otherwise
int EthernetBonjourClass::addServiceRecord(const char* name, uint16_t port,
MDNSServiceProtocol_t proto, const char* textContent)
{
int i, status = 0;
MDNSServiceRecord_t* record = NULL;
if (NULL != name && 0 != port) {
for (i=0; i < NumMDNSServiceRecords; i++) {
if (NULL == this->_serviceRecords[i]) {
record = (MDNSServiceRecord_t*)my_malloc(sizeof(MDNSServiceRecord_t));
if (NULL != record) {
record->name = record->textContent = NULL;
record->name = (uint8_t*)my_malloc(strlen((char*)name));
if (NULL == record->name)
goto errorReturn;
if (NULL != textContent) {
record->textContent = (uint8_t*)my_malloc(strlen((char*)textContent));
if (NULL == record->textContent)
goto errorReturn;
strcpy((char*)record->textContent, textContent);
}
record->port = port;
record->proto = proto;
strcpy((char*)record->name, name);
uint8_t* s = this->_findFirstDotFromRight(record->name);
record->servName = (uint8_t*)my_malloc(strlen((char*)s) + 12);
if (record->servName) {
strcpy((char*)record->servName, (const char*)s);
const uint8_t* srv_type = this->_postfixForProtocol(proto);
if (srv_type)
strcat((char*)record->servName, (const char*)srv_type);
}
this->_serviceRecords[i] = record;
status = (MDNSSuccess ==
this->_sendMDNSMessage(0, 0, (int)MDNSPacketTypeServiceRecord, i));
break;
}
}
}
}
return status;
errorReturn:
if (NULL != record) {
if (NULL != record->name)
my_free(record->name);
if (NULL != record->servName)
my_free(record->servName);
if (NULL != record->textContent)
my_free(record->textContent);
my_free(record);
}
return 0;
}
Naturally I would like to make this work for both boards without any #defines.