From 40c6572a81472a3760c3a53c8411d7774f67c276 Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Thu, 9 Dec 2021 15:21:54 -0600 Subject: [PATCH] Moved setting sys params to sysdetect Cleans up the main function --- src/rhosts.go | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/rhosts.go b/src/rhosts.go index 9d7d5e0..7b139e5 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -23,40 +23,40 @@ package main import ( "runtime" - "fmt" "os" "bufio" "log" ) func main() { - // Detect which OS is running - //tmpdir := "" - //hostsloc := "" - cfgloc := "" - switch runtime.GOOS { - case "windows": - fmt.Println("Windows is currently unsupported") - os.Exit(1) - //tmpdir := "C:\\tmp" - //hostsloc := "C:\\Windows\\System32\\drivers\\etc\\hosts" - case "linux": - //tmpdir = "/tmp/" - //hostsloc = "/etc/hosts" - cfgloc ="/etc/rhosts/rhosts.cfg" - case "ios": - fmt.Println("ios") - os.Exit(1) - default: - log.Print(runtime.GOOS," is not supported") - os.Exit(1) - } + tmpdir := "" + hostsloc := "" + cfgloc := "" + + sysdetect (&tmpdir, &hostsloc, &cfgloc) - // Parse Config cfgparse(cfgloc) } +func sysdetect (tmpdir, hostsloc, cfgloc *string) { + // Detect OS and set params + switch runtime.GOOS { + case "windows": + log.Fatal("Windows is not supported") + *tmpdir = "C:\\tmp" + *hostsloc = "C:\\Windows\\System32\\drivers\\etc\\hosts" + case "linux": + *tmpdir = "/tmp/" + *hostsloc = "/etc/hosts" + *cfgloc ="/etc/rhosts/rhosts.cfg" + case "ios": + log.Fatal("IOS is not supported") + default: + log.Fatal(runtime.GOOS," is not supported") + } +} + func cfgparse (cfgloc string){ log.Print("Opening: ", cfgloc) file, err := os.Open(cfgloc)