Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
48bb3e8f
Commit
48bb3e8f
authored
Oct 18, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: allow LookupSRV on non-standard DNS names
R=golang-dev, bradfitz CC=golang-dev
https://golang.org/cl/5313043
parent
835dcb71
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
11 deletions
+52
-11
lookup_plan9.go
src/pkg/net/lookup_plan9.go
+14
-5
lookup_test.go
src/pkg/net/lookup_test.go
+9
-0
lookup_unix.go
src/pkg/net/lookup_unix.go
+14
-5
lookup_windows.go
src/pkg/net/lookup_windows.go
+15
-1
No files found.
src/pkg/net/lookup_plan9.go
View file @
48bb3e8f
...
...
@@ -157,12 +157,21 @@ func LookupCNAME(name string) (cname string, err os.Error) {
}
// LookupSRV tries to resolve an SRV query of the given service,
// protocol, and domain name, as specified in RFC 2782. In most cases
// the proto argument can be the same as the corresponding
// Addr.Network(). The returned records are sorted by priority
// and randomized by weight within a priority.
// protocol, and domain name. The proto is "tcp" or "udp".
// The returned records are sorted by priority and randomized
// by weight within a priority.
//
// LookupSRV constructs the DNS name to look up following RFC 2782.
// That is, it looks up _service._proto.name. To accommodate services
// publishing SRV records under non-standard names, if both service
// and proto are empty strings, LookupSRV looks up name directly.
func
LookupSRV
(
service
,
proto
,
name
string
)
(
cname
string
,
addrs
[]
*
SRV
,
err
os
.
Error
)
{
target
:=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
var
target
string
if
service
==
""
&&
proto
==
""
{
target
=
name
}
else
{
target
=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
}
lines
,
err
:=
queryDNS
(
target
,
"srv"
)
if
err
!=
nil
{
return
...
...
src/pkg/net/lookup_test.go
View file @
48bb3e8f
...
...
@@ -26,6 +26,15 @@ func TestGoogleSRV(t *testing.T) {
if
len
(
addrs
)
==
0
{
t
.
Errorf
(
"no results"
)
}
// Non-standard back door.
_
,
addrs
,
err
=
LookupSRV
(
""
,
""
,
"_xmpp-server._tcp.google.com"
)
if
err
!=
nil
{
t
.
Errorf
(
"back door failed: %s"
,
err
)
}
if
len
(
addrs
)
==
0
{
t
.
Errorf
(
"back door no results"
)
}
}
func
TestGmailMX
(
t
*
testing
.
T
)
{
...
...
src/pkg/net/lookup_unix.go
View file @
48bb3e8f
...
...
@@ -94,12 +94,21 @@ func LookupCNAME(name string) (cname string, err os.Error) {
}
// LookupSRV tries to resolve an SRV query of the given service,
// protocol, and domain name, as specified in RFC 2782. In most cases
// the proto argument can be the same as the corresponding
// Addr.Network(). The returned records are sorted by priority
// and randomized by weight within a priority.
// protocol, and domain name. The proto is "tcp" or "udp".
// The returned records are sorted by priority and randomized
// by weight within a priority.
//
// LookupSRV constructs the DNS name to look up following RFC 2782.
// That is, it looks up _service._proto.name. To accommodate services
// publishing SRV records under non-standard names, if both service
// and proto are empty strings, LookupSRV looks up name directly.
func
LookupSRV
(
service
,
proto
,
name
string
)
(
cname
string
,
addrs
[]
*
SRV
,
err
os
.
Error
)
{
target
:=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
var
target
string
if
service
==
""
&&
proto
==
""
{
target
=
name
}
else
{
target
=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
}
var
records
[]
dnsRR
cname
,
records
,
err
=
lookup
(
target
,
dnsTypeSRV
)
if
err
!=
nil
{
...
...
src/pkg/net/lookup_windows.go
View file @
48bb3e8f
...
...
@@ -91,9 +91,23 @@ func LookupCNAME(name string) (cname string, err os.Error) {
return
}
// LookupSRV tries to resolve an SRV query of the given service,
// protocol, and domain name. The proto is "tcp" or "udp".
// The returned records are sorted by priority and randomized
// by weight within a priority.
//
// LookupSRV constructs the DNS name to look up following RFC 2782.
// That is, it looks up _service._proto.name. To accommodate services
// publishing SRV records under non-standard names, if both service
// and proto are empty strings, LookupSRV looks up name directly.
func
LookupSRV
(
service
,
proto
,
name
string
)
(
cname
string
,
addrs
[]
*
SRV
,
err
os
.
Error
)
{
var
target
string
if
service
==
""
&&
proto
==
""
{
target
=
name
}
else
{
target
=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
}
var
r
*
syscall
.
DNSRecord
target
:=
"_"
+
service
+
"._"
+
proto
+
"."
+
name
e
:=
syscall
.
DnsQuery
(
target
,
syscall
.
DNS_TYPE_SRV
,
0
,
nil
,
&
r
,
nil
)
if
int
(
e
)
!=
0
{
return
""
,
nil
,
os
.
NewSyscallError
(
"LookupSRV"
,
int
(
e
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment