ronin-support 0.4.1 → 0.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/ChangeLog.md +75 -32
  2. data/Gemfile +17 -18
  3. data/README.md +9 -10
  4. data/Rakefile +10 -2
  5. data/gemspec.yml +1 -1
  6. data/lib/ronin/binary.rb +21 -0
  7. data/lib/ronin/binary/hexdump.rb +20 -0
  8. data/lib/ronin/binary/hexdump/parser.rb +411 -0
  9. data/lib/ronin/binary/struct.rb +579 -0
  10. data/lib/ronin/binary/template.rb +437 -0
  11. data/lib/ronin/extensions/ip_addr.rb +17 -13
  12. data/lib/ronin/extensions/regexp.rb +45 -0
  13. data/lib/ronin/extensions/string.rb +3 -3
  14. data/lib/ronin/formatting/extensions/binary.rb +1 -0
  15. data/lib/ronin/formatting/extensions/binary/array.rb +63 -0
  16. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  17. data/lib/ronin/formatting/extensions/binary/file.rb +39 -6
  18. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  19. data/lib/ronin/formatting/extensions/binary/integer.rb +56 -43
  20. data/lib/ronin/formatting/extensions/binary/string.rb +75 -187
  21. data/lib/ronin/formatting/extensions/text/string.rb +61 -0
  22. data/lib/ronin/fuzzing/extensions/string.rb +21 -8
  23. data/lib/ronin/fuzzing/fuzzing.rb +19 -17
  24. data/lib/ronin/network.rb +2 -1
  25. data/lib/ronin/network/dns.rb +57 -15
  26. data/lib/ronin/network/extensions.rb +0 -1
  27. data/lib/ronin/network/ftp.rb +145 -0
  28. data/lib/ronin/network/http/http.rb +13 -14
  29. data/lib/ronin/network/imap.rb +11 -10
  30. data/lib/ronin/network/mixins.rb +1 -0
  31. data/lib/ronin/network/mixins/ftp.rb +155 -0
  32. data/lib/ronin/network/mixins/ssl.rb +1 -1
  33. data/lib/ronin/network/mixins/tcp.rb +39 -6
  34. data/lib/ronin/network/mixins/udp.rb +121 -1
  35. data/lib/ronin/network/mixins/unix.rb +279 -0
  36. data/lib/ronin/network/pop3.rb +5 -5
  37. data/lib/ronin/network/proxy.rb +578 -0
  38. data/lib/ronin/network/smtp/email.rb +1 -1
  39. data/lib/ronin/network/smtp/smtp.rb +7 -8
  40. data/lib/ronin/network/ssl.rb +1 -6
  41. data/lib/ronin/network/tcp.rb +2 -305
  42. data/lib/ronin/network/tcp/proxy.rb +377 -0
  43. data/lib/ronin/network/tcp/tcp.rb +435 -0
  44. data/lib/ronin/network/telnet.rb +27 -23
  45. data/lib/ronin/network/udp.rb +2 -266
  46. data/lib/ronin/network/udp/proxy.rb +169 -0
  47. data/lib/ronin/network/udp/udp.rb +442 -0
  48. data/lib/ronin/network/unix.rb +287 -0
  49. data/lib/ronin/path.rb +2 -2
  50. data/lib/ronin/spec/ui/output.rb +1 -7
  51. data/lib/ronin/support.rb +1 -0
  52. data/lib/ronin/support/inflector.rb +3 -7
  53. data/lib/ronin/support/support.rb +2 -1
  54. data/lib/ronin/support/version.rb +1 -1
  55. data/lib/ronin/ui/output/helpers.rb +13 -15
  56. data/lib/ronin/ui/output/output.rb +2 -2
  57. data/lib/ronin/ui/output/terminal/color.rb +10 -4
  58. data/lib/ronin/wordlist.rb +92 -17
  59. data/ronin-support.gemspec +38 -109
  60. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  61. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  62. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  63. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  64. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  65. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  66. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  67. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  68. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  69. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  70. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  71. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  72. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  73. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  74. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  75. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  76. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  77. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  78. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  79. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  80. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  81. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  82. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  83. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  84. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  85. data/spec/binary/hexdump/parser_spec.rb +302 -0
  86. data/spec/binary/struct_spec.rb +496 -0
  87. data/spec/binary/template_spec.rb +400 -0
  88. data/spec/extensions/ip_addr_spec.rb +58 -32
  89. data/spec/extensions/regexp_spec.rb +60 -0
  90. data/spec/extensions/string_spec.rb +1 -1
  91. data/spec/formatting/binary/array_spec.rb +22 -0
  92. data/spec/formatting/binary/base64_spec.rb +50 -0
  93. data/spec/formatting/binary/float_spec.rb +30 -0
  94. data/spec/formatting/binary/integer_spec.rb +54 -40
  95. data/spec/formatting/binary/string_spec.rb +69 -182
  96. data/spec/formatting/text/string_spec.rb +30 -0
  97. data/spec/network/dns_spec.rb +64 -0
  98. data/spec/network/ftp_spec.rb +65 -0
  99. data/spec/network/proxy_spec.rb +121 -0
  100. data/spec/network/shared/unix_server.rb +31 -0
  101. data/spec/network/tcp/proxy_spec.rb +116 -0
  102. data/spec/network/{tcp_spec.rb → tcp/tcp_spec.rb} +24 -1
  103. data/spec/network/telnet_spec.rb +67 -0
  104. data/spec/network/{udp_spec.rb → udp/udp_spec.rb} +24 -1
  105. data/spec/network/unix_spec.rb +183 -0
  106. data/spec/wordlist_spec.rb +74 -13
  107. metadata +129 -85
  108. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
