mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 1 | // Copyright 2018-present Open Networking Foundation |
Dinesh Belwalkar | 6c0bc75 | 2020-04-24 23:47:53 +0000 | [diff] [blame] | 2 | // Copyright 2018-present Edgecore Networks Corporation |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | package main |
| 17 | |
| 18 | import "net" |
| 19 | import "fmt" |
| 20 | import "bufio" |
| 21 | import "os" |
| 22 | import "strings" |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame] | 23 | import "log" |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 24 | |
| 25 | func main() { |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame] | 26 | if len(os.Args) <= 1 { |
| 27 | log.Printf("Syntax: ./dm <arguments>") |
| 28 | os.Exit(-1) |
| 29 | } |
| 30 | |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 31 | // connect to this socket |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 32 | cmdstr := strings.Join(os.Args[1:], " ") |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame] | 33 | conn, err := net.Dial("tcp", "127.0.0.1:9999") |
| 34 | if err != nil { |
| 35 | log.Printf("Error opening connection: %v", err) |
| 36 | os.Exit(-1) |
| 37 | } |
| 38 | |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 39 | // send to socket |
Dinesh Belwalkar | a6ba07d | 2020-01-10 23:22:34 +0000 | [diff] [blame] | 40 | fmt.Fprintf(conn, cmdstr+"\n") |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 41 | |
| 42 | // listen for reply |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame] | 43 | message, err := bufio.NewReader(conn).ReadString(';') |
| 44 | if err != nil { |
| 45 | log.Printf("Error reading result: %v", err) |
| 46 | os.Exit(-1) |
| 47 | } |
| 48 | |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 49 | message = strings.TrimSuffix(message, ";") |
| 50 | fmt.Print(message) |
| 51 | } |