Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
785fbd94
Commit
785fbd94
authored
Apr 14, 2011
by
Corey Thomasson
Committed by
Andrew Gerrand
Apr 14, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: sort records returned by LookupMX
R=rog, adg, rsc CC=golang-dev
https://golang.org/cl/4388048
parent
eb5e4b85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
+23
-8
src/pkg/net/dnsclient.go
src/pkg/net/dnsclient.go
+23
-8
No files found.
src/pkg/net/dnsclient.go
View file @
785fbd94
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"rand"
"rand"
"sync"
"sync"
"time"
"time"
"sort"
)
)
// DNSError represents a DNS lookup error.
// DNSError represents a DNS lookup error.
...
@@ -410,18 +411,32 @@ type MX struct {
...
@@ -410,18 +411,32 @@ type MX struct {
Pref
uint16
Pref
uint16
}
}
// LookupMX returns the DNS MX records associated with name.
// byPref implements sort.Interface to sort MX records by preference
func
LookupMX
(
name
string
)
(
entries
[]
*
MX
,
err
os
.
Error
)
{
type
byPref
[]
*
MX
var
records
[]
dnsRR
_
,
records
,
err
=
lookup
(
name
,
dnsTypeMX
)
func
(
s
byPref
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
byPref
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
Pref
<
s
[
j
]
.
Pref
}
func
(
s
byPref
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
// LookupMX returns the DNS MX records for the given domain name sorted by preference.
func
LookupMX
(
name
string
)
(
mx
[]
*
MX
,
err
os
.
Error
)
{
_
,
rr
,
err
:=
lookup
(
name
,
dnsTypeMX
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
entries
=
make
([]
*
MX
,
len
(
records
))
mx
=
make
([]
*
MX
,
len
(
rr
))
for
i
:=
range
records
{
for
i
:=
range
rr
{
r
:=
records
[
i
]
.
(
*
dnsRR_MX
)
r
:=
rr
[
i
]
.
(
*
dnsRR_MX
)
entries
[
i
]
=
&
MX
{
r
.
Mx
,
r
.
Pref
}
mx
[
i
]
=
&
MX
{
r
.
Mx
,
r
.
Pref
}
}
// Shuffle the records to match RFC 5321 when sorted
for
i
:=
range
mx
{
j
:=
rand
.
Intn
(
i
+
1
)
mx
[
i
],
mx
[
j
]
=
mx
[
j
],
mx
[
i
]
}
}
sort
.
Sort
(
byPref
(
mx
))
return
return
}
}
...
...
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