ffi-libc 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b34fc7cee6607ace19df65af88ddd4f84c9b9eb
4
+ data.tar.gz: 872117aa89b9d0728ab50ebf9d299f88d0af3db5
5
+ SHA512:
6
+ metadata.gz: fcf582bb0a029f134897796dda7eb570931da272ece724473e95a58b3650a3c5dbfa0439061f3277d2107e5b18e758333cf21200d75b51666ebc5ba50b33183e
7
+ data.tar.gz: 5c456c33211162a7bd2662b5fbc94d4aea64bf9a0ca904cbe6dfd658817637ef0fe8a77ce67126fe5088bc532a99d066c06e4018b05cb45e942af603cdf3d97a
@@ -0,0 +1,4 @@
1
+ doc
2
+ pkg
3
+ .bundle
4
+ .yardoc
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem install ffi rubygems-tasks rspec yard
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-18mode
13
+ - rvm: rbx-19mode
14
+ script: rake test
@@ -1,3 +1,24 @@
1
+ ### 0.1.0 / 2013-08-15
2
+
3
+ * Require ffi ~> 1.0.
4
+ * Added `alarm`.
5
+ * Added `clock`.
6
+ * Added `getc`.
7
+ * Added `getchar`.
8
+ * Added `gets`.
9
+ * Added `ungetc`.
10
+ * Added `getifaddrs`.
11
+ * Added `puts`.
12
+ * Added `putchar`.
13
+ * Added `putc`.
14
+ * Added `strcmp`.
15
+ * Added `strncmp`.
16
+ * Added {FFI::LibC::NULL}.
17
+ * Added {FFI::LibC::Ifaddrs}.
18
+ * Added {FFI::LibC.raise_error}.
19
+ * Added {FFI::LibC.each_ifaddr}.
20
+ * Added {FFI::LibC.rusage}.
21
+
1
22
  ### 0.0.5 / 2011-05-11
2
23
 
3
24
  * Skip `clearenv`, `memrchr`, `stdin`, `stdout` and `stderr` if they cannot
@@ -27,10 +48,10 @@
27
48
  * Added the Structs:
28
49
  * {FFI::LibC::InAddr}.
29
50
  * {FFI::LibC::In6Addr}.
30
- * {FFI::LibC::SockAddr}.
31
- * {FFI::LibC::SockAddrDL}.
32
- * {FFI::LibC::SockAddrIn}.
33
- * {FFI::LibC::SockAddrIn6}.
51
+ * {FFI::LibC::Sockaddr}.
52
+ * {FFI::LibC::SockaddrDL}.
53
+ * {FFI::LibC::SockaddrIn}.
54
+ * {FFI::LibC::SockaddrIn6}.
34
55
 
35
56
  ### 0.0.1 / 2010-05-19
36
57
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Hal Brodigan
1
+ Copyright (c) 2010-2013 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ffi-libc
2
2
 
