pingpong: check for missing remote port when validating flags
While there, consolidate the validation of flags.
@@ -94,12 +94,6 @@ func main() {
initNetwork()
switch *mode {
case ModeClient:
- if remote.Host == nil {
- LogFatal("Missing remote address")
- }
- if remote.Host.L4.Port() == 0 {
- LogFatal("Invalid remote port", "remote port", remote.Host.L4.Port())
- }
c := newClient()
setSignalHandler(c)
c.run()
@@ -113,9 +107,17 @@ func validateFlags() {
if *mode != ModeClient && *mode != ModeServer {
LogFatal("Unknown mode, must be either '" + ModeClient + "' or '" + ModeServer + "'")
}
- if *mode == ModeClient && remote.Host == nil {
+ if *mode == ModeClient {
+ if remote.Host == nil {
LogFatal("Missing remote address")
}
+ if remote.Host.L4 == nil {
+ LogFatal("Missing remote port")
+ }
+ if remote.Host.L4.Port() == 0 {
+ LogFatal("Invalid remote port", "remote port", remote.Host.L4.Port())
+ }
+ }
if local.Host == nil {
LogFatal("Missing local address")
}
