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 1217
1217:       def Message.decode(m)
1218:         o = Message.new(0)
1219:         MessageDecoder.new(m) {|msg|
1220:           id, flag, qdcount, ancount, nscount, arcount =
1221:             msg.get_unpack('nnnnnn')
1222:           o.id = id
1223:           o.qr = (flag >> 15) & 1
1224:           o.opcode = (flag >> 11) & 15
1225:           o.aa = (flag >> 10) & 1
1226:           o.tc = (flag >> 9) & 1
1227:           o.rd = (flag >> 8) & 1
1228:           o.ra = (flag >> 7) & 1
1229:           o.rcode = flag & 15
1230:           (1..qdcount).each {
1231:             name, typeclass = msg.get_question
1232:             o.add_question(name, typeclass)
1233:           }
1234:           (1..ancount).each {
1235:             name, ttl, data = msg.get_rr
1236:             o.add_answer(name, ttl, data)
1237:           }
1238:           (1..nscount).each {
1239:             name, ttl, data = msg.get_rr
1240:             o.add_authority(name, ttl, data)
1241:           }
1242:           (1..arcount).each {
1243:             name, ttl, data = msg.get_rr
1244:             o.add_additional(name, ttl, data)
1245:           }
1246:         }
1247:         return o
1248:       end

[Source]

      # File lib/resolv.rb, line 1045
1045:       def initialize(id = (@@identifier += 1) & 0xffff)
1046:         @id = id
1047:         @qr = 0
1048:         @opcode = 0
1049:         @aa = 0
1050:         @tc = 0
1051:         @rd = 0 # recursion desired
1052:         @ra = 0 # recursion available
1053:         @rcode = 0
1054:         @question = []
1055:         @answer = []
1056:         @authority = []
1057:         @additional = []
1058:       end

Public Instance methods

[Source]

      # File lib/resolv.rb, line 1063
1063:       def ==(other)
1064:         return @id == other.id &&
1065:                @qr == other.qr &&
1066:                @opcode == other.opcode &&
1067:                @aa == other.aa &&
1068:                @tc == other.tc &&
1069:                @rd == other.rd &&
1070:                @ra == other.ra &&
1071:                @rcode == other.rcode &&
1072:                @question == other.question &&
1073:                @answer == other.answer &&
1074:                @authority == other.authority &&
1075:                @additional == other.additional
1076:       end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

      # File lib/resolv.rb, line 1112
1112:       def each_additional
1113:         @additional.each {|name, ttl, data|
1114:           yield name, ttl, data
1115:         }
1116:       end

[Source]

      # File lib/resolv.rb, line 1092
1092:       def each_answer
1093:         @answer.each {|name, ttl, data|
1094:           yield name, ttl, data
1095:         }
1096:       end

[Source]

      # File lib/resolv.rb, line 1102
1102:       def each_authority
1103:         @authority.each {|name, ttl, data|
1104:           yield name, ttl, data
1105:         }
1106:       end

[Source]

      # File lib/resolv.rb, line 1082
1082:       def each_question
1083:         @question.each {|name, typeclass|
1084:           yield name, typeclass
1085:         }
1086:       end

[Source]

      # File lib/resolv.rb, line 1118
1118:       def each_resource
1119:         each_answer {|name, ttl, data| yield name, ttl, data}
1120:         each_authority {|name, ttl, data| yield name, ttl, data}
1121:         each_additional {|name, ttl, data| yield name, ttl, data}
1122:       end

[Source]

      # File lib/resolv.rb, line 1124
1124:       def encode
1125:         return MessageEncoder.new {|msg|
1126:           msg.put_pack('nnnnnn',
1127:             @id,
1128:             (@qr & 1) << 15 |
1129:             (@opcode & 15) << 11 |
1130:             (@aa & 1) << 10 |
1131:             (@tc & 1) << 9 |
1132:             (@rd & 1) << 8 |
1133:             (@ra & 1) << 7 |
1134:             (@rcode & 15),
1135:             @question.length,
1136:             @answer.length,
1137:             @authority.length,
1138:             @additional.length)
1139:           @question.each {|q|
1140:             name, typeclass = q
1141:             msg.put_name(name)
1142:             msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue)
1143:           }
1144:           [@answer, @authority, @additional].each {|rr|
1145:             rr.each {|r|
1146:               name, ttl, data = r
1147:               msg.put_name(name)
1148:               msg.put_pack('nnN', data.class::TypeValue, data.class::ClassValue, ttl)
1149:               msg.put_length16 {data.encode_rdata(msg)}
1150:             }
1151:           }
1152:         }.to_s
1153:       end

[Validate]