3
- * [Source](http://github.com/postmodern/ffi-libc/)
4
- * [Issues](http://github.com/postmodern/ffi-libc/issues)
3
+ * [Source](https://github.com/postmodern/ffi-libc/)
4
+ * [Issues](https://github.com/postmodern/ffi-libc/issues)
5
5
  * [Documentation](http://rubydoc.info/gems/ffi-libc)
6
6
  * [Email](postmodern.mod3 at gmail.com)
7
7
 
@@ -12,15 +12,17 @@ Useful Ruby FFI bindings for `libc`.
12
12
  ## Features
13
13
 
14
14
  * Provides common Structs used in `libc`:
15
+ * {FFI::LibC::Ifaddrs}
15
16
  * {FFI::LibC::In6Addr}
16
17
  * {FFI::LibC::InAddr}
17
- * {FFI::LibC::SockAddrDL}
18
- * {FFI::LibC::SockAddrFamily}
19
- * {FFI::LibC::SockAddrIn6}
20
- * {FFI::LibC::SockAddrIn}
21
- * {FFI::LibC::SockAddr}
18
+ * {FFI::LibC::SockaddrDL}
19
+ * {FFI::LibC::SockaddrFamily}
20
+ * {FFI::LibC::SockaddrIn6}
21
+ * {FFI::LibC::SockaddrIn}
22
+ * {FFI::LibC::Sockaddr}
22
23
  * {FFI::LibC::Timeval}
23
24
  * {FFI::LibC::Timezone}
25
+ * {FFI::LibC::RUsage}
24
26
  * Binds to common functions and global variables in `libc`:
25
27
  * `errno.h`:
26
28
  * `sys_errlist`
@@ -49,6 +51,8 @@ Useful Ruby FFI bindings for `libc`.
49
51
  * `sys/time.h`:
50
52
  * `gettimeofday`
51
53
  * `settimeofday`
54
+ * `sys/resource.h` / `bits/resource.h`:
55
+ * `getrusage`
52
56
  * `sys/mman.h`:
53
57
  * `mmap`
54
58
  * `munmap`
@@ -91,17 +95,24 @@ Useful Ruby FFI bindings for `libc`.
91
95
  * `ferror`
92
96
  * `fileno`
93
97
  * `perror`
98
+ * `netdb.h`:
99
+ * `getnameinfo`
100
+ * `ifaddrs.h`:
101
+ * `getifaddrs`
102
+ * `freeifaddrs`
94
103
 
95
104
  ## Requirements
96
105
 
97
- * [ffi](http://github.com/ffi/ffi) >= 0.6.0, <= 1.1.0
106
+ * [ffi] ~> 1.0
98
107
 
99
108
  ## Install
100
109
 
101
- $ sudo gem install ffi-libc
110
+ $ gem install ffi-libc
102
111
 
103
112
  ## License
104
113
 
105
- Copyright (c) 2010-2011 Hal Brodigan
114
+ Copyright (c) 2010-2013 Hal Brodigan
106
115
 
107
116
  See {file:LICENSE.txt} for license information.
117
+
118
+ [ffi]: https://github.com/ffi/ffi#readme
data/Rakefile CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'ore-tasks', '~> 0.4'
6
- require 'ore/tasks'
5
+ gem 'rubygems-tasks', '~> 0.1'
6
+ require 'rubygems/tasks'
7
7
 
8
- Ore::Tasks.new
8
+ Gem::Tasks.new
9
9
  rescue LoadError => e
10
10
  STDERR.puts e.message
11
- STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
11
+ STDERR.puts "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
12
12
  end
13
13
 
14
14
  begin
@@ -25,7 +25,7 @@ task :test => :spec
25
25
  task :default => :spec
26
26
 
27
27
  begin
28
- gem 'yard', '~> 0.6.0'
28
+ gem 'yard', '~> 0.8'
29
29
  require 'yard'
30
30
 
31
31
  YARD::Rake::YardocTask.new
@@ -1,15 +1,60 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
- begin
4
- Ore::Specification.new do |gemspec|
5
- # custom logic here
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'ffi/libc/version'
14
+ FFI::LibC::VERSION
15
+ end
16
+
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
+
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
28
+
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
6
31
  end
7
- rescue NameError
8
- begin
9
- require 'ore/specification'
10
- retry
11
- rescue LoadError
12
- STDERR.puts "The 'ffi-libc.gemspec' file requires Ore."
13
- STDERR.puts "Run `gem install ore-core` to install Ore."
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
33
+
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
37
+
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
41
+
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
46
+
47
+ split = lambda { |string| string.split(/,\s*/) }
48
+
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
52
+ end
53
+ end
54
+
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
58
+ end
14
59
  end
15
60
  end
@@ -1,17 +1,17 @@
1
1
  name: ffi-libc
2
- version: 0.0.5
2
+ version: 0.1.0
3
3
  summary: Useful FFI bindings for libc
4
4
  description: Useful Ruby FFI bindings for libc.
5
5
  license: MIT
6
6
  authors: Postmodern
7
7
  email: postmodern.mod3@gmail.com
8
- homepage: http://github.com/postmodern/ffi-libc
8
+ homepage: https://github.com/postmodern/ffi-libc#redme
9
9
  has_yard: true
10
10
 
11
11
  dependencies:
12
- ffi: >= 0.6.0, <= 1.1.0
12
+ ffi: ~> 1.0
13
13
 
14
14
  development_dependencies:
15
- ore-tasks: ~> 0.4
15
+ rubygems-tasks: ~> 0.1
16
16
  rspec: ~> 2.4
17
- yard: ~> 0.6.0
17
+ yard: ~> 0.8
@@ -1,2 +1,13 @@
1
1
  require 'ffi/libc/types'
2
+ require 'ffi/libc/af'
3
+ require 'ffi/libc/ifaddrs'
4
+ require 'ffi/libc/in_addr'
5
+ require 'ffi/libc/in6_addr'
6
+ require 'ffi/libc/sockaddr'
7
+ require 'ffi/libc/sockaddr_dl'
8
+ require 'ffi/libc/sockaddr_in'
9
+ require 'ffi/libc/sockaddr_in6'
10
+ require 'ffi/libc/timeval'
11
+ require 'ffi/libc/timezone'
12
+ require 'ffi/libc/rusage'
2
13
  require 'ffi/libc/libc'
@@ -0,0 +1,93 @@
1
+ require 'ffi/libc/ifaddrs_union'
2
+ require 'ffi/libc/sockaddr'
3
+
4
+ module FFI
5
+ module LibC
6
+ #
7
+ # @since 0.1.0
8
+ #
9
+ class Ifaddrs < FFI::Struct
10
+
11
+ layout :ifa_next, :pointer,
12
+ :ifa_name, :string,
13
+ :ifa_flags, :uint,
14
+ :ifa_addr, :pointer,
15
+ :ifa_netmask, :pointer,
16
+ :ifa_ifu, IfaddrsUnion,
17
+ :ifa_data, :pointer
18
+
19
+ #
20
+ # Gets the next Interface Address in the list.
21
+ #
22
+ # @return [Ifaddrs, nil]
23
+ # The next Interface Address in the list.
24
+ #
25
+ def next
26
+ unless self[:ifa_next].null?
27
+ Ifaddrs.new(self[:ifa_next])
28
+ end
29
+ end
30
+
31
+ #
32
+ # The name of the Interface.
33
+ #
34
+ # @return [String]
35
+ # The name.
36
+ #
37
+ def name
38
+ self[:ifa_name]
39
+ end
40
+
41
+ #
42
+ # The flags of the Interface.
43
+ #
44
+ # @return [Integer]
45
+ # The flags.
46
+ #
47
+ def flags
48
+ self[:ifa_flags]
49
+ end
50
+
51
+ #
52
+ # The address of the Interface.
53
+ #
54
+ # @return [Sockaddr]
55
+ # The basic socket address.
56
+ #
57
+ def addr
58
+ Sockaddr.new(self[:ifa_addr])
59
+ end
60
+
61
+ #
62
+ # The netmask of the Interface.
63
+ #
64
+ # @return [Sockaddr]
65
+ # The socket address containing the netmask.
66
+ #
67
+ def netmask
68
+ Sockaddr.new(self[:ifa_netmask])
69
+ end
70
+
71
+ #
72
+ # The broadcast address of the Interface.
73
+ #
74
+ # @return [Sockaddr]
75
+ # The broadcast address.
76
+ #
77
+ def broadaddr
78
+ Sockaddr.new(self[:ifa_ifu][:ifu_broadaddr])
79
+ end
80
+
81
+ #
82
+ # The destination address of the Interface.
83
+ #
84
+ # @return [Sockaddr]
85
+ # The destination address.
86
+ #
87
+ def dstaddr
88
+ Sockaddr.new(self[:ifa_ifu][:ifu_dstaddr])
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,15 @@
1
+ require 'ffi'
2
+
3
+ module FFI
4
+ module LibC
5
+ #
6
+ # @since 0.1.0
7
+ #
8
+ class IfaddrsUnion < FFI::Union
9
+
10
+ layout :ifu_broadaddr, :pointer,
11
+ :ifu_dstaddr, :pointer
12
+
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,8 @@
1
1
  require 'ffi/libc/types'
2
2
  require 'ffi/libc/timeval'
3
3
  require 'ffi/libc/timezone'
4
+ require 'ffi/libc/ifaddrs'
5
+ require 'ffi/libc/rusage'
4
6
 
5
7
  require 'ffi'
6
8
 
@@ -10,11 +12,18 @@ module FFI
10
12
 
11
13
  ffi_lib [FFI::CURRENT_PROCESS, 'c']
12
14
 
15
+ # The NULL constant
16
+ NULL = nil
17
+
13
18
  # errno.h
14
19
  attach_variable :sys_errlist, :pointer
15
20
  attach_variable :sys_nerr, :int
16
21
  attach_variable :errno, :int
17
22
 
23
+ def self.raise_error(error=self.errno)
24
+ raise(strerror(error))
25
+ end
26
+
18
27
  # unistd.h
19
28
  attach_function :brk, [:pointer], :int
20
29
  attach_function :sbrk, [:pointer], :pointer
@@ -24,6 +33,7 @@ module FFI
24
33
  attach_function :geteuid, [], :uid_t
25
34
  attach_function :getgid, [], :gid_t
26
35
  attach_function :getegid, [], :gid_t
36
+ attach_function :alarm, [:uint], :uint
27
37
 
28
38
  # stdlib.h
29
39
  attach_function :calloc, [:size_t, :size_t], :pointer
@@ -41,6 +51,7 @@ module FFI
41
51
  end
42
52
 
43
53
  # time.h
54
+ attach_function :clock, [], :clock_t
44
55
  attach_function :time, [:pointer], :time_t
45
56
 
46
57
  # sys/time.h
@@ -54,26 +65,28 @@ module FFI
54
65
  # string.h
55
66
  attach_function :bzero, [:pointer, :size_t], :void
56
67
  attach_function :memset, [:pointer, :int, :size_t], :pointer
57
- attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
58
- attach_function :memcmp, [:pointer, :pointer, :size_t], :int
59
- attach_function :memchr, [:pointer, :int, :size_t], :pointer
68
+ attach_function :memcpy, [:buffer_out, :buffer_in, :size_t], :pointer
69
+ attach_function :memcmp, [:buffer_in, :buffer_in, :size_t], :int
70
+ attach_function :memchr, [:buffer_in, :int, :size_t], :pointer
60
71
 
61
72
  begin
62
- attach_function :memrchr, [:pointer, :int, :size_t], :pointer
73
+ attach_function :memrchr, [:buffer_in, :int, :size_t], :pointer
63
74
  rescue FFI::NotFoundError
64
75
  # memrchr is not available on OSX
65
76
  end
66
77
 
67
- attach_function :strcpy, [:string, :string], :pointer
68
- attach_function :strncpy, [:string, :string, :size_t], :pointer
69
- attach_function :strlen, [:string], :size_t
70
- attach_function :index, [:string, :int], :string
71
- attach_function :rindex, [:string, :int], :string
72
- attach_function :strchr, [:string, :int], :string
73
- attach_function :strrchr, [:string, :int], :string
74
- attach_function :strstr, [:string, :string], :string
78
+ attach_function :strcpy, [:buffer_out, :string], :pointer
79
+ attach_function :strncpy, [:buffer_out, :string, :size_t], :pointer
80
+ attach_function :strcmp, [:buffer_in, :buffer_in], :int
81
+ attach_function :strncmp, [:buffer_in, :buffer_in, :size_t], :int
82
+ attach_function :strlen, [:buffer_in], :size_t
83
+ attach_function :index, [:buffer_in, :int], :pointer
84
+ attach_function :rindex, [:buffer_in, :int], :pointer
85
+ attach_function :strchr, [:buffer_in, :int], :pointer
86
+ attach_function :strrchr, [:buffer_in, :int], :pointer
87
+ attach_function :strstr, [:buffer_in, :string], :pointer
75
88
  attach_function :strerror, [:int], :string
76
-
89
+
77
90
  begin
78
91
  attach_variable :stdin, :pointer
79
92
  attach_variable :stdout, :pointer
@@ -81,19 +94,19 @@ module FFI
81
94
  rescue FFI::NotFoundError
82
95
  # stdin, stdout, stderr are not available on OSX
83
96
  end
84
-
97
+
85
98
  attach_function :fopen, [:string, :string], :FILE
86
99
  attach_function :fdopen, [:int, :string], :FILE
87
100
  attach_function :freopen, [:string, :string, :FILE], :FILE
88
101
  attach_function :fseek, [:FILE, :long, :int], :int
89
102
  attach_function :ftell, [:FILE], :long
90
103
  attach_function :rewind, [:FILE], :void
91
- attach_function :fread, [:pointer, :size_t, :size_t, :FILE], :size_t
92
- attach_function :fwrite, [:pointer, :size_t, :size_t, :FILE], :size_t
104
+ attach_function :fread, [:buffer_out, :size_t, :size_t, :FILE], :size_t
105
+ attach_function :fwrite, [:buffer_in, :size_t, :size_t, :FILE], :size_t
93
106
  attach_function :fgetc, [:FILE], :int
94
- attach_function :fgets, [:pointer, :int, :FILE], :pointer
107
+ attach_function :fgets, [:buffer_out, :int, :FILE], :pointer
95
108
  attach_function :fputc, [:int, :FILE], :int
96
- attach_function :fputs, [:string, :FILE], :int
109
+ attach_function :fputs, [:buffer_in, :FILE], :int
97
110
  attach_function :fflush, [:FILE], :int
98
111
  attach_function :fclose, [:FILE], :int
99
112
  attach_function :clearerr, [:FILE], :void
@@ -101,5 +114,104 @@ module FFI
101
114
  attach_function :ferror, [:FILE], :int
102
115
  attach_function :fileno, [:FILE], :int
103
116
  attach_function :perror, [:string], :void
117
+
118
+ attach_function :getc, [:FILE], :int
119
+ attach_function :getchar, [], :int
120
+ attach_function :gets, [:buffer_out], :int
121
+ attach_function :ungetc, [:int, :pointer], :int
122
+
123
+ attach_function :putc, [:int, :FILE], :int
124
+ attach_function :putchar, [:int], :int
125
+ attach_function :puts, [:string], :int
126
+
127
+ # netdb.h
128
+ attach_function :getnameinfo, [
129
+ :pointer,
130
+ :socklen_t, :pointer,
131
+ :socklen_t, :pointer,
132
+ :socklen_t, :int
133
+ ], :int
134
+
135
+ NI_MAXHOST = 1024
136
+ NI_MAXSERV = 32
137
+
138
+ NI_NUMERICHOST = 1 # Don't try to look up hostname.
139
+ NI_NUMERICSERV = 2 # Don't convert port number to name.
140
+ NI_NOFQDN = 4 # Only return nodename portion.
141
+ NI_NAMEREQD = 8 # Don't return numeric addresses.
142
+ NI_DGRAM = 16 # Look up UDP service rather than TCP.
143
+
144
+ # ifaddrs.h
145
+ attach_function :getifaddrs, [:pointer], :int
146
+ attach_function :freeifaddrs, [:pointer], :void
147
+
148
+ #
149
+ # Enumerates over the Interface Addresses.
150
+ #
151
+ # @yield [ifaddr]
152
+ # The given block will be passed each Interface Address.
153
+ #
154
+ # @yieldparam [Ifaddrs] ifaddr
155
+ # An Interface Address.
156
+ #
157
+ # @return [Enumerator]
158
+ # If no block is given, an enumerator will be returned.
159
+ #
160
+ # @since 0.1.0
161
+ #
162
+ def self.each_ifaddr
163
+ return enum_for(__method__) unless block_given?
164
+
165
+ ptr = MemoryPointer.new(:pointer)
166
+
167
+ if getifaddrs(ptr) == -1
168
+ raise_error
169
+ end
170
+
171
+ if (ifaddrs = ptr.get_pointer(0)).null?
172
+ return
173
+ end
174
+
175
+ ifaddr = Ifaddrs.new(ifaddrs)
176
+
177
+ while ifaddr
178
+ yield ifaddr
179
+
180
+ ifaddr = ifaddr.next
181
+ end
182
+
183
+ freeifaddrs(ifaddrs)
184
+ end
185
+
186
+ # bits/resource.h (Linux) / sys/resource.h (Darwin)
187
+ RUSAGE_SELF = 0
188
+ RUSAGE_CHILDREN = -1
189
+ RUSAGE_THREAD = 1 # Linux/glibc only
190
+
191
+ attach_function :getrusage, [:int, :pointer], :int
192
+
193
+ #
194
+ # Gets the RUsage for the user.
195
+ #
196
+ # @param [RUSAGE_SELF, RUSAGE_CHILDREN, RUSAGE_THREAD] who
197
+ # Whome to get RUsage statistics for.
198
+ #
199
+ # @return [RUsage]
200
+ # The RUsage statistics.
201
+ #
202
+ # @raise [RuntimeError]
203
+ # An error has occurred.
204
+ #
205
+ # @since 0.1.0
206
+ #
207
+ def self.rusage(who=RUSAGE_SELF)
208
+ rusage = RUsage.new
209
+
210
+ unless (ret = getrusage(who,rusage)) == 0
211
+ raise_error(ret)
212
+ end
213
+
214
+ return rusage
215
+ end
104
216
  end
105
217
  end
@@ -0,0 +1,30 @@
1
+ require 'ffi/libc/types'
2
+ require 'ffi/libc/timeval'
3
+
4
+ module FFI
5
+ module LibC
6
+ #
7
+ # @since 0.1.0
8
+ #
9
+ class RUsage < FFI::Struct
10
+
11
+ layout :ru_utime, Timeval,
12
+ :ru_stime, Timeval,
13
+ :ru_maxrss, :long,
14
+ :ru_ixrss, :long,
15
+ :ru_idrss, :long,
16
+ :ru_isrss, :long,
17
+ :ru_minflt, :long,
18
+ :ru_majflt, :long,
19
+ :ru_nswap, :long,
20
+ :ru_inblock, :long,
21
+ :ru_oublock, :long,
22
+ :ru_msgsnd, :long,
23
+ :ru_msgrcv, :long,
24
+ :ru_nsignals, :long,
25
+ :ru_nvcsw, :long,
26
+ :ru_nivcsw, :long
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ require 'ffi/libc/types'
2
+ require 'ffi/libc/sockaddr_family'
3
+
4
+ module FFI
5
+ module LibC
6
+ #
7
+ # The generic `sockaddr` structure.
8
+ #
9
+ class Sockaddr < SockaddrFamily
10
+
11
+ layout :family, :sa_family_t,
12
+ :data, [:char, 14]
13
+
14
+ end
15
+ end
16
+ end
@@ -1,12 +1,12 @@
1
1
  require 'ffi/libc/types'
2
- require 'ffi/libc/sock_addr_family'
2
+ require 'ffi/libc/sockaddr_family'
3
3
 
4
4
  module FFI
5
5
  module LibC
6
6
  #
7
7
  # The data-link socket address
8
8
  #
9
- class SockAddrDL < SockAddrFamily
9
+ class SockaddrDL < SockaddrFamily
10
10
 
11
11
  layout :len, :uint8,
12
12
  :family, :sa_family_t,
@@ -5,7 +5,7 @@ module FFI
5
5
  #
6
6
  # Common abstract superclass for all sockaddr struct classes
7
7
  #
8
- class SockAddrFamily < ::FFI::Struct
8
+ class SockaddrFamily < ::FFI::Struct
9
9
 
10
10
  end
11
11
  end
@@ -0,0 +1,19 @@
1
+ require 'ffi/libc/types'
2
+ require 'ffi/libc/sockaddr_family'
3
+
4
+ module FFI
5
+ module LibC
6
+ #
7
+ # sockaddr inet, always good to have around
8
+ #
9
+ class SockaddrIn < SockaddrFamily
10
+
11
+ layout :len, :uint8,
12
+ :family, :sa_family_t,
13
+ :port, :in_port_t,
14
+ :addr, :in_addr_t,
15
+ :_sa_zero, [:uint8, 8]
16
+
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,5 @@
1
1
  require 'ffi/libc/types'
2
+ require 'ffi/libc/sockaddr_family'
2
3
  require 'ffi/libc/in6_addr'
3
4
 
4
5
  module FFI
@@ -6,7 +7,7 @@ module FFI
6
7
  #
7
8
  # IPv6 socket address
8
9
  #
9
- class SockAddrIn6 < SockAddrFamily
10
+ class SockaddrIn6 < SockaddrFamily
10
11
 
11
12
  layout :len, :uint8,
12
13
  :family, :sa_family_t,
@@ -7,5 +7,8 @@ module FFI
7
7
  typedef :pointer, :FILE
8
8
  typedef :uint32, :in_addr_t
9
9
  typedef :uint16, :in_port_t
10
+
11
+ # time.h
12
+ typedef :long, :clock_t
10
13
  end
11
14
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'ffi/libc/ifaddrs'
3
+
4
+ describe Ifaddrs do
5
+ subject { LibC.each_ifaddr.first }
6
+
7
+ it "should have a name" do
8
+ subject.name.should_not be_empty
9
+ end
10
+
11
+ it "should have flags" do
12
+ subject.flags.should be_kind_of(Integer)
13
+ end
14
+
15
+ it "should have an addr" do
16
+ subject.addr.should be_kind_of(Sockaddr)
17
+ end
18
+
19
+ it "should have an netmask" do
20
+ subject.netmask.should be_kind_of(Sockaddr)
21
+ end
22
+
23
+ it "should have a broadcast addr" do
24
+ subject.broadaddr.should be_kind_of(Sockaddr)
25
+ end
26
+
27
+ it "should have a destination addr" do
28
+ subject.dstaddr.should be_kind_of(Sockaddr)
29
+ end
30
+ end
@@ -1,9 +1,36 @@
1
1
  require 'spec_helper'
2
+ require 'ffi/libc'
2
3
 
3
- describe "FFI::LibC" do
4
- it "should attach all functions" do
5
- lambda {
6
- require 'ffi/libc/libc'
7
- }.should_not raise_error(FFI::NotFoundError)
4
+ describe FFI::LibC do
5
+ describe "NULL" do
6
+ subject { described_class::NULL }
7
+
8
+ it { should == nil }
9
+ end
10
+
11
+ describe "each_ifaddr" do
12
+ it "should yield Ifaddrs" do
13
+ addrs = []
14
+
15
+ described_class.each_ifaddr do |ifaddr|
16
+ addrs << ifaddr
17
+ end
18
+
19
+ addrs.all? { |addr| addr.kind_of?(Ifaddrs) }.should be_true
20
+ end
21
+
22
+ context "when not given a block" do
23
+ subject { described_class.each_ifaddr }
24
+
25
+ it { should be_kind_of(Enumerable) }
26
+ end
27
+ end
28
+
29
+ describe "rusage" do
30
+ subject { described_class.rusage }
31
+
32
+ it "should be able to fetch its own memory usage" do
33
+ subject[:ru_maxrss].should be > 4000
34
+ end
8
35
  end
9
36
  end
@@ -1,4 +1,6 @@
1
1
  gem 'rspec', '~> 2.4'
2
2
  require 'rspec'
3
3
 
4
- require 'ffi'
4
+ require 'ffi/libc'
5
+ include FFI
6
+ include FFI::LibC
metadata CHANGED
@@ -1,76 +1,84 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffi-libc
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Postmodern
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-05-11 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2013-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: ffi
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - <=
22
- - !ruby/object:Gem::Version
23
- version: 1.1.0
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.6.0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
27
20
  type: :runtime
28
- version_requirements: *id001
29
- - !ruby/object:Gem::Dependency
30
- name: ore-tasks
31
21
  prerelease: false
32
- requirement: &id002 !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
35
24
  - - ~>
36
- - !ruby/object:Gem::Version
37
- version: "0.4"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubygems-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
38
34
  type: :development
39
- version_requirements: *id002
40
- - !ruby/object:Gem::Dependency
41
- name: rspec
42
35
  prerelease: false
43
- requirement: &id003 !ruby/object:Gem::Requirement
44
- none: false
45
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
46
38
  - - ~>
47
- - !ruby/object:Gem::Version
48
- version: "2.4"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
49
48
  type: :development
50
- version_requirements: *id003
51
- - !ruby/object:Gem::Dependency
52
- name: yard
53
49
  prerelease: false
54
- requirement: &id004 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
57
52
  - - ~>
58
- - !ruby/object:Gem::Version
59
- version: 0.6.0
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
60
62
  type: :development
61
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
62
69
  description: Useful Ruby FFI bindings for libc.
63
- email:
64
- - postmodern.mod3@gmail.com
70
+ email: postmodern.mod3@gmail.com
65
71
  executables: []
66
-
67
72
  extensions: []
68
-
69
- extra_rdoc_files:
73
+ extra_rdoc_files:
74
+ - ChangeLog.md
75
+ - LICENSE.txt
70
76
  - README.md
71
- files:
77
+ files:
72
78
  - .gemtest
79
+ - .gitignore
73
80
  - .rspec
81
+ - .travis.yml
74
82
  - .yardopts
75
83
  - ChangeLog.md
76
84
  - LICENSE.txt
@@ -80,45 +88,45 @@ files:
80
88
  - gemspec.yml
81
89
  - lib/ffi/libc.rb
82
90
  - lib/ffi/libc/af.rb
91
+ - lib/ffi/libc/ifaddrs.rb
92
+ - lib/ffi/libc/ifaddrs_union.rb
83
93
  - lib/ffi/libc/in6_addr.rb
84
94
  - lib/ffi/libc/in_addr.rb
85
95
  - lib/ffi/libc/libc.rb
86
- - lib/ffi/libc/sock_addr.rb
87
- - lib/ffi/libc/sock_addr_dl.rb
88
- - lib/ffi/libc/sock_addr_family.rb
89
- - lib/ffi/libc/sock_addr_in.rb
90
- - lib/ffi/libc/sock_addr_in6.rb
96
+ - lib/ffi/libc/rusage.rb
97
+ - lib/ffi/libc/sockaddr.rb
98
+ - lib/ffi/libc/sockaddr_dl.rb
99
+ - lib/ffi/libc/sockaddr_family.rb
100
+ - lib/ffi/libc/sockaddr_in.rb
101
+ - lib/ffi/libc/sockaddr_in6.rb
91
102
  - lib/ffi/libc/timeval.rb
92
103
  - lib/ffi/libc/timezone.rb
93
104
  - lib/ffi/libc/types.rb
105
+ - spec/ifaddrs_spec.rb
94
106
  - spec/libc_spec.rb
95
107
  - spec/spec_helper.rb
96
- homepage: http://github.com/postmodern/ffi-libc
97
- licenses:
108
+ homepage: https://github.com/postmodern/ffi-libc#redme
109
+ licenses:
98
110
  - MIT
111
+ metadata: {}
99
112
  post_install_message:
100
113
  rdoc_options: []
101
-
102
- require_paths:
114
+ require_paths:
103
115
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
111
- none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: "0"
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
116
126
  requirements: []
117
-
118
- rubyforge_project: ffi-libc
119
- rubygems_version: 1.8.1
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.5
120
129
  signing_key:
121
- specification_version: 3
130
+ specification_version: 4
122
131
  summary: Useful FFI bindings for libc
123
- test_files:
124
- - spec/libc_spec.rb
132
+ test_files: []
@@ -1,17 +0,0 @@
1
- require 'ffi/libc/types'
2
- require 'ffi/libc/sock_addr_family'
3
-
4
- module FFI
5
- module LibC
6
- #
7
- # The generic `sock_addr` structure.
8
- #
9
- class SockAddr < SockAddrFamily
10
-
11
- layout :len, :uint8,
12
- :family, :sa_family_t,
13
- :data, :char
14
-
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require 'ffi/libc/types'
2
- require 'ffi/libc/sock_addr_family'
3
-
4
- module FFI
5
- module LibC
6
- #
7
- # sockaddr inet, always good to have around
8
- #
9
- class SockAddrIn < SockAddrFamily
10
-
11
- layout :len, :uint8,
12
- :family, :sa_family_t,
13
- :port, :in_port_t,
14
- :addr, :in_addr_t,
15
- :_sa_zero, [:uint8, 8]
16
-
17
- end
18
- end
19
- end