[649] | 1 | Namespace System
|
---|
| 2 | Namespace Net
|
---|
| 3 |
|
---|
| 4 | /*
|
---|
| 5 | @brief インターネットホストの情報を表すクラス
|
---|
| 6 | @author OverTaker
|
---|
| 7 | @date 2008/10/19
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | Class IPHostEntry
|
---|
| 11 | Public
|
---|
| 12 | /*
|
---|
| 13 | @brief ホストに関連付けられた端末の情報をリストで取得する
|
---|
| 14 | @return IPEndPointクラスが格納されたリスト
|
---|
| 15 | */
|
---|
| 16 | Abstract Function HostList() As System.Collections.Generic.List<IPEndPoint>
|
---|
| 17 |
|
---|
| 18 | /*
|
---|
| 19 | @brief ホストに関連付けられた端末の情報を1つだけ取得する
|
---|
| 20 | @return ホストの情報を表すIPEndPointクラス
|
---|
| 21 | */
|
---|
| 22 | Abstract Function Host() As IPEndPoint
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | @brief ホストに関連付けられたIPアドレスを取得する
|
---|
| 26 | @return IPAddressクラスが格納されたリスト
|
---|
| 27 | */
|
---|
| 28 | Abstract Function IPAddressList() As System.Collections.Generic.List<IPAddress>
|
---|
| 29 |
|
---|
| 30 | /*
|
---|
| 31 | @brief ホストに付けられている、他の名前を取得する
|
---|
| 32 | @return 名前が格納されたリスト
|
---|
| 33 | */
|
---|
| 34 | Abstract Function Aliases() As System.Collections.Generic.List<String>
|
---|
| 35 |
|
---|
| 36 | /*
|
---|
| 37 | @brief ホスト名を取得する
|
---|
| 38 | @return ホスト名
|
---|
| 39 | */
|
---|
| 40 | Abstract Function HostName() As String
|
---|
| 41 | End Class
|
---|
| 42 |
|
---|
| 43 | Namespace Detail
|
---|
| 44 |
|
---|
| 45 | /*
|
---|
| 46 | @brief IPHostEntryクラスのaddrinfoを使った実装
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 | Class IPHostEntryAddrinfo
|
---|
| 50 | Inherits IPHostEntry
|
---|
| 51 | infos As *addrinfo
|
---|
| 52 | Public
|
---|
| 53 | Sub IPHostEntryAddrinfo(addrinfos As *addrinfo)
|
---|
| 54 | infos = addrinfos
|
---|
| 55 | End Sub
|
---|
| 56 |
|
---|
| 57 | Sub ~IPHostEntryAddrinfo()
|
---|
| 58 | freeaddrinfo(infos As addrinfo)
|
---|
| 59 | End Sub
|
---|
| 60 |
|
---|
| 61 | Override Function HostList() As System.Collections.Generic.List<IPEndPoint>
|
---|
| 62 | Dim list As System.Collections.Generic.List<IPEndPoint>
|
---|
| 63 | Dim info = infos As *addrinfo
|
---|
| 64 | While info <> NULL
|
---|
| 65 | list.Add( IPEndPoint.Create( New SocketAddress(info->ai_addr, info->ai_addrlen) ) )
|
---|
| 66 | info = info->ai_next
|
---|
| 67 | Wend
|
---|
| 68 | Return list
|
---|
| 69 | End Function
|
---|
| 70 |
|
---|
| 71 | Override Function Host() As IPEndPoint
|
---|
| 72 | Return IPEndPoint.Create( New SocketAddress(infos->ai_addr, infos->ai_addrlen) )
|
---|
| 73 | End Function
|
---|
| 74 |
|
---|
| 75 | Override Function IPAddressList() As System.Collections.Generic.List<IPAddress>
|
---|
| 76 | Dim list As System.Collections.Generic.List<IPAddress>
|
---|
| 77 | Dim info = infos As *addrinfo
|
---|
| 78 | While info <> NULL
|
---|
| 79 | list.Add( New IPAddress(info->ai_addr))
|
---|
| 80 | info = info->ai_next
|
---|
| 81 | Wend
|
---|
| 82 | Return list
|
---|
| 83 | End Function
|
---|
| 84 |
|
---|
| 85 | Override Function Aliases() As System.Collections.Generic.List<String>
|
---|
| 86 | Dim list As System.Collections.Generic.List<String>
|
---|
| 87 | Dim info = infos As *addrinfo
|
---|
| 88 | Dim temp[ELM(NI_MAXHOST)] As TCHAR
|
---|
| 89 | While info <> NULL
|
---|
| 90 | If getnameinfo(info->ai_addr As sockaddr, info->ai_addrlen, temp, NI_MAXHOST, NULL, 0, 0) Then
|
---|
| 91 | Throw New ActiveBasic.Windows.WindowsException(WSAGetLastError(), "IPHostEntry.Aliases: Failed to getnameinfo.")
|
---|
| 92 | End If
|
---|
| 93 | list.Add(New String(temp))
|
---|
| 94 | info = info->ai_next
|
---|
| 95 | Wend
|
---|
| 96 | Return list
|
---|
| 97 | End Function
|
---|
| 98 |
|
---|
| 99 | Override Function HostName() As String
|
---|
| 100 | Dim temp[ELM(NI_MAXHOST)] As TCHAR
|
---|
| 101 | If getnameinfo(infos->ai_addr As sockaddr, infos->ai_addrlen, temp, NI_MAXHOST, NULL, 0, 0) Then
|
---|
| 102 | Throw New ActiveBasic.Windows.WindowsException(WSAGetLastError(), "IPHostEntry.HostName: Failed to getnameinfo.")
|
---|
| 103 | End If
|
---|
| 104 | Return New String(temp)
|
---|
| 105 | End Function
|
---|
| 106 | End Class
|
---|
| 107 |
|
---|
| 108 | End Namespace
|
---|
| 109 |
|
---|
| 110 | End Namespace
|
---|
| 111 | End Namespace
|
---|