diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-12 23:40:51 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-12 23:40:51 +0000 |
commit | 46bc1fe2f5a3c7ee4273b99d700fecf1555f64e0 (patch) | |
tree | 0c68629fac9d7c6f103b401c9063ef00ed259f06 /libgo/go/syscall/netlink_linux.go | |
parent | dc15d51eb56c0efe84bf82b02ac2ba9a231ce69b (diff) | |
download | gcc-46bc1fe2f5a3c7ee4273b99d700fecf1555f64e0.tar.gz |
libgo: Update to weekly.2011-11-18.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182266 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/syscall/netlink_linux.go')
-rw-r--r-- | libgo/go/syscall/netlink_linux.go | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/libgo/go/syscall/netlink_linux.go b/libgo/go/syscall/netlink_linux.go index 4ee78d62f25..8683bb3dacb 100644 --- a/libgo/go/syscall/netlink_linux.go +++ b/libgo/go/syscall/netlink_linux.go @@ -63,31 +63,28 @@ func newNetlinkRouteRequest(proto, seq, family int) []byte { // NetlinkRIB returns routing information base, as known as RIB, // which consists of network facility information, states and // parameters. -func NetlinkRIB(proto, family int) ([]byte, int) { +func NetlinkRIB(proto, family int) ([]byte, error) { var ( - s int - e int lsanl SockaddrNetlink - seq int tab []byte ) - s, e = Socket(AF_NETLINK, SOCK_RAW, 0) - if e != 0 { + s, e := Socket(AF_NETLINK, SOCK_RAW, 0) + if e != nil { return nil, e } defer Close(s) lsanl.Family = AF_NETLINK e = Bind(s, &lsanl) - if e != 0 { + if e != nil { return nil, e } - seq++ + seq := 1 wb := newNetlinkRouteRequest(proto, seq, family) e = Sendto(s, wb, 0, &lsanl) - if e != 0 { + if e != nil { return nil, e } @@ -100,7 +97,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) { rb = make([]byte, Getpagesize()) nr, _, e = Recvfrom(s, rb, 0) - if e != 0 { + if e != nil { return nil, e } if nr < NLMSG_HDRLEN { @@ -111,7 +108,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) { msgs, _ := ParseNetlinkMessage(rb) for _, m := range msgs { - if lsa, e = Getsockname(s); e != 0 { + if lsa, e = Getsockname(s); e != nil { return nil, e } switch v := lsa.(type) { @@ -132,7 +129,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) { } done: - return tab, 0 + return tab, nil } // NetlinkMessage represents the netlink message. @@ -143,18 +140,18 @@ type NetlinkMessage struct { // ParseNetlinkMessage parses buf as netlink messages and returns // the slice containing the NetlinkMessage structs. -func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) { +func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, error) { var ( h *NlMsghdr dbuf []byte dlen int - e int + e error msgs []NetlinkMessage ) for len(buf) >= NLMSG_HDRLEN { h, dbuf, dlen, e = netlinkMessageHeaderAndData(buf) - if e != 0 { + if e != nil { break } m := NetlinkMessage{} @@ -167,12 +164,12 @@ func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) { return msgs, e } -func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, int) { +func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, error) { h := (*NlMsghdr)(unsafe.Pointer(&buf[0])) if int(h.Len) < NLMSG_HDRLEN || int(h.Len) > len(buf) { return nil, nil, 0, EINVAL } - return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), 0 + return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), nil } // NetlinkRouteAttr represents the netlink route attribute. @@ -184,13 +181,13 @@ type NetlinkRouteAttr struct { // ParseNetlinkRouteAttr parses msg's payload as netlink route // attributes and returns the slice containing the NetlinkRouteAttr // structs. -func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) { +func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, error) { var ( buf []byte a *RtAttr alen int vbuf []byte - e int + e error attrs []NetlinkRouteAttr ) @@ -207,7 +204,7 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) { for len(buf) >= SizeofRtAttr { a, vbuf, alen, e = netlinkRouteAttrAndValue(buf) - if e != 0 { + if e != nil { break } ra := NetlinkRouteAttr{} @@ -217,13 +214,13 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) { buf = buf[alen:] } - return attrs, 0 + return attrs, nil } -func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, int) { +func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, error) { h := (*RtAttr)(unsafe.Pointer(&buf[0])) if int(h.Len) < SizeofRtAttr || int(h.Len) > len(buf) { return nil, nil, 0, EINVAL } - return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), 0 + return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), nil } |