2008-12-18 16:42:39 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2014-09-18 04:17:55 -06:00
|
|
|
"runtime"
|
2009-12-15 16:35:38 -07:00
|
|
|
"testing"
|
2008-12-18 16:42:39 -07:00
|
|
|
)
|
|
|
|
|
2009-01-16 15:16:31 -07:00
|
|
|
type portTest struct {
|
2009-12-15 16:35:38 -07:00
|
|
|
netw string
|
|
|
|
name string
|
|
|
|
port int
|
|
|
|
ok bool
|
2008-12-18 16:42:39 -07:00
|
|
|
}
|
|
|
|
|
2009-11-05 00:16:46 -07:00
|
|
|
var porttests = []portTest{
|
2010-10-22 11:06:33 -06:00
|
|
|
{"tcp", "echo", 7, true},
|
|
|
|
{"tcp", "discard", 9, true},
|
|
|
|
{"tcp", "systat", 11, true},
|
|
|
|
{"tcp", "daytime", 13, true},
|
|
|
|
{"tcp", "chargen", 19, true},
|
|
|
|
{"tcp", "ftp-data", 20, true},
|
|
|
|
{"tcp", "ftp", 21, true},
|
|
|
|
{"tcp", "telnet", 23, true},
|
|
|
|
{"tcp", "smtp", 25, true},
|
|
|
|
{"tcp", "time", 37, true},
|
|
|
|
{"tcp", "domain", 53, true},
|
|
|
|
{"tcp", "finger", 79, true},
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2010-10-22 11:06:33 -06:00
|
|
|
{"udp", "echo", 7, true},
|
|
|
|
{"udp", "tftp", 69, true},
|
|
|
|
{"udp", "bootpc", 68, true},
|
|
|
|
{"udp", "bootps", 67, true},
|
|
|
|
{"udp", "domain", 53, true},
|
|
|
|
{"udp", "ntp", 123, true},
|
|
|
|
{"udp", "snmp", 161, true},
|
|
|
|
{"udp", "syslog", 514, true},
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2010-10-22 11:06:33 -06:00
|
|
|
{"--badnet--", "zzz", 0, false},
|
|
|
|
{"tcp", "--badport--", 0, false},
|
2009-03-03 09:39:12 -07:00
|
|
|
}
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
func TestLookupPort(t *testing.T) {
|
2014-09-18 04:17:55 -06:00
|
|
|
switch runtime.GOOS {
|
|
|
|
case "nacl":
|
|
|
|
t.Skipf("skipping test on %q", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
2008-12-18 16:42:39 -07:00
|
|
|
for i := 0; i < len(porttests); i++ {
|
2009-12-15 16:35:38 -07:00
|
|
|
tt := porttests[i]
|
2009-03-05 16:48:12 -07:00
|
|
|
if port, err := LookupPort(tt.netw, tt.name); port != tt.port || (err == nil) != tt.ok {
|
2013-01-17 23:05:04 -07:00
|
|
|
t.Errorf("LookupPort(%q, %q) = %v, %v; want %v",
|
2009-11-09 13:07:39 -07:00
|
|
|
tt.netw, tt.name, port, err, tt.port)
|
2008-12-18 16:42:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|