@@ -31,19 +31,30 @@ def initialize(client)
31
31
self . client = client
32
32
end
33
33
34
- def resolve_host ( hostname , family = AF_INET )
34
+ def resolve_host ( hostname , family = AF_INET )
35
35
request = Packet . create_request ( COMMAND_ID_STDAPI_NET_RESOLVE_HOST )
36
36
request . add_tlv ( TLV_TYPE_HOST_NAME , hostname )
37
37
request . add_tlv ( TLV_TYPE_ADDR_TYPE , family )
38
38
39
39
response = client . send_request ( request )
40
40
41
- raw = response . get_tlv_value ( TLV_TYPE_IP )
41
+ ips = [ ]
42
+ if response . has_tlv? ( TLV_TYPE_RESOLVE_HOST_ENTRY )
43
+ response . each ( TLV_TYPE_RESOLVE_HOST_ENTRY ) do |tlv |
44
+ tlv . each ( TLV_TYPE_IP ) do |ip |
45
+ ips << raw_to_host_ip_pair ( hostname , ip . value ) [ :ip ]
46
+ end
47
+ end
48
+ elsif response . has_tlv? ( TLV_TYPE_IP )
49
+ ip = response . get_tlv_value ( TLV_TYPE_IP )
50
+ ips << raw_to_host_ip_pair ( hostname , ip ) [ :ip ]
51
+ end
42
52
43
- return raw_to_host_ip_pair ( hostname , raw )
53
+ { hostname : hostname , ip : ips . first , ips : ips }
44
54
end
45
55
46
- def resolve_hosts ( hostnames , family = AF_INET )
56
+ def resolve_hosts ( hostnames , family = AF_INET )
57
+ result = [ ]
47
58
request = Packet . create_request ( COMMAND_ID_STDAPI_NET_RESOLVE_HOSTS )
48
59
request . add_tlv ( TLV_TYPE_ADDR_TYPE , family )
49
60
@@ -53,21 +64,22 @@ def resolve_hosts(hostnames, family=AF_INET)
53
64
54
65
response = client . send_request ( request )
55
66
56
- hosts = [ ]
57
- raws = [ ]
58
-
59
- response . each ( TLV_TYPE_IP ) do |raw |
60
- raws << raw
61
- end
62
-
63
- 0 . upto ( hostnames . length - 1 ) do |i |
64
- raw = raws [ i ]
65
- host = hostnames [ i ]
66
-
67
- hosts << raw_to_host_ip_pair ( host , raw &.value )
67
+ if response . has_tlv? ( TLV_TYPE_RESOLVE_HOST_ENTRY )
68
+ response . each_with_index ( TLV_TYPE_RESOLVE_HOST_ENTRY ) do |tlv , index |
69
+ ips = [ ]
70
+ tlv . each ( TLV_TYPE_IP ) do |ip |
71
+ ips << raw_to_host_ip_pair ( hostnames [ index ] , ip . value ) [ :ip ]
72
+ end
73
+ result << { hostname : hostnames [ index ] , ip : ips . first , ips : ips }
74
+ end
75
+ elsif response . has_tlv? ( TLV_TYPE_IP )
76
+ response . each_with_index ( TLV_TYPE_IP ) do |tlv , index |
77
+ ips = [ raw_to_host_ip_pair ( hostnames [ index ] , tlv . value ) [ :ip ] ]
78
+ result << { hostname : hostnames [ index ] , ip : ips . first , ips : ips }
79
+ end
68
80
end
69
81
70
- return hosts
82
+ result
71
83
end
72
84
73
85
def raw_to_host_ip_pair ( host , raw )
0 commit comments