@@ -27,7 +27,6 @@ require 'net/http'
27
27
  begin
28
28
  require 'net/https'
29
29
  rescue ::LoadError
30
- $stderr.puts "WARNING: could not load 'net/https'"
31
30
  end
32
31
 
33
32
  module Ronin
@@ -51,7 +50,7 @@ module Ronin
51
50
  #
52
51
  # @api public
53
52
  #
54
- def HTTP.proxy
53
+ def self.proxy
55
54
  @proxy ||= if ENV['HTTP_PROXY']
56
55
  Proxy.parse(ENV['HTTP_PROXY'])
57
56
  else
@@ -74,7 +73,7 @@ module Ronin
74
73
  #
75
74
  # @api public
76
75
  #
77
- def HTTP.proxy=(new_proxy)
76
+ def self.proxy=(new_proxy)
78
77
  @proxy = Proxy.create(new_proxy)
79
78
  end
80
79
 
@@ -86,7 +85,7 @@ module Ronin
86
85
  #
87
86
  # @api public
88
87
  #
89
- def HTTP.user_agent
88
+ def self.user_agent
90
89
  @user_agent ||= nil
91
90
  end
92
91
 
@@ -98,7 +97,7 @@ module Ronin
98
97
  #
99
98
  # @api public
100
99
  #
101
- def HTTP.user_agent=(agent)
100
+ def self.user_agent=(agent)
102
101
  @user_agent = agent
103
102
  end
104
103
 
@@ -113,7 +112,7 @@ module Ronin
113
112
  #
114
113
  # @api private
115
114
  #
116
- def HTTP.expand_url(url)
115
+ def self.expand_url(url)
117
116
  new_options = {}
118
117
 
119
118
  url = case url
@@ -155,7 +154,7 @@ module Ronin
155
154
  # @option options [String] :host
156
155
  # The host to connect to.
157
156
  #
158
- # @option options [String] :port (::Net::HTTP.default_port)
157
+ # @option options [String] :port (Net::HTTP.default_port)
159
158
  # The port to connect to.
160
159
  #
161
160
  # @option options [String] :user
@@ -175,7 +174,7 @@ module Ronin
175
174
  #
176
175
  # @api private
177
176
  #
178
- def HTTP.expand_options(options={})
177
+ def self.expand_options(options={})
179
178
  new_options = options.dup
180
179
 
