Add IPv6 support: Use net.SplitHostPort
This commit is contained in:
parent
b9b3e9bcc0
commit
0d03b4dd26
10
irc.go
10
irc.go
@ -428,18 +428,16 @@ func (irc *Connection) Connect(server string) error {
|
|||||||
if len(irc.Server) == 0 {
|
if len(irc.Server) == 0 {
|
||||||
return errors.New("empty 'server'")
|
return errors.New("empty 'server'")
|
||||||
}
|
}
|
||||||
if !strings.HasPrefix("[", irc.Server) && strings.Count(irc.Server, ":") != 1 {
|
|
||||||
return errors.New("wrong number of ':' in address")
|
|
||||||
}
|
|
||||||
if strings.Index(irc.Server, ":") == 0 {
|
if strings.Index(irc.Server, ":") == 0 {
|
||||||
return errors.New("hostname is missing")
|
return errors.New("hostname is missing")
|
||||||
}
|
}
|
||||||
if strings.Index(irc.Server, ":") == len(irc.Server)-1 {
|
if strings.Index(irc.Server, ":") == len(irc.Server)-1 {
|
||||||
return errors.New("port missing")
|
return errors.New("port missing")
|
||||||
}
|
}
|
||||||
// check for valid range
|
_, ports, err := net.SplitHostPort(irc.Server)
|
||||||
substrings := strings.Split(irc.Server, ":")
|
if err != nil {
|
||||||
ports := substrings[len(substrings) - 1]
|
return errors.New("wrong address string")
|
||||||
|
}
|
||||||
port, err := strconv.Atoi(ports)
|
port, err := strconv.Atoi(ports)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("extracting port failed")
|
return errors.New("extracting port failed")
|
||||||
|
Loading…
Reference in New Issue
Block a user