Browse Source

Simplify peerIP determination in connectionChecker()

    peerIP = net.ParseIP(addr.IP.String())

can be simplified to just:

    peerIP = addr.IP

but we can also skip the safe cast since we know the net.Addr will always
be net.TCPAddr because we only have TCP listeners.
Jonathon Reinhart 4 years ago
parent
commit
4036213dd5
1 changed files with 2 additions and 8 deletions
  1. 2 8
      main.go

+ 2 - 8
main.go

@@ -17,14 +17,8 @@ import (
 )
 
 func connectionChecker(peer smtpd.Peer) error {
-	var peerIP net.IP
-	if addr, ok := peer.Addr.(*net.TCPAddr); ok {
-		peerIP = net.ParseIP(addr.IP.String())
-	} else {
-		log.WithField("ip", addr.IP).
-			Warn("failed to parse IP")
-		return smtpd.Error{Code: 421, Message: "Denied"}
-	}
+	// This can't panic because we only have TCP listeners
+	peerIP := peer.Addr.(*net.TCPAddr).IP
 
 	nets := strings.Split(*allowedNets, " ")