forked from vishvananda/go-netlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
47 lines (38 loc) · 1.09 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package netlink
/*
Copyright (c) 2011, Abneptis LLC. All rights reserved.
Original Author: James D. Nurmi <[email protected]>
See LICENSE for details
*/
import "fmt"
import (
"encoding/binary"
"errors"
"syscall"
)
// Unlike other headers, errors MAY be longer than the minimum length.
const ERROR_LENGTH = HEADER_LENGTH + 4
// Represents a netlink Error message.
type Error [ERROR_LENGTH]byte
// The error code (-errno) of the netlink message.
// 0 is used for netlink ACK's.
func (self Error) Code() int32 {
return int32(binary.LittleEndian.Uint32(self[0:4]))
}
// Marshals an error to the wire.
func (self Error) MarshalNetlink() (out []byte, err error) {
out = Padded(self[0:ERROR_LENGTH])
return
}
// Unmarshals an error from a netlink message.
func (self *Error) UnmarshalNetlink(in []byte) (err error) {
if len(in) < ERROR_LENGTH {
return errors.New(fmt.Sprintf("Invalid netlink error length: %d", len(in)))
}
copy(self[0:ERROR_LENGTH], in)
return
}
// Implements os.Error by using the syscall Errno error
func (self Error) Error() string {
return syscall.Errno(-self.Code()).Error()
}