181
180
  new_options[:port] ||= Net::HTTP.default_port
@@ -210,7 +209,7 @@ module Ronin
210
209
  #
211
210
  # @api private
212
211
  #
213
- def HTTP.header_name(name)
212
+ def self.header_name(name)
214
213
  words = name.to_s.split(/[\s+_-]/)
215
214
 
216
215
  words.each { |word| word.capitalize! }
@@ -229,11 +228,11 @@ module Ronin
229
228
  #
230
229
  # @api private
231
230
  #
232
- def HTTP.headers(options={})
231
+ def self.headers(options={})
233
232
  headers = {}
234
233
 
235
- if HTTP.user_agent
236
- headers['User-Agent'] = HTTP.user_agent
234
+ if user_agent
235
+ headers['User-Agent'] = user_agent
237
236
  end
238
237
 
239
238
  if options
@@ -292,7 +291,7 @@ module Ronin
292
291
  #
293
292
  # @api private
294
293
  #
295
- def HTTP.request(options={})
294
+ def self.request(options={})
296
295
  unless options[:method]
297
296
  raise(ArgumentError,"the :method option must be specified")
298
297
  end
@@ -303,7 +302,7 @@ module Ronin
303
302
  raise(UnknownRequest,"unknown HTTP request type #{name.dump}")
304
303
  end
305
304
 
306
- headers = HTTP.headers(options[:headers])
305
+ headers = headers(options[:headers])
307
306
  path = (options[:path] || '/').to_s
308
307
  query = if options[:query]
309
308
  URI.escape(options[:query])
@@ -36,7 +36,7 @@ module Ronin
36
36
  #
37
37
  # @api public
38
38
  #
39
- def IMAP.default_port
39
+ def self.default_port
40
40
  @default_port ||= DEFAULT_PORT
41
41
  end
42
42
 
@@ -48,7 +48,7 @@ module Ronin
48
48
  #
49
49
  # @api public
50
50
  #
51
- def IMAP.default_port=(port)
51
+ def self.default_port=(port)
52
52
  @default_port = port
53
53
  end
54
54
 
@@ -90,19 +90,20 @@ module Ronin
90
90
  # @api public
91
91
  #
92
92
  def imap_connect(host,options={})
93
- host = host.to_s
94
- port = (options[:port] || IMAP.default_port)
95
- certs = options[:certs]
96
- auth = options[:auth]
97
- user = options[:user]
93
+ host = host.to_s
94
+ port = (options[:port] || IMAP.default_port)
95
+ certs = options[:certs]
96
+ auth = options[:auth]
97
+ user = options[:user]
98
98
  passwd = options[:password]
99
99
 
100
100
  if options[:ssl]
101
- ssl = true
102
- ssl_certs = options[:ssl][:certs]
101
+ ssl = true
102
+ ssl_certs = options[:ssl][:certs]
103
103
  ssl_verify = SSL::VERIFY[options[:ssl][:verify]]
104
104
  else
105
- ssl = false
105
+ ssl = false
106
+ ssl_certs = nil
106
107
  ssl_verify = false
107
108
  end
108
109
 
@@ -25,4 +25,5 @@ require 'ronin/network/mixins/esmtp'
25
25
  require 'ronin/network/mixins/pop3'
26
26
  require 'ronin/network/mixins/imap'
27
27
  require 'ronin/network/mixins/telnet'
28
+ require 'ronin/network/mixins/ftp'
28
29
  require 'ronin/network/mixins/http'
