From 0579cfea1d688707461add0be38aa2c12bb6bcae Mon Sep 17 00:00:00 2001 From: yo Date: Tue, 4 Jan 2022 11:03:58 +0100 Subject: [PATCH] Version bump, fix EOF error, move PrintIPv4FromInt --- libbsm.go | 15 +++++++++------ main.go | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libbsm.go b/libbsm.go index 53cf84e..9e5510d 100644 --- a/libbsm.go +++ b/libbsm.go @@ -282,6 +282,11 @@ type Text struct { /* Utilities */ +func PrintIpv4FromInt(ipv4int uint32) string { + return fmt.Sprintf("%d.%d.%d.%d", ipv4int & 0xFF000000 >> 24, ipv4int & 0x00FF0000 >> 16, + ipv4int & 0x0000FF00 >> 8, ipv4int & 0x000000FF) +} + func PrintIpv6FromInt(ipv6int [4]uint32) string { //return fmt.Sprintf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", return fmt.Sprintf("%x:%x:%x:%x:%x:%x:%x:%x", @@ -602,11 +607,6 @@ func (s *Subject32) LoadFromBinary(file *os.File) error { return nil } -func PrintIpv4FromInt(ipv4int uint32) string { - return fmt.Sprintf("%d.%d.%d.%d", ipv4int & 0xFF000000 >> 24, ipv4int & 0x00FF0000 >> 16, - ipv4int & 0x0000FF00 >> 8, ipv4int & 0x000000FF) -} - func (s *Subject32) Print(file *os.File, delimiter string, flags int) { fmt.Fprintf(file, "subject%s%v%s%v%s%v%s%v%s%v%s%v%s%v%s%v%s%s", delimiter, s.Auid, delimiter, s.Euid, delimiter, s.Egid, delimiter, s.Ruid, delimiter, s.Rgid, delimiter, s.Sid, delimiter, s.Tid.Port, delimiter, s.Tid.IpVers, @@ -1324,7 +1324,10 @@ func readRecordToStruct(file *os.File) (Record, error) { hdr := make([]byte, 1) n, err := file.Read(hdr) if err != nil || n < 1 { - return rec, fmt.Errorf("Unable to read header ID in file: %v", err) + if err != io.EOF { + return rec, fmt.Errorf("Unable to read header ID in file: %v", err) + } + return rec, err } // DEBUG diff --git a/main.go b/main.go index 5b768a0..79ba1c8 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import "C" import "unsafe" import ( + "io" "os" "fmt" // "encoding/hex" @@ -23,7 +24,7 @@ import ( ) const ( - version = "0.001" + version = "0.01" ) var ( @@ -139,8 +140,10 @@ func main() { //for i := 0 ; i < 20 ; i++ { for { rec, err := readRecordToStruct(f) - if err != nil { - fmt.Printf("Erreur : %v\n", err) + if err != nil { + if err != io.EOF { + fmt.Printf("Erreur : %v\n", err) + } return } rec.Print(os.Stdout, ",", 0)