]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/DNSServiceBrowser.VB/DNSServiceBrowser.vb
mDNSResponder-258.13.tar.gz
[apple/mdnsresponder.git] / Clients / DNSServiceBrowser.VB / DNSServiceBrowser.vb
1 '
2 ' Copyright (c) 2010 Apple Inc. All rights reserved.
3 '
4 ' Licensed under the Apache License, Version 2.0 (the "License");
5 ' you may not use this file except in compliance with the License.
6 ' You may obtain a copy of the License at
7 '
8 ' http://www.apache.org/licenses/LICENSE-2.0
9 '
10 ' Unless required by applicable law or agreed to in writing, software
11 ' distributed under the License is distributed on an "AS IS" BASIS,
12 ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ' See the License for the specific language governing permissions and
14 ' limitations under the License.
15 '
16
17 Public Class DNSServiceBrowser
18 Public WithEvents MyEventManager As New Bonjour.DNSSDEventManager
19
20 Private m_service As New Bonjour.DNSSDService
21 Private m_browser As Bonjour.DNSSDService
22 Private m_resolver As Bonjour.DNSSDService
23
24 Public Sub New()
25 MyBase.New()
26
27 'This call is required by the Windows Form Designer.
28 InitializeComponent()
29
30 ComboBox1.SelectedIndex = 0
31 End Sub
32 Public Sub MyEventManager_ServiceFound(ByVal browser As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal serviceName As String, ByVal regtype As String, ByVal domain As String) Handles MyEventManager.ServiceFound
33 Dim browseData As New BrowseData
34 browseData.ServiceName = serviceName
35 browseData.RegType = regtype
36 browseData.Domain = domain
37 ServiceNames.Items.Add(browseData)
38 End Sub
39 Public Sub MyEventManager_ServiceLost(ByVal browser As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal serviceName As String, ByVal regtype As String, ByVal domain As String) Handles MyEventManager.ServiceLost
40 ServiceNames.Items.Remove(serviceName)
41 End Sub
42 Public Sub MyEventManager_ServiceResolved(ByVal resolver As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal fullname As String, ByVal hostname As String, ByVal port As UShort, ByVal record As Bonjour.TXTRecord) Handles MyEventManager.ServiceResolved
43 m_resolver.Stop()
44 m_resolver = Nothing
45 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
46 NameField.Text = browseData.ServiceName
47 TypeField.Text = browseData.RegType
48 DomainField.Text = browseData.Domain
49 HostField.Text = hostname
50 PortField.Text = port
51
52 If record IsNot Nothing Then
53 For i As UInteger = 0 To record.GetCount() - 1
54 Dim key As String = record.GetKeyAtIndex(i)
55 If key.Length() > 0 Then
56 TextRecord.Items.Add(key + "=" + System.Text.Encoding.ASCII.GetString(record.GetValueAtIndex(i)))
57 End If
58 Next i
59 End If
60 End Sub
61 Private Sub ClearServiceInfo()
62 TextRecord.Items.Clear()
63 NameField.Text = ""
64 TypeField.Text = ""
65 DomainField.Text = ""
66 HostField.Text = ""
67 PortField.Text = ""
68 End Sub
69 Private Sub ServiceNames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServiceNames.SelectedIndexChanged
70 If m_resolver IsNot Nothing Then
71 m_resolver.Stop()
72 End If
73 Me.ClearServiceInfo()
74 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
75 m_resolver = m_service.Resolve(0, 0, browseData.ServiceName, browseData.RegType, browseData.Domain, MyEventManager)
76 End Sub
77 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
78 If m_browser IsNot Nothing Then
79 m_browser.Stop()
80 End If
81
82 ServiceNames.Items.Clear()
83 Me.ClearServiceInfo()
84 m_browser = m_service.Browse(0, 0, ComboBox1.Items.Item(ComboBox1.SelectedIndex), "", MyEventManager)
85 End Sub
86
87 Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRecord.SelectedIndexChanged
88
89 End Sub
90 End Class
91 Public Class BrowseData
92 Private m_serviceName As String
93 Private m_regType As String
94 Private m_domain As String
95
96 Property ServiceName() As String
97 Get
98 Return m_serviceName
99 End Get
100 Set(ByVal Value As String)
101 m_serviceName = Value
102 End Set
103 End Property
104
105 Property RegType() As String
106 Get
107 Return m_regType
108 End Get
109 Set(ByVal Value As String)
110 m_regType = Value
111 End Set
112 End Property
113
114 Property Domain() As String
115 Get
116 Return m_domain
117 End Get
118 Set(ByVal Value As String)
119 m_domain = Value
120 End Set
121 End Property
122
123 Public Overrides Function ToString() As String
124 Return m_serviceName
125 End Function
126
127 End Class