@@ -0,0 +1,155 @@
1
+ #
2
+ # Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/network/mixins/mixin'
21
+ require 'ronin/network/ftp'
22
+
23
+ module Ronin
24
+ module Network
25
+ module Mixins
26
+ #
27
+ # Adds FTP convenience methods and connection parameters to a class.
28
+ #
29
+ # Defines the following parameters:
30
+ #
31
+ # * `host` (`String`) - FTP host.
32
+ # * `port` (`Integer`) - FTP port.
33
+ # * `ftp_user` (`String`) - FTP user to login as.
34
+ # * `ftp_password` (`String`) - FTP password to login with.
35
+ # * `ftp_account` (`String`) - FTP account information to send.
36
+ #
37
+ # @since 0.5.0
38
+ #
39
+ module FTP
40
+ include Mixin, Network::FTP
41
+
42
+ # FTP host
43
+ parameter :host, :type => String,
44
+ :description => 'FTP host'
45
+
46
+ # FTP port
47
+ parameter :port, :type => Integer,
48
+ :description => 'FTP port'
49
+
50
+ # FTP user to login as
51
+ parameter :ftp_user, :type => String,
52
+ :description => 'FTP user to login as'
53
+
54
+ # FTP password to login with
55
+ parameter :ftp_password, :type => String,
56
+ :description => 'FTP password to login with'
57
+
58
+ # FTP account information to send
59
+ parameter :ftp_password, :type => String,
60
+ :description => 'FTP account information'
61
+
62
+ protected
63
+
64
+ #
65
+ # Creates a connection to the FTP server. The `host`, `port`,
66
+ # `ftp_user`, `ftp_password` and `ftp_account` parameters
67
+ # will also be used to connect to the server.
68
+ #
69
+ # @param [Hash] options
70
+ # Additional options.
71
+ #
72
+ # @option options [Integer] :port (Network::FTP.default_port)
73
+ # The port to connect to.
74
+ #
75
+ # @option options [String] :user
76
+ # The username to authenticate with.
77
+ #
78
+ # @option options [String] :password
79
+ # The password to authenticate with.
80
+ #
81
+ # @option options [String] :account
82
+ # The account information to send via the FTP `ACCT` command.
83
+ #
84
+ # @yield [session]
85
+ # If a block is given, it will be passed an FTP session object.
86
+ #
87
+ # @yieldparam [Net::FTP] session
88
+ # The FTP session.
89
+ #
90
+ # @return [Net::FTP]
91
+ # The FTP session.
92
+ #
93
+ # @see Network::FTP#ftp_connect
94
+ #
95
+ # @api public
96
+ #
97
+ def ftp_connect(options={},&block)
98
+ print_info "Connecting to #{host_port} ..."
99
+
100
+ return super(self.host,ftp_merge_options(options),&block)
101
+ end
102
+
103
+ #
104
+ # Starts a session with the FTP server. The `host`, `port`,
105
+ # `ftp_login`, `ftp_user` and `ftp_password` parameters
106
+ # will also be used to connect to the server.
107
+ #
108
+ # @yield [session]
109
+ # If a block is given, it will be passed an FTP session object.
110
+ # After the block has returned, the session will be closed.
111
+ #
112
+ # @yieldparam [Net::FTP] session
113
+ # The FTP session.
114
+ #
115
+ # @see Network::FTP#ftp_session
116
+ #
117
+ # @api public
118
+ #
119
+ def ftp_session(options={},&block)
120
+ super(ftp_merge_options(options)) do |sess|
121
+ yield sess if block_given?
122
+
123
+ print_info "Logging out ..."
124
+ end
125
+
126
+ print_info "Disconnected to #{host_port}"
127
+ return nil
128
+ end
129
+
130
+ private
131
+
132
+ #
133
+ # Merges the FTP parameters into the options for {Network::FTP}
134
+ # methods.
135
+ #
136
+ # @param [Hash] options
137
+ # The original options.
138
+ #
139
+ # @return [Hash]
140
+ # The merged options.
141
+ #
142
+ # @api private
143
+ #
144
+ def ftp_merge_options(options={})
145
+ options[:port] ||= self.port
146
+ options[:user] ||= self.ftp_user
147
+ options[:password] ||= self.ftp_password
148
+ options[:account] ||= self.ftp_account
149
+
150
+ return options
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -130,7 +130,7 @@ module Ronin
130
130
  #
131
131
  # @example
132
132
  # ssl_session do |socket|
133
- # socket.write("GET / HTTP/1.1\n\r\n\r")
133
+ # socket.write("GET /\n\n")
134
134
  #
