Class Resolv::DNS::Message
In: lib/resolv.rb
Parent: Object

Methods

Classes and Modules

Class Resolv::DNS::Message::MessageDecoder
Class Resolv::DNS::Message::MessageEncoder

Attributes

aa  [RW] 
additional  [R] 
answer  [R] 
authority  [R] 
id  [RW] 
opcode  [RW] 
qr  [RW] 
question  [R] 
ra  [RW] 
rcode  [RW] 
rd  [RW] 
tc  [RW] 

Public Class methods

[Source]

      # File lib/resolv.rb, line 1263
1263:       def Message.decode(m)
1264:         o = Message.new(0)
1265:         MessageDecoder.new(m) {|msg|
1266:           id, flag, qdcount, ancount, nscount, arcount =
1267:             msg.get_unpack('nnnnnn')
1268:           o.id = id
1269:           o.qr = (flag >> 15) & 1
1270:           o.opcode = (flag >> 11) & 15
1271:           o.aa = (flag >> 10) & 1
1272:           o.tc = (flag >> 9) & 1
1273:           o.rd = (flag >> 8) & 1
1274:           o.ra = (flag >> 7) & 1
1275:           o.rcode = flag & 15
1276:           (1..qdcount).each {
1277:             name, typeclass = msg.get_question
1278:             o.add_question(name, typeclass)
1279:           }
1280:           (1..ancount).each {
1281:             name, ttl, data = msg.get_rr
1282:             o.add_answer(name, ttl, data)
1283:           }
1284:           (1..nscount).each {
1285:             name, ttl, data = msg.get_rr
1286:             o.add_authority(name, ttl, data)
1287:           }
1288:           (1..arcount).each {
1289:             name, ttl, data = msg.get_rr
1290:             o.add_additional(name, ttl, data)
1291:           }
1292:         }
1293:         return o
1294:       end

[Source]

      # File lib/resolv.rb, line 1091
1091:       def initialize(id = (@@identifier += 1) & 0xffff)
1092:         @id = id
1093:         @qr = 0
1094:         @opcode = 0
1095:         @aa = 0
1096:         @tc = 0
1097:         @rd = 0 # recursion desired
1098:         @ra = 0 # recursion available
1099:         @rcode = 0
1100:         @question = []
1101:         @answer = []
1102:         @authority = []
1103:         @additional = []
1104:       end

Public Instance methods

[Source]

      # File lib/resolv.rb, line 1109
1109:       def ==(other)
1110:         return @id == other.id &&
1111:                @qr == other.qr &&
1112:                @opcode == other.opcode &&
1113:                @aa == other.aa &&
1114:                @tc == other.tc &&
1115:                @rd == other.rd &&
1116:                @ra == other.ra &&
1117:                @rcode == other.rcode &&
1118:                @question == other.question &&
1119:                @answer == other.answer &&
1120:                @authority == other.authority &&
1121:                @additional == other.additional
1122:       end

[Source]

      # File lib/resolv.rb, line 1154
1154:       def add_additional(name, ttl, data)
1155:         @additional << [Name.create(name), ttl, data]
1156:       end

[Source]

      # File lib/resolv.rb, line 1134
1134:       def add_answer(name, ttl, data)
1135:         @answer << [Name.create(name), ttl, data]
1136:       end

[Source]

      # File lib/resolv.rb, line 1144
1144:       def add_authority(name, ttl, data)
1145:         @authority << [Name.create(name), ttl, data]
1146:       end

[Source]

      # File lib/resolv.rb, line 1124
1124:       def add_question(name, typeclass)
1125:         @question << [Name.create(name), typeclass]
1126:       end

[Source]

      # File lib/resolv.rb, line 1158
1158:       def each_additional
1159:         @additional.each {|name, ttl, data|
1160:           yield name, ttl, data
1161:         }
1162:       end

[Source]

      # File lib/resolv.rb, line 1138
1138:       def each_answer
1139:         @answer.each {|name, ttl, data|
1140:           yield name, ttl, data
1141:         }
1142:       end

[Source]

      # File lib/resolv.rb, line 1148
1148:       def each_authority
1149:         @authority.each {|name, ttl, data|
1150:           yield name, ttl, data
1151:         }
1152:       end

[Source]

      # File lib/resolv.rb, line 1128
1128:       def each_question
1129:         @question.each {|name, typeclass|
1130:           yield name, typeclass
1131:         }
1132:       end

[Source]

      # File lib/resolv.rb, line 1164
1164:       def each_resource
1165:         each_answer {|name, ttl, data| yield name, ttl, data}
1166:         each_authority {|name, ttl, data| yield name, ttl, data}
1167:         each_additional {|name, ttl, data| yield name, ttl, data}
1168:       end

[Source]

      # File lib/resolv.rb, line 1170
1170:       def encode
1171:         return MessageEncoder.new {|msg|
1172:           msg.put_pack('nnnnnn',
1173:             @id,
1174:             (@qr & 1) << 15 |
1175:             (@opcode & 15) << 11 |
1176:             (@aa & 1) << 10 |
1177:             (@tc & 1) << 9 |
1178:             (@rd & 1) << 8 |
1179:             (@ra & 1) << 7 |
1180:             (@rcode & 15),
1181:             @question.length,
1182:             @answer.length,
1183:             @authority.length,
1184:             @additional.length)
1185:           @question.each {|q|
1186:             name, typeclass = q
1187:             msg.put_name(name)
1188:             msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue)
1189:           }
1190:           [@answer, @authority, @additional].each {|rr|
1191:             rr.each {|r|
1192:               name, ttl, data = r
1193:               msg.put_name(name)
1194:               msg.put_pack('nnN', data.class::TypeValue, data.class::ClassValue, ttl)
1195:               msg.put_length16 {data.encode_rdata(msg)}
1196:             }
1197:           }
1198:         }.to_s
1199:       end

[Validate]