From b9b3e9bcc0305127155464c9abf06ae0e1fdbe24 Mon Sep 17 00:00:00 2001 From: Viktor Villainov Date: Wed, 3 Apr 2019 17:50:05 -0400 Subject: [PATCH 1/2] Add IPv6 address support --- irc.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/irc.go b/irc.go index b79fca7..9afb00b 100644 --- a/irc.go +++ b/irc.go @@ -428,7 +428,7 @@ func (irc *Connection) Connect(server string) error { if len(irc.Server) == 0 { return errors.New("empty 'server'") } - if strings.Count(irc.Server, ":") != 1 { + if !strings.HasPrefix("[", irc.Server) && strings.Count(irc.Server, ":") != 1 { return errors.New("wrong number of ':' in address") } if strings.Index(irc.Server, ":") == 0 { @@ -438,7 +438,8 @@ func (irc *Connection) Connect(server string) error { return errors.New("port missing") } // check for valid range - ports := strings.Split(irc.Server, ":")[1] + substrings := strings.Split(irc.Server, ":") + ports := substrings[len(substrings) - 1] port, err := strconv.Atoi(ports) if err != nil { return errors.New("extracting port failed") From 0d03b4dd26f8a13df2d0458d5fd0cc9e1ce42848 Mon Sep 17 00:00:00 2001 From: Viktor Villainov Date: Thu, 4 Apr 2019 10:35:40 -0400 Subject: [PATCH 2/2] Add IPv6 support: Use net.SplitHostPort --- irc.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/irc.go b/irc.go index 9afb00b..de8f6a5 100644 --- a/irc.go +++ b/irc.go @@ -428,18 +428,16 @@ func (irc *Connection) Connect(server string) error { if len(irc.Server) == 0 { 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 { return errors.New("hostname is missing") } if strings.Index(irc.Server, ":") == len(irc.Server)-1 { return errors.New("port missing") } - // check for valid range - substrings := strings.Split(irc.Server, ":") - ports := substrings[len(substrings) - 1] + _, ports, err := net.SplitHostPort(irc.Server) + if err != nil { + return errors.New("wrong address string") + } port, err := strconv.Atoi(ports) if err != nil { return errors.New("extracting port failed")