| 1 | // Copyright 2017-2018 DigitalOcean. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Command lssmbios accesses and displays SMBIOS data. |
| 16 | package main |
| 17 | |
| 18 | import ( |
| 19 | "fmt" |
| 20 | "log" |
| 21 | |
| 22 | "github.com/digitalocean/go-smbios/smbios" |
| 23 | ) |
| 24 | |
| 25 | func main() { |
| 26 | // Find SMBIOS data in operating system-specific location. |
| 27 | rc, ep, err := smbios.Stream() |
| 28 | if err != nil { |
| 29 | log.Fatalf("failed to open stream: %v", err) |
| 30 | } |
| 31 | // Be sure to close the stream! |
| 32 | defer rc.Close() |
| 33 | |
| 34 | // Decode SMBIOS structures from the stream. |
| 35 | d := smbios.NewDecoder(rc) |
| 36 | ss, err := d.Decode() |
| 37 | if err != nil { |
| 38 | log.Fatalf("failed to decode structures: %v", err) |
| 39 | } |
| 40 | |
| 41 | // Determine SMBIOS version and table location from entry point. |
| 42 | major, minor, rev := ep.Version() |
| 43 | addr, size := ep.Table() |
| 44 | |
| 45 | fmt.Printf("SMBIOS %d.%d.%d - table: address: %#x, size: %d\n", |
| 46 | major, minor, rev, addr, size) |
| 47 | |
| 48 | for _, s := range ss { |
| 49 | fmt.Println(s) |
| 50 | } |
| 51 | } |