NameServicePacketpublic abstract class NameServicePacket extends Object
Fields Summary |
---|
static final int | QUERY | static final int | WACK | static final int | FMT_ERR | static final int | SRV_ERR | static final int | IMP_ERR | static final int | RFS_ERR | static final int | ACT_ERR | static final int | CFT_ERR | static final int | NB_IN | static final int | NBSTAT_IN | static final int | NB | static final int | NBSTAT | static final int | IN | static final int | A | static final int | NS | static final int | NULL | static final int | HEADER_LENGTH | static final int | OPCODE_OFFSET | static final int | QUESTION_OFFSET | static final int | ANSWER_OFFSET | static final int | AUTHORITY_OFFSET | static final int | ADDITIONAL_OFFSET | int | addrIndex | NbtAddress[] | addrEntry | int | nameTrnId | int | opCode | int | resultCode | int | questionCount | int | answerCount | int | authorityCount | int | additionalCount | boolean | received | boolean | isResponse | boolean | isAuthAnswer | boolean | isTruncated | boolean | isRecurDesired | boolean | isRecurAvailable | boolean | isBroadcast | Name | questionName | Name | recordName | int | questionType | int | questionClass | int | recordType | int | recordClass | int | ttl | int | rDataLength | InetAddress | addr |
Constructors Summary |
---|
NameServicePacket()
isRecurDesired = true;
isBroadcast = true;
questionCount = 1;
questionClass = IN;
|
Methods Summary |
---|
abstract int | readBodyWireFormat(byte[] src, int srcIndex)
| int | readHeaderWireFormat(byte[] src, int srcIndex)
nameTrnId = readInt2( src, srcIndex );
isResponse = (( src[srcIndex + OPCODE_OFFSET] & 0x80 ) == 0 ) ? false : true;
opCode = ( src[srcIndex + OPCODE_OFFSET] & 0x78 ) >> 3;
isAuthAnswer = (( src[srcIndex + OPCODE_OFFSET] & 0x04 ) == 0 ) ? false : true;
isTruncated = (( src[srcIndex + OPCODE_OFFSET] & 0x02 ) == 0 ) ? false : true;
isRecurDesired = (( src[srcIndex + OPCODE_OFFSET] & 0x01 ) == 0 ) ? false : true;
isRecurAvailable =
(( src[srcIndex + OPCODE_OFFSET + 1] & 0x80 ) == 0 ) ? false : true;
isBroadcast = (( src[srcIndex + OPCODE_OFFSET + 1] & 0x10 ) == 0 ) ? false : true;
resultCode = src[srcIndex + OPCODE_OFFSET + 1] & 0x0F;
questionCount = readInt2( src, srcIndex + QUESTION_OFFSET );
answerCount = readInt2( src, srcIndex + ANSWER_OFFSET );
authorityCount = readInt2( src, srcIndex + AUTHORITY_OFFSET );
additionalCount = readInt2( src, srcIndex + ADDITIONAL_OFFSET );
return HEADER_LENGTH;
| static int | readInt2(byte[] src, int srcIndex)
return (( src[srcIndex] & 0xFF ) << 8 ) +
( src[srcIndex + 1] & 0xFF );
| static int | readInt4(byte[] src, int srcIndex)
return (( src[srcIndex] & 0xFF ) << 24 ) +
(( src[srcIndex + 1] & 0xFF ) << 16 ) +
(( src[srcIndex + 2] & 0xFF ) << 8 ) +
( src[srcIndex + 3] & 0xFF );
| static int | readNameTrnId(byte[] src, int srcIndex)
return readInt2( src, srcIndex );
| int | readQuestionSectionWireFormat(byte[] src, int srcIndex)
int start = srcIndex;
srcIndex += questionName.readWireFormat( src, srcIndex );
questionType = readInt2( src, srcIndex );
srcIndex += 2;
questionClass = readInt2( src, srcIndex );
srcIndex += 2;
return srcIndex - start;
| abstract int | readRDataWireFormat(byte[] src, int srcIndex)
| int | readResourceRecordWireFormat(byte[] src, int srcIndex)
int start = srcIndex;
int end;
if(( src[srcIndex] & 0xC0 ) == 0xC0 ) {
recordName = questionName; // label string pointer to questionName
srcIndex += 2;
} else {
srcIndex += recordName.readWireFormat( src, srcIndex );
}
recordType = readInt2( src, srcIndex );
srcIndex += 2;
recordClass = readInt2( src, srcIndex );
srcIndex += 2;
ttl = readInt4( src, srcIndex );
srcIndex += 4;
rDataLength = readInt2( src, srcIndex );
srcIndex += 2;
addrEntry = new NbtAddress[rDataLength / 6];
end = srcIndex + rDataLength;
for( addrIndex = 0; srcIndex < end; addrIndex++ ) {
srcIndex += readRDataWireFormat( src, srcIndex );
}
return srcIndex - start;
| int | readWireFormat(byte[] src, int srcIndex)
int start = srcIndex;
srcIndex += readHeaderWireFormat( src, srcIndex );
srcIndex += readBodyWireFormat( src, srcIndex );
return srcIndex - start;
| public java.lang.String | toString()
String opCodeString,
resultCodeString,
questionTypeString,
questionClassString,
recordTypeString,
recordClassString;
switch( opCode ) {
case QUERY:
opCodeString = "QUERY";
break;
case WACK:
opCodeString = "WACK";
break;
default:
opCodeString = Integer.toString( opCode );
break;
}
switch( resultCode ) {
case FMT_ERR:
resultCodeString = "FMT_ERR";
break;
case SRV_ERR:
resultCodeString = "SRV_ERR";
break;
case IMP_ERR:
resultCodeString = "IMP_ERR";
break;
case RFS_ERR:
resultCodeString = "RFS_ERR";
break;
case ACT_ERR:
resultCodeString = "ACT_ERR";
break;
case CFT_ERR:
resultCodeString = "CFT_ERR";
break;
default:
resultCodeString = "0x" + Hexdump.toHexString( resultCode, 1 );
break;
}
switch( questionType ) {
case NB:
questionTypeString = "NB";
break;
case NBSTAT:
questionTypeString = "NBSTAT";
break;
default:
questionTypeString = "0x" + Hexdump.toHexString( questionType, 4 );
break;
}
switch( recordType ) {
case A:
recordTypeString = "A";
break;
case NS:
recordTypeString = "NS";
break;
case NULL:
recordTypeString = "NULL";
break;
case NB:
recordTypeString = "NB";
break;
case NBSTAT:
recordTypeString = "NBSTAT";
break;
default:
recordTypeString = "0x" + Hexdump.toHexString( recordType, 4 );
break;
}
return new String(
"nameTrnId=" + nameTrnId +
",isResponse=" + isResponse +
",opCode=" + opCodeString +
",isAuthAnswer=" + isAuthAnswer +
",isTruncated=" + isTruncated +
",isRecurAvailable=" + isRecurAvailable +
",isRecurDesired=" + isRecurDesired +
",isBroadcast=" + isBroadcast +
",resultCode=" + resultCode +
",questionCount=" + questionCount +
",answerCount=" + answerCount +
",authorityCount=" + authorityCount +
",additionalCount=" + additionalCount +
",questionName=" + questionName +
",questionType=" + questionTypeString +
",questionClass=" + ( questionClass == IN ? "IN" :
"0x" + Hexdump.toHexString( questionClass, 4 )) +
",recordName=" + recordName +
",recordType=" + recordTypeString +
",recordClass=" + ( recordClass == IN ? "IN" :
"0x" + Hexdump.toHexString( recordClass, 4 )) +
",ttl=" + ttl +
",rDataLength=" + rDataLength );
| abstract int | writeBodyWireFormat(byte[] dst, int dstIndex)
| int | writeHeaderWireFormat(byte[] dst, int dstIndex)
int start = dstIndex;
writeInt2( nameTrnId, dst, dstIndex );
dst[dstIndex + OPCODE_OFFSET] = (byte)(( isResponse ? 0x80 : 0x00 ) +
(( opCode << 3 ) & 0x78 ) +
( isAuthAnswer ? 0x04 : 0x00 ) +
( isTruncated ? 0x02 : 0x00 ) +
( isRecurDesired ? 0x01 : 0x00 ));
dst[dstIndex + OPCODE_OFFSET + 1] = (byte)(( isRecurAvailable ? 0x80 : 0x00 ) +
( isBroadcast ? 0x10 : 0x00 ) +
( resultCode & 0x0F ));
writeInt2( questionCount, dst, start + QUESTION_OFFSET );
writeInt2( answerCount, dst, start + ANSWER_OFFSET );
writeInt2( authorityCount, dst, start + AUTHORITY_OFFSET );
writeInt2( additionalCount, dst, start + ADDITIONAL_OFFSET );
return HEADER_LENGTH;
| static void | writeInt2(int val, byte[] dst, int dstIndex)
dst[dstIndex++] = (byte)(( val >> 8 ) & 0xFF );
dst[dstIndex] = (byte)( val & 0xFF );
| static void | writeInt4(int val, byte[] dst, int dstIndex)
dst[dstIndex++] = (byte)(( val >> 24 ) & 0xFF );
dst[dstIndex++] = (byte)(( val >> 16 ) & 0xFF );
dst[dstIndex++] = (byte)(( val >> 8 ) & 0xFF );
dst[dstIndex] = (byte)( val & 0xFF );
| int | writeQuestionSectionWireFormat(byte[] dst, int dstIndex)
int start = dstIndex;
dstIndex += questionName.writeWireFormat( dst, dstIndex );
writeInt2( questionType, dst, dstIndex );
dstIndex += 2;
writeInt2( questionClass, dst, dstIndex );
dstIndex += 2;
return dstIndex - start;
| abstract int | writeRDataWireFormat(byte[] dst, int dstIndex)
| int | writeResourceRecordWireFormat(byte[] dst, int dstIndex)
int start = dstIndex;
if( recordName == questionName ) {
dst[dstIndex++] = (byte)0xC0; // label string pointer to
dst[dstIndex++] = (byte)0x0C; // questionName (offset 12)
} else {
dstIndex += recordName.writeWireFormat( dst, dstIndex );
}
writeInt2( recordType, dst, dstIndex );
dstIndex += 2;
writeInt2( recordClass, dst, dstIndex );
dstIndex += 2;
writeInt4( ttl, dst, dstIndex );
dstIndex += 4;
rDataLength = writeRDataWireFormat( dst, dstIndex + 2 );
writeInt2( rDataLength, dst, dstIndex );
dstIndex += 2 + rDataLength;
return dstIndex - start;
| int | writeWireFormat(byte[] dst, int dstIndex)
int start = dstIndex;
dstIndex += writeHeaderWireFormat( dst, dstIndex );
dstIndex += writeBodyWireFormat( dst, dstIndex );
return dstIndex - start;
|
|