Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/net/dns/rr/aaaa.rb
Views: 11784
# -*- coding: binary -*-1##2#3# Net::DNS::RR::AAAA4#5# $id$6#7##89require 'ipaddr'1011module Net12module DNS1314class RR1516#17# RR type AAAA18#19class AAAA < RR20attr_reader :address2122# Assign to the RR::AAAA object a new IPv6 address, which can be in the23# form of a string or an IPAddr object24#25# a.address = "::1"26# a.address = IPAddr.new("::1")27#28def address=(addr)29@address = check_address addr30build_pack31end # address=3233private3435def check_address(addr)36address = ""37case addr38when String39address = IPAddr.new addr40when IPAddr41address = addr42else43raise RRArgumentError, "Unknown address type: #{addr.inspect}"44end45raise RRArgumentError, "Must specify an IPv6 address" unless address.ipv6?46address47rescue ArgumentError48raise RRArgumentError, "Invalid address #{addr.inspect}"49end5051def build_pack52@address_pack = @address.hton53@rdlength = @address_pack.size54end5556def set_type57@type = Net::DNS::RR::Types.new("AAAA")58end5960def get_data61@address_pack62end6364def get_inspect65"#@address"66end6768def subclass_new_from_hash(args)69if args.has_key? :address70@address = check_address args[:address]71else72raise RRArgumentError, ":address field is mandatory but missing"73end74end7576def subclass_new_from_string(str)77@address = check_address(str)78end7980def subclass_new_from_binary(data,offset)81arr = data.unpack("@#{offset} n8")82@address = IPAddr.new sprintf("%x:%x:%x:%x:%x:%x:%x:%x",*arr)83return offset + 1684end8586end # class AAAA8788end # class RR89end # module DNS90end # module Net919293