Skip to content

Commit

Permalink
defines a new error for ip validation
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Apr 16, 2021
1 parent f0335a6 commit 8ce6155
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions transfer_pasv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ type passiveTransferHandler struct {
logger log.Logger // Logger
}

type ipValidationError struct {
error string
}

func (e *ipValidationError) Error() string {
return e.error
}

func (c *clientHandler) getCurrentIP() ([]string, error) {
// Provide our external IP address so the ftp client can connect back to us
ip := c.server.settings.PublicHost
Expand All @@ -58,12 +66,12 @@ func (c *clientHandler) getCurrentIP() ([]string, error) {

parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return nil, fmt.Errorf("invalid passive IP %#v", ip)
return nil, &ipValidationError{error: fmt.Sprintf("invalid passive IP %#v", ip)}
}

parsedIP = parsedIP.To4()
if parsedIP == nil {
return nil, fmt.Errorf("invalid IPv4 passive IP %#v", ip)
return nil, &ipValidationError{error: fmt.Sprintf("invalid IPv4 passive IP %#v", ip)}
}

return strings.Split(parsedIP.String(), "."), nil
Expand Down

0 comments on commit 8ce6155

Please sign in to comment.