Version bump, fix EOF error, move PrintIPv4FromInt

This commit is contained in:
yo 2022-01-04 11:03:58 +01:00
parent 501b371936
commit 0579cfea1d
2 changed files with 15 additions and 9 deletions

View File

@ -282,6 +282,11 @@ type Text struct {
/* Utilities */ /* 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 { func PrintIpv6FromInt(ipv6int [4]uint32) string {
//return fmt.Sprintf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", //return fmt.Sprintf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
return fmt.Sprintf("%x:%x:%x:%x:%x:%x:%x:%x", 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 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) { 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, 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, 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) hdr := make([]byte, 1)
n, err := file.Read(hdr) n, err := file.Read(hdr)
if err != nil || n < 1 { 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 // DEBUG

View File

@ -16,6 +16,7 @@ import "C"
import "unsafe" import "unsafe"
import ( import (
"io"
"os" "os"
"fmt" "fmt"
// "encoding/hex" // "encoding/hex"
@ -23,7 +24,7 @@ import (
) )
const ( const (
version = "0.001" version = "0.01"
) )
var ( var (
@ -139,8 +140,10 @@ func main() {
//for i := 0 ; i < 20 ; i++ { //for i := 0 ; i < 20 ; i++ {
for { for {
rec, err := readRecordToStruct(f) rec, err := readRecordToStruct(f)
if err != nil { if err != nil {
fmt.Printf("Erreur : %v\n", err) if err != io.EOF {
fmt.Printf("Erreur : %v\n", err)
}
return return
} }
rec.Print(os.Stdout, ",", 0) rec.Print(os.Stdout, ",", 0)