2
0
forked from drew/smtprelay

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.
This commit is contained in:
Jonathon Reinhart
2021-03-13 02:38:13 -05:00
parent 2475cadbad
commit 4036213dd5

10
main.go
View File

@@ -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, " ")