Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
Revision 101:5022828ace54, committed 2014-10-27
- Comitter:
- nyatla
- Date:
- Mon Oct 27 11:21:29 2014 +0000
- Parent:
- 100:8d45dab6dcf6
- Child:
- 102:41a5e92e0a8e
- Commit message:
- mDNS????????????
Changed in this revision
| core/net/mdns/NyLPC_cMDnsServer.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/core/net/mdns/NyLPC_cMDnsServer.c Sun Oct 26 14:11:23 2014 +0000
+++ b/core/net/mdns/NyLPC_cMDnsServer.c Mon Oct 27 11:21:29 2014 +0000
@@ -37,7 +37,7 @@
#define MDNS_MCAST_PORT 5353
static const struct NyLPC_TIPv4Addr MDNS_MCAST_IPADDR=NyLPC_TIPv4Addr_pack(224,0,0,251);
#define TIMEOUT_IN_MS 1000
-#define NyLPC_TcMDns_TTL (30*60) //30min
+#define NyLPC_TcMDns_TTL (120) //120
struct NyLPC_TDnsHeader
@@ -80,6 +80,8 @@
#define NyLPC_TDnsQuestion_QCLASS_CH 3
#define NyLPC_TDnsQuestion_QCLASS_HS 4
#define NyLPC_TDnsQuestion_QTYPR_SRV 33
+#define NyLPC_TDnsQuestion_QCLASS_CACHE_FLUSH 0x8000
+
/**************************************************
* TLabelCache
@@ -118,7 +120,7 @@
/**
* 展開しない圧縮文字列の長さを返す
*/
-NyLPC_TInt16 sizeofCompressName(const char* i_str)
+static NyLPC_TInt16 sizeofCompressName(const char* i_str)
{
NyLPC_TInt16 l = 0;
NyLPC_TUInt8 c;
@@ -285,9 +287,9 @@
return NyLPC_ntohs(ptr->qd);
}
-
/**
* [i_name].[i_protocol].localをquestionと比較します。i_nameは省略ができます。
+ * i_nameはincasesensitiveです。
* @return 等しい場合true
*/
static NyLPC_TBool NyLPC_TDnsQuestion_isEqualName(const struct NyLPC_TDnsQuestion* question, const char* i_name, const char* i_protocol)
@@ -304,7 +306,7 @@
return NyLPC_TBool_FALSE;
}
tmp = (NyLPC_TUInt8)strlen(i_name);
- if (tmp != *s || memcmp(s + 1, i_name, tmp) != 0){
+ if (tmp != *s || NyLPC_strnicmp(s + 1, i_name, tmp) != 0){
return NyLPC_TBool_FALSE;
}
s += (*s) + 1;
@@ -426,7 +428,7 @@
/**
* ResourceHeaderのライタ
- */
+ *//*
static NyLPC_TInt16 writeResourceHeader(char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 buflen,const char* i_name,NyLPC_TUInt16 i_type,NyLPC_TUInt16 i_class)
{
NyLPC_TInt16 s;
@@ -442,7 +444,7 @@
(*(NyLPC_TUInt16*)(i_packet+l+2))=NyLPC_HTONS(i_class);
(*(NyLPC_TUInt32*)(i_packet+l+4))=NyLPC_HTONL(NyLPC_TcMDns_TTL);
return l+2+2+4;
-}
+}*/
inline static NyLPC_TInt16 writeSrvResourceHeader(char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 buflen,const struct NyLPC_TDnsRecord* i_recode,int i_sid,NyLPC_TUInt16 i_type,NyLPC_TUInt16 i_class)
{
@@ -482,22 +484,75 @@
p->ar=NyLPC_HTONS(i_ar_count);
return sizeof(struct NyLPC_TDnsHeader);
}
-inline static NyLPC_TInt16 writeARecord(char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 obuflen,const NyLPC_TChar* a_rec,const struct NyLPC_TIPv4Addr* ip)
+/**
+ * ドメイン名からAレコードレスポンスを書きだす。
+ */
+inline static NyLPC_TInt16 writeARecord(char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 obuflen,const NyLPC_TChar* i_name,const struct NyLPC_TIPv4Addr* ip)
{
NyLPC_TInt16 s;
//AnswerはAレコードのみ
+ NyLPC_TInt16 l=1+(NyLPC_TInt16)strlen(i_name)+1+5+1;
+ if(obuflen<i_spos+l+4+4){
+ return 0;
+ }
+ s=str2label(i_packet+i_spos,i_name)-1;
+ s+=str2label(i_packet+i_spos+s,"local");
+ //レコード圧縮
+ l=compressName(i_packet,i_spos,s);
+ (*(NyLPC_TUInt16*)(i_packet+l))=NyLPC_HTONS(NyLPC_TDnsQuestion_QTYPR_A);
+ (*(NyLPC_TUInt16*)(i_packet+l+2))=NyLPC_HTONS(NyLPC_TDnsQuestion_QCLASS_IN|NyLPC_TDnsQuestion_QCLASS_CACHE_FLUSH);
+ (*(NyLPC_TUInt32*)(i_packet+l+4))=NyLPC_HTONL(NyLPC_TcMDns_TTL);
+ l+=2+2+4;
//A record header
- s=writeResourceHeader(i_packet,i_spos,obuflen,a_rec,NyLPC_TDnsQuestion_QTYPR_A,NyLPC_TDnsQuestion_QCLASS_IN);
- if(s==0 || obuflen<s+6){
+ if(obuflen<l+6){
return 0;
}
//Aレコードを書く
//IPADDR
- (*(NyLPC_TUInt16*)(i_packet+s))=NyLPC_HTONS(4);
- (*(NyLPC_TUInt32*)(i_packet+s+2))=ip->v;
- return s+6;
+ (*(NyLPC_TUInt16*)(i_packet+l))=NyLPC_HTONS(4);
+ (*(NyLPC_TUInt32*)(i_packet+l+2))=ip->v;
+ return l+6;
}
-
+/**
+ * AレコードクエリからAレコードレスポンスを書きだす。
+ */
+inline static NyLPC_TInt16 writeARecordByQuery(char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 obuflen,const NyLPC_TChar* i_query,const struct NyLPC_TIPv4Addr* ip)
+{
+ const char* n;
+ NyLPC_TInt16 s;
+ //AnswerはAレコードのみ
+ NyLPC_TInt16 l;
+ s=0;
+ for(;;){
+ n=getExtractNamePos(i_query,i_query+s);
+ if(n==NULL){
+ *(i_packet+i_spos+s)=0;
+ s++;
+ break;
+ }else{
+ memcpy(i_packet+i_spos+s,i_query+s,((NyLPC_TUInt8)*n)+1);
+ s+=((NyLPC_TUInt8)*n)+1;
+ if(obuflen<i_spos+s+1+4+4){
+ return 0;
+ }
+ }
+ }
+ //レコード圧縮
+ l=compressName(i_packet,i_spos,s);
+ (*(NyLPC_TUInt16*)(i_packet+l))=NyLPC_HTONS(NyLPC_TDnsQuestion_QTYPR_A);
+ (*(NyLPC_TUInt16*)(i_packet+l+2))=NyLPC_HTONS(NyLPC_TDnsQuestion_QCLASS_IN|NyLPC_TDnsQuestion_QCLASS_CACHE_FLUSH);
+ (*(NyLPC_TUInt32*)(i_packet+l+4))=NyLPC_HTONL(NyLPC_TcMDns_TTL);
+ l+=2+2+4;
+ //A record header
+ if(obuflen<l+6){
+ return 0;
+ }
+ //Aレコードを書く
+ //IPADDR
+ (*(NyLPC_TUInt16*)(i_packet+l))=NyLPC_HTONS(4);
+ (*(NyLPC_TUInt32*)(i_packet+l+2))=ip->v;
+ return l+6;
+}
static NyLPC_TInt16 writeSdPtrRecord(const struct NyLPC_TDnsQuestion* i_question,const struct NyLPC_TMDnsServiceRecord* i_srvlec,char* i_packet,NyLPC_TInt16 i_spos,NyLPC_TInt16 obuflen)
{
@@ -568,7 +623,7 @@
NyLPC_TUInt16* rlen;
//SRV Record
- s=writeSrvResourceHeader(i_packet,i_spos,obuflen,i_inst->_ref_record,i_sid,NyLPC_TDnsQuestion_QTYPR_SRV,NyLPC_TDnsQuestion_QCLASS_IN);
+ s=writeSrvResourceHeader(i_packet,i_spos,obuflen,i_inst->_ref_record,i_sid,NyLPC_TDnsQuestion_QTYPR_SRV,NyLPC_TDnsQuestion_QCLASS_IN|NyLPC_TDnsQuestion_QCLASS_CACHE_FLUSH);
if(s==0){
return 0;
}
@@ -594,7 +649,7 @@
NyLPC_TInt16 ret;
NyLPC_TInt16 l;
//Answer
- ret=writeSrvResourceHeader(i_packet,i_spos,obuflen,i_inst->_ref_record,i_sid,NyLPC_TDnsQuestion_QTYPR_TXT,NyLPC_TDnsQuestion_QCLASS_IN);
+ ret=writeSrvResourceHeader(i_packet,i_spos,obuflen,i_inst->_ref_record,i_sid,NyLPC_TDnsQuestion_QTYPR_TXT,NyLPC_TDnsQuestion_QCLASS_IN|NyLPC_TDnsQuestion_QCLASS_CACHE_FLUSH);
if(ret==0){
return 0;
}
@@ -703,7 +758,7 @@
//Headerのコピー
l=setResponseHeader(obuf,i_dns_header,1,0,0);
//Aレコードのみ
- l=writeARecord(obuf,l,obuflen,i_inst->_ref_record->a,&(i_inst->_super.uip_udp_conn.lipaddr));
+ l=writeARecordByQuery(obuf,l,obuflen,q->buf+q->qname_pos,&(i_inst->_super.uip_udp_conn.lipaddr));
if(l<=0){
NyLPC_OnErrorGoto(ERROR);
}
@@ -829,7 +884,7 @@
//アナウンス
sendAnnounse(((NyLPC_TcMDnsServer_t*)i_inst));
//TTL(msec)*1000*80%
- NyLPC_cStopwatch_startExpire((&((NyLPC_TcMDnsServer_t*)i_inst)->_periodic_sw),NyLPC_TcMDns_TTL*1000/2);
+ NyLPC_cStopwatch_startExpire((&((NyLPC_TcMDnsServer_t*)i_inst)->_periodic_sw),NyLPC_TcMDns_TTL*1000*4/5);
}
}
MiMic Webservice library