135
135
  # socket.each_line { |line| puts line }
136
136
  # end
@@ -64,6 +64,29 @@ module Ronin
64
64
 
65
65
  protected
66
66
 
67
+ #
68
+ # Tests whether the TCP port, specified by the `host` and `port`
69
+ # parameters, is open.
70
+ #
71
+ # @param [Integer] timeout (5)
72
+ # The maximum time to attempt connecting.
73
+ #
74
+ # @return [Boolean, nil]
75
+ # Specifies whether the remote TCP port is open.
76
+ # If the connection was not accepted, `nil` will be returned.
77
+ #
78
+ # @see Network::TCP#tcp_open?
79
+ #
80
+ # @api public
81
+ #
82
+ # @since 0.5.0
83
+ #
84
+ def tcp_open?(timeout=nil)
85
+ print_info "Testing if #{host_port} is open ..."
86
+
87
+ super(self.host,self.port,self.local_host,self.local_port,timeout)
88
+ end
89
+
67
90
  #
68
91
  # Opens a TCP connection to the host and port specified by the
69
92
  # `host` and `port` parameters. If the `local_host` and
@@ -84,7 +107,7 @@ module Ronin
84
107
  #
85
108
  # @example
86
109
  # tcp_connect do |socket|
87
- # socket.write("GET / HTTP/1.1\n\r\n\r")
110
+ # socket.write("GET /\n\n")
88
111
  #
89
112
  # puts socket.readlines
90
113
  # socket.close
@@ -147,7 +170,7 @@ module Ronin
147
170
  def tcp_session(&block)
148
171
  print_info "Connecting to #{host_port} ..."
149
172
 
150
- Net.tcp_session(self.host,self.port,self.local_host,self.local_port,&block)
173
+ super(self.host,self.port,self.local_host,self.local_port,&block)
151
174
 
152
175
  print_info "Disconnected from #{host_port}"
153
176
  return nil
@@ -189,7 +212,7 @@ module Ronin
189
212
  #
190
213
  # @example
191
214
  # buffer = "GET /" + ('A' * 4096) + "\n\r"
192
- # Net.tcp_send(buffer)
215
+ # tcp_send(buffer)
193
216
  # # => true
194
217
  #
195
218
  # @see Network::TCP#tcp_send
@@ -287,15 +310,17 @@ module Ronin
287
310
  # @return [nil]
288
311
  #
289
312
  # @example
290
- # tcp_single_server do |client|
313
+ # tcp_accept do |client|
291
314
  # client.puts 'lol'
292
315
  # end
293
316
  #
294
- # @see Network::TCP#tcp_server_single_server
317
+ # @see Network::TCP#tcp_accept
295
318
  #
296
319
  # @api public
297
320
  #
298
- def tcp_single_server(&block)
321
+ # @since 0.5.0
322
+ #
323
+ def tcp_accept(&block)
299
324
  print_info "Listening on #{server_host_port} ..."
300
325
 
301
326
  super(self.server_port,self.server_host) do |client|
@@ -314,6 +339,14 @@ module Ronin
314
339
  return nil
315
340
  end
316
341
 
342
+ #
343
+ # @deprecated
344
+ # Deprecated as of 0.5.0. Use {#tcp_accept} instead.
345
+ #
346
+ def tcp_single_server(&block)
347
+ tcp_accept(&block)
348
+ end
349
+
317
350
  private
318
351
 
319
352
  #
@@ -64,6 +64,27 @@ module Ronin
64
64
 
65
65
  protected
66
66
 
67
+ #
68
+ # Tests whether the UDP port, specified by the `host` and `port`
69
+ # parameters, is open.
70
+ #
71
+ # @param [Integer] timeout (5)
72
+ # The maximum time to attempt connecting.
73
+ #
74
+ # @return [Boolean, nil]
75
+ # Specifies whether the remote UDP port is open.
76
+ # If no data or ICMP error were received, `nil` will be returned.
77
+ #
78
+ # @api public
79
+ #
80
+ # @since 0.5.0
81
+ #
82
+ def udp_open?(timeout=nil)
83
+ print_info "Testing if #{host_port} is open ..."
84
+
85
+ super(self.host,self.port,self.local_host,self.local_port,timeout)
86
+ end
87
+
67
88
  #
