Skip to content

Commit 1547a7c

Browse files
committed
netlink: type name NetlinkSocket -> Socket
1 parent 05025e1 commit 1547a7c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Diff for: connector/connector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type ConnectorMsg struct {
6060
}
6161

6262
type Connector struct {
63-
nls *netlink.NetlinkSocket
63+
nls *netlink.Socket
6464
id CbId
6565
seq uint32
6666
}

Diff for: netlink/netlink.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ type netlinkMsg struct {
3838
data []byte
3939
}
4040

41-
// NetlinkSocket is a Linux Netlink socket
42-
type NetlinkSocket struct {
41+
// Socket is a Linux Netlink socket
42+
type Socket struct {
4343
socketFd int
4444
lsa *syscall.SockaddrNetlink
4545
seq uint32
4646
}
4747

4848
// Open creates and binds a new Netlink socket
49-
func Open() (*NetlinkSocket, error) {
49+
func Open() (*Socket, error) {
5050
// TODO remove Connector hardcode
5151
socketFd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_DGRAM, syscall.NETLINK_CONNECTOR)
5252
if err != nil {
@@ -57,24 +57,24 @@ func Open() (*NetlinkSocket, error) {
5757
lsa.Family = syscall.AF_NETLINK
5858
lsa.Pid = 0
5959
err = syscall.Bind(socketFd, lsa)
60-
return &NetlinkSocket{socketFd, lsa, 0xaffe}, err
60+
return &Socket{socketFd, lsa, 0xaffe}, err
6161
}
6262

6363
// Close this Socket's connection
64-
func (nls *NetlinkSocket) Close() {
65-
syscall.Close(nls.socketFd)
64+
func (s *Socket) Close() {
65+
syscall.Close(s.socketFd)
6666
}
6767

6868
// Send the given data through this Netlink connection
69-
func (nls *NetlinkSocket) Send(data []byte) error {
69+
func (s *Socket) Send(data []byte) error {
7070
// TODO remove magic numbers
71-
msg := &netlinkMsg{uint32(syscall.NLMSG_HDRLEN + len(data)), syscall.NLMSG_DONE, 0, nls.seq, uint32(os.Getpid()), data}
72-
nls.seq++
71+
msg := &netlinkMsg{uint32(syscall.NLMSG_HDRLEN + len(data)), syscall.NLMSG_DONE, 0, s.seq, uint32(os.Getpid()), data}
72+
s.seq++
7373

7474
log.Printf("\t\t\tNL SEND: %v", msg)
7575

7676
// TODO remove magic number
77-
err := syscall.Sendto(nls.socketFd, msg.Bytes(), 0, nls.lsa)
77+
err := syscall.Sendto(s.socketFd, msg.Bytes(), 0, s.lsa)
7878
return err
7979
}
8080

@@ -107,10 +107,10 @@ func (msg *netlinkMsg) String() string {
107107
}
108108

109109
// Receive data from this Netlink connection
110-
func (nls *NetlinkSocket) Receive() ([]byte, error) {
110+
func (s *Socket) Receive() ([]byte, error) {
111111
// TODO remove magic numbers
112112
rb := make([]byte, 8192)
113-
_, _, err := syscall.Recvfrom(nls.socketFd, rb, 0)
113+
_, _, err := syscall.Recvfrom(s.socketFd, rb, 0)
114114
if err != nil {
115115
return nil, err
116116
}

0 commit comments

Comments
 (0)