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 */
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,8 +1324,11 @@ func readRecordToStruct(file *os.File) (Record, error) {
hdr := make([]byte, 1)
n, err := file.Read(hdr)
if err != nil || n < 1 {
if err != io.EOF {
return rec, fmt.Errorf("Unable to read header ID in file: %v", err)
}
return rec, err
}
// DEBUG
/* startOf, _ := file.Seek(0, io.SeekCurrent)

View File

@ -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 (
@ -140,7 +141,9 @@ func main() {
for {
rec, err := readRecordToStruct(f)
if err != nil {
if err != io.EOF {
fmt.Printf("Erreur : %v\n", err)
}
return
}
rec.Print(os.Stdout, ",", 0)