68
89
  # Opens a UDP connection to the host and port specified by the
69
90
  # `host` and `port` parameters. If the `local_host` and
@@ -164,7 +185,7 @@ module Ronin
164
185
  #
165
186
  # @example
166
187
  # buffer = "GET /" + ('A' * 4096) + "\n\r"
167
- # Net.udp_send(buffer)
188
+ # udp_send(buffer)
168
189
  # # => true
169
190
  #
170
191
  # @see Network::UDP#udp_send
@@ -240,6 +261,105 @@ module Ronin
240
261
  return nil
241
262
  end
242
263
 
264
+ #
265
+ # Creates a new UDPServer listening on the `server_host` and
266
+ # `server_port` parameters, accepting messages from clients in a loop.
267
+ #
268
+ # @yield [server, (client_host, client_port), mesg]
269
+ # The given block will be passed the client host/port and the received
270
+ # message.
271
+ #
272
+ # @yieldparam [UDPServer] server
273
+ # The UDPServer.
274
+ #
275
+ # @yieldparam [String] client_host
276
+ # The source host of the mesg.
277
+ #
278
+ # @yieldparam [Integer] client_port
279
+ # The source port of the mesg.
280
+ #
281
+ # @yieldparam [String] mesg
282
+ # The received message.
283
+ #
284
+ # @return [nil]
285
+ #
286
+ # @example
287
+ # udp_server_loop do |server,(host,port),mesg|
288
+ # server.send('hello',host,port)
289
+ # end
290
+ #
291
+ # @see Network::UDP#udp_server_loop
292
+ #
293
+ # @api public
294
+ #
295
+ # @since 0.5.0
296
+ #
297
+ def udp_server_loop(&block)
298
+ print_info "Listening on #{self.server_host_port} ..."
299
+
300
+ super(self.server_port,self.server_host,&block)
301
+
302
+ print_info "Closed #{self.server_host_port}"
303
+ return nil
304
+ end
305
+
306
+ #
307
+ # Creates a new UDPServer listening on the `server_host` and
308
+ # `server_port` parameters, accepts only one message from a client.
309
+ #
310
+ # @yield [server, (client_host, client_port), mesg]
311
+ # The given block will be passed the client host/port and the received
312
+ # message.
313
+ #
314
+ # @yieldparam [UDPServer] server
315
+ # The UDPServer.
316
+ #
317
+ # @yieldparam [String] client_host
318
+ # The source host of the mesg.
319
+ #
320
+ # @yieldparam [Integer] client_port
321
+ # The source port of the mesg.
322
+ #
323
+ # @yieldparam [String] mesg
324
+ # The received message.
325
+ #
326
+ # @return [nil]
327
+ #
328
+ # @example
329
+ # udp_recv do |server,(host,port),mesg|
330
+ # server.send('hello',host,port)
331
+ # end
332
+ #
333
+ # @see Network::UDP#udp_recv
334
+ #
335
+ # @api public
336
+ #
337
+ # @since 0.5.0
338
+ #
339
+ def udp_recv(&block)
340
+ print_info "Listening on #{self.server_host_port} ..."
341
+
342
+ super(self.server_port,self.server_host) do |server,(host,port),mesg|
343
+ print_info "Received message from #{host}:#{port}"
344
+ print_debug mesg
345
+
346
+ yield server, [host, port], mesg if block_given?
347
+ end
348
+
349
+ print_info "Closed #{self.server_host_port}"
350
+ return nil
351
+ end
352
+
353
+ #
354
+ # @deprecated
355
+ # Deprecated as of 0.5.0. Use {#udp_recv} instead.
356
+ #
357
+ # @since 0.5.0
358
+ #
359
+ def udp_single_server(&block)
360
+ udp_recv(&block)
361
+ end
362
+
243
363
  private
244
364
 
245
365
  #