Methods Summary |
---|
public java.lang.String | getDnsQueryName()Returns query DNS name.
sVmpack = new HashMap<Integer, String>();
sVmpack.put(0x0c, "_tcp.local.");
sVmpack.put(0x11, "local.");
sVmpack.put(0x1c, "_udp.local.");
return mDnsQueryName;
|
public int | getDnsType()Return query DNS type.
return mDnsType;
|
public java.lang.String | getInstanceName()Return instance name.
return mInstanceName;
|
public java.util.Map | getTxtRecord()Return TXT record data.
return mTxtRecord;
|
public int | getVersion()Return bonjour version number.
return mVersion;
|
static android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceResponse | newInstance(int status, int transId, android.net.wifi.p2p.WifiP2pDevice dev, byte[] data)Creates DnsSd service response.
This is only called from WifiP2pServiceResponse
if (status != WifiP2pServiceResponse.Status.SUCCESS) {
return new WifiP2pDnsSdServiceResponse(status,
transId, dev, null);
}
try {
return new WifiP2pDnsSdServiceResponse(status,
transId, dev, data);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return null;
|
private boolean | parse()Parse DnsSd service discovery response.
/*
* The data format from Wi-Fi Direct spec is as follows.
* ________________________________________________
* | encoded and compressed dns name (variable) |
* ________________________________________________
* | dnstype(2byte) | version(1byte) |
* ________________________________________________
* | RDATA (variable) |
*/
if (mData == null) {
// the empty is OK.
return true;
}
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(mData));
mDnsQueryName = readDnsName(dis);
if (mDnsQueryName == null) {
return false;
}
try {
mDnsType = dis.readUnsignedShort();
mVersion = dis.readUnsignedByte();
} catch (IOException e) {
e.printStackTrace();
return false;
}
if (mDnsType == WifiP2pDnsSdServiceInfo.DNS_TYPE_PTR) {
String rData = readDnsName(dis);
if (rData == null) {
return false;
}
if (rData.length() <= mDnsQueryName.length()) {
return false;
}
mInstanceName = rData.substring(0,
rData.length() - mDnsQueryName.length() -1);
} else if (mDnsType == WifiP2pDnsSdServiceInfo.DNS_TYPE_TXT) {
return readTxtData(dis);
} else {
return false;
}
return true;
|
private java.lang.String | readDnsName(java.io.DataInputStream dis)Read dns name.
StringBuffer sb = new StringBuffer();
// copy virtual memory packet.
HashMap<Integer, String> vmpack = new HashMap<Integer, String>(sVmpack);
if (mDnsQueryName != null) {
vmpack.put(0x27, mDnsQueryName);
}
try {
while (true) {
int i = dis.readUnsignedByte();
if (i == 0x00) {
return sb.toString();
} else if (i == 0xc0) {
// refer to pointer.
String ref = vmpack.get(dis.readUnsignedByte());
if (ref == null) {
//invalid.
return null;
}
sb.append(ref);
return sb.toString();
} else {
byte[] data = new byte[i];
dis.readFully(data);
sb.append(new String(data));
sb.append(".");
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
|
private boolean | readTxtData(java.io.DataInputStream dis)Read TXT record data.
try {
while (dis.available() > 0) {
int len = dis.readUnsignedByte();
if (len == 0) {
break;
}
byte[] data = new byte[len];
dis.readFully(data);
String[] keyVal = new String(data).split("=");
if (keyVal.length != 2) {
return false;
}
mTxtRecord.put(keyVal[0], keyVal[1]);
}
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
|
public java.lang.String | toString()
StringBuffer sbuf = new StringBuffer();
sbuf.append("serviceType:DnsSd(").append(mServiceType).append(")");
sbuf.append(" status:").append(Status.toString(mStatus));
sbuf.append(" srcAddr:").append(mDevice.deviceAddress);
sbuf.append(" version:").append(String.format("%02x", mVersion));
sbuf.append(" dnsName:").append(mDnsQueryName);
sbuf.append(" TxtRecord:");
for (String key : mTxtRecord.keySet()) {
sbuf.append(" key:").append(key).append(" value:").append(mTxtRecord.get(key));
}
if (mInstanceName != null) {
sbuf.append(" InsName:").append(mInstanceName);
}
return sbuf.toString();
|