Class: OSPFv2::RecvSocket
Instance Attribute Summary collapse
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
Instance Method Summary collapse
- #add_membership(group) ⇒ Object
- #close ⇒ Object
-
#initialize(src, options = {}) ⇒ RecvSocket
constructor
A new instance of RecvSocket.
- #recv(size = 8192) ⇒ Object
Constructor Details
#initialize(src, options = {}) ⇒ RecvSocket
Returns a new instance of RecvSocket.
100 101 102 103 104 105 |
# File 'lib/infra/ospf_socket.rb', line 100 def initialize(src, ={}) @src=src @sock = Socket.open(Socket::PF_INET, Socket::SOCK_RAW,89) add_membership OSPFv2::AllSPFRouters add_membership OSPFv2::AllDRouters end |
Instance Attribute Details
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
99 100 101 |
# File 'lib/infra/ospf_socket.rb', line 99 def sock @sock end |
Instance Method Details
#add_membership(group) ⇒ Object
119 120 121 122 123 |
# File 'lib/infra/ospf_socket.rb', line 119 def add_membership(group) @sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, (IPAddr.new(group).hton + IPAddr.new(@src).hton)) puts "*** ADDED #{group} membership to Recv Socket ***" rescue Errno::EADDRNOTAVAIL end |
#close ⇒ Object
115 116 117 118 |
# File 'lib/infra/ospf_socket.rb', line 115 def close begin ; @sock.close ; rescue ; end @sock=nil end |
#recv(size = 8192) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/infra/ospf_socket.rb', line 106 def recv(size=8192) begin data, sender = @sock.recvfrom(size) port, host = Socket.unpack_sockaddr_in(sender) [host,port,data] rescue => e STDERR.puts "RSocket recv() error: #{e}" end end |