Class: Netlink::Addrinfo

Inherits:
Object
  • Object
show all
Defined in:
lib/netlink/addrinfo.rb

Overview

AddrInfo for Socket.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sockaddr) ⇒ Addrinfo

Returns a new instance of Addrinfo.

Parameters:

  • sockaddr (Array(String, Integer, Integer), Array(Integer, Integer, Integer), String)

    array form should be compatible to the value of Socket#addr. The string should be struct sockaddr as generated by Netlink::Addrinfo.{Socket{Socket.sockaddr_nl}.



13
14
15
16
17
18
19
20
21
22
# File 'lib/netlink/addrinfo.rb', line 13

def initialize(sockaddr)
  case sockaddr
  when Array
    init_from_array(sockaddr)
  when String
    init_from_string(sockaddr)
  else
    raise TypeError, 'sockaddr must be a String or an Array'
  end
end

Instance Attribute Details

#afamilyObject (readonly)

Returns the value of attribute afamily.



9
10
11
# File 'lib/netlink/addrinfo.rb', line 9

def afamily
  @afamily
end

#groupsObject (readonly)

Returns the value of attribute groups.



9
10
11
# File 'lib/netlink/addrinfo.rb', line 9

def groups
  @groups
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/netlink/addrinfo.rb', line 9

def pid
  @pid
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/netlink/addrinfo.rb', line 32

def ==(other)
  other.is_a?(Addrinfo) && (other.pid == @pid) && (other.groups == @groups)
end

#to_sockaddrString Also known as: to_s, to_str

returns the socket address as packed struct sockaddr string

Returns:

  • (String)


26
27
28
# File 'lib/netlink/addrinfo.rb', line 26

def to_sockaddr
  Socket.sockaddr_nl(@pid, @groups)
end