lib/net/dns/names.rb in net-dns-0.9.0 vs lib/net/dns/names.rb in net-dns-0.20.0
- old
+ new
@@ -10,11 +10,11 @@
end
INT16SZ = 2
# Expand a compressed name in a DNS Packet object. Please
- # see RFC1025 for an explanation of how the compression
+ # see RFC1035 for an explanation of how the compression
# in DNS packets works, how may it be useful and how should
# be handled.
#
# This method accept two parameters: a raw packet data and an
# offset, which indicates the point in the packet in which the
@@ -22,21 +22,21 @@
#
def dn_expand(packet, offset)
name = ""
packetlen = packet.size
loop do
- raise ExpandError, "Offset is greater than packet lenght!" if packetlen < (offset + 1)
+ raise ExpandError, "Offset is greater than packet length!" if packetlen < (offset + 1)
- len = packet.unpack("@#{offset} C")[0]
+ len = packet.unpack1("@#{offset} C")
if len == 0
offset += 1
break
elsif (len & 0xC0) == 0xC0
raise ExpandError, "Packet ended before offset expand" if packetlen < (offset + INT16SZ)
- ptr = packet.unpack("@#{offset} n")[0]
+ ptr = packet.unpack1("@#{offset} n")
ptr &= 0x3FFF
name2 = dn_expand(packet, ptr)[0]
raise ExpandError, "Packet is malformed!" if name2.nil?
name += name2
@@ -96,25 +96,23 @@
ptr = 0xC000 | compnames[entry]
str += [ptr].pack("n")
offset += INT16SZ
break
else
- len = entry.unpack("C")[0]
+ len = entry.unpack1("C")
elem = entry[1..len]
str += [len, elem].pack("Ca*")
names.update(entry.to_s => offset)
offset += len
end
end
[str, offset, names]
end
def valid?(name)
- if name =~ /^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i
- name
- else
- raise ArgumentError, "Invalid FQDN: #{name}"
- end
+ raise ArgumentError, "Invalid FQDN: #{name}" unless name =~ /^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i
+
+ name
end
end
end
end