sctp-socket 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES.md +10 -3
- data/README.md +3 -0
- data/ext/sctp/socket.c +150 -9
- data/sctp-socket.gemspec +11 -6
- metadata +22 -19
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30d42e64586703d527155f2fb7582e165ce6662fa3ddecec417b9905479454ca
|
4
|
+
data.tar.gz: ad2fce717f7d4c42a83db6524e7323c92b1b1edf1b73058757e6689a638cc3ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b319f18b44be59f7b5434ccbd9c4e2b4b1e948d9dfcf155c29c497e13059a6016a945aca04712b0b1afaa6801043450268533c758491ce118dc615d1209c4b
|
7
|
+
data.tar.gz: f77fd5430cc646354117a27c3a5a2064b8af11cdc7019c7400286300065eea6b107b6b7bb7796408de0f5998661c652eb16b07460b54ef25defca5a231ffa731
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGES.md
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
-
##
|
1
|
+
## 0.0.4 - 3-Dec-2020
|
2
|
+
* Added the send method. Use this when you already have a connection.
|
3
|
+
* Fixed a flags bug in the sendmsg method.
|
4
|
+
* Fixed an association_id typo in the connect method.
|
5
|
+
* The SCTP_PR_SCTP_TTL flag is automatically set if a TTL value is provided.
|
6
|
+
* Added some constants so you can actually start passing flag values.
|
7
|
+
|
8
|
+
## 0.0.3 - 1-Dec-2020
|
2
9
|
* Added notification hooks that you can subscribe to, so now the subscribe method
|
3
10
|
actually does something.
|
4
11
|
|
5
|
-
## 29-Nov-2020
|
12
|
+
## 0.0.2 - 29-Nov-2020
|
6
13
|
* Fixed the homepage link in the gemspec metadata. Thanks go to Nick LaMuro for the patch.
|
7
14
|
* The getlocalnames and getpeernames now return an array of addresses.
|
8
15
|
* Added a shutdown method.
|
9
16
|
* Added more documentation.
|
10
17
|
|
11
|
-
## 24-Nov-2020
|
18
|
+
## 0.0.1 - 24-Nov-2020
|
12
19
|
* Initial release.
|
data/README.md
CHANGED
@@ -59,6 +59,9 @@ end
|
|
59
59
|
|
60
60
|
## Known Issues
|
61
61
|
|
62
|
+
Currently this has only been developed and tested on Linux. Other platforms
|
63
|
+
will probably only be supported via community contributions.
|
64
|
+
|
62
65
|
Please report any issues on the github project page.
|
63
66
|
|
64
67
|
https://github.com/djberg96/sctp-socket
|
data/ext/sctp/socket.c
CHANGED
@@ -16,6 +16,19 @@ VALUE v_sndinfo_struct;
|
|
16
16
|
VALUE v_adaptation_event_struct;
|
17
17
|
VALUE v_partial_delivery_event_struct;
|
18
18
|
VALUE v_auth_event_struct;
|
19
|
+
VALUE v_sockaddr_in_struct;
|
20
|
+
|
21
|
+
VALUE convert_sockaddr_in_to_struct(struct sockaddr_in* addr){
|
22
|
+
char ipbuf[16];
|
23
|
+
|
24
|
+
inet_ntop(addr->sin_family, &(((struct sockaddr_in *)addr)->sin_addr), ipbuf, sizeof(ipbuf));
|
25
|
+
|
26
|
+
return rb_struct_new(v_sockaddr_in_struct,
|
27
|
+
INT2NUM(addr->sin_family),
|
28
|
+
INT2NUM(ntohs(addr->sin_port)),
|
29
|
+
rb_str_new2(ipbuf)
|
30
|
+
);
|
31
|
+
}
|
19
32
|
|
20
33
|
// Helper function to get a hash value via string or symbol.
|
21
34
|
VALUE rb_hash_aref2(VALUE v_hash, const char* key){
|
@@ -35,8 +48,15 @@ VALUE rb_hash_aref2(VALUE v_hash, const char* key){
|
|
35
48
|
* a domain (aka family) value and socket type. By default these are AF_INET
|
36
49
|
* and SOCK_SEQPACKET, respectively.
|
37
50
|
*
|
51
|
+
* There are only two supported families: SOCK_SEQPACKET for the creation
|
52
|
+
* of a one-to-many socket, and SOCK_STREAM for the creation of a
|
53
|
+
* one-to-one socket.
|
54
|
+
*
|
38
55
|
* Example:
|
39
56
|
*
|
57
|
+
* require 'socket'
|
58
|
+
* require 'sctp/socket'
|
59
|
+
*
|
40
60
|
* socket1 = SCTP::Socket.new
|
41
61
|
* socket2 = SCTP::Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
|
42
62
|
*/
|
@@ -202,7 +222,7 @@ static VALUE rsctp_connect(int argc, VALUE* argv, VALUE self){
|
|
202
222
|
if(sctp_connectx(sock_fd, (struct sockaddr *) addrs, num_ip, &assoc) < 0)
|
203
223
|
rb_raise(rb_eSystemCallError, "sctp_connectx: %s", strerror(errno));
|
204
224
|
|
205
|
-
rb_iv_set(self, "@
|
225
|
+
rb_iv_set(self, "@association_id", INT2NUM(assoc));
|
206
226
|
|
207
227
|
return self;
|
208
228
|
}
|
@@ -296,6 +316,99 @@ static VALUE rsctp_getlocalnames(VALUE self){
|
|
296
316
|
return v_array;
|
297
317
|
}
|
298
318
|
|
319
|
+
/*
|
320
|
+
* Send a message on an already-connected socket to a specific association.
|
321
|
+
*
|
322
|
+
* Example:
|
323
|
+
*
|
324
|
+
* socket = SCTP::Socket.new
|
325
|
+
* socket.connect(:port => 42000, :addresses => ['10.0.4.5', '10.0.5.5'])
|
326
|
+
*
|
327
|
+
* socket.send(:message => "Hello World")
|
328
|
+
* socket.send(:message => "Hello World", :association_id => 37)
|
329
|
+
*
|
330
|
+
*/
|
331
|
+
static VALUE rsctp_send(VALUE self, VALUE v_options){
|
332
|
+
uint16_t stream;
|
333
|
+
uint32_t ppid, send_flags, ctrl_flags, ttl, context;
|
334
|
+
ssize_t num_bytes;
|
335
|
+
int sock_fd;
|
336
|
+
sctp_assoc_t assoc_id;
|
337
|
+
struct sctp_sndrcvinfo info;
|
338
|
+
VALUE v_msg, v_stream, v_ppid, v_context, v_send_flags, v_ctrl_flags, v_ttl, v_assoc_id;
|
339
|
+
|
340
|
+
Check_Type(v_options, T_HASH);
|
341
|
+
|
342
|
+
v_msg = rb_hash_aref2(v_options, "message");
|
343
|
+
v_stream = rb_hash_aref2(v_options, "stream");
|
344
|
+
v_ppid = rb_hash_aref2(v_options, "ppid");
|
345
|
+
v_context = rb_hash_aref2(v_options, "context");
|
346
|
+
v_send_flags = rb_hash_aref2(v_options, "send_flags");
|
347
|
+
v_ctrl_flags = rb_hash_aref2(v_options, "control_flags");
|
348
|
+
v_ttl = rb_hash_aref2(v_options, "ttl");
|
349
|
+
v_assoc_id = rb_hash_aref2(v_options, "association_id");
|
350
|
+
|
351
|
+
if(NIL_P(v_stream))
|
352
|
+
stream = 0;
|
353
|
+
else
|
354
|
+
stream = NUM2INT(v_stream);
|
355
|
+
|
356
|
+
if(NIL_P(v_send_flags))
|
357
|
+
send_flags = 0;
|
358
|
+
else
|
359
|
+
send_flags = NUM2INT(v_send_flags);
|
360
|
+
|
361
|
+
if(NIL_P(v_ctrl_flags))
|
362
|
+
ctrl_flags = 0;
|
363
|
+
else
|
364
|
+
ctrl_flags = NUM2INT(v_ctrl_flags);
|
365
|
+
|
366
|
+
if(NIL_P(v_ttl)){
|
367
|
+
ttl = 0;
|
368
|
+
}
|
369
|
+
else{
|
370
|
+
ttl = NUM2INT(v_ttl);
|
371
|
+
send_flags |= SCTP_PR_SCTP_TTL;
|
372
|
+
}
|
373
|
+
|
374
|
+
if(NIL_P(v_ppid))
|
375
|
+
ppid = 0;
|
376
|
+
else
|
377
|
+
ppid = NUM2INT(v_ppid);
|
378
|
+
|
379
|
+
if(NIL_P(v_context))
|
380
|
+
context = 0;
|
381
|
+
else
|
382
|
+
context = NUM2INT(v_context);
|
383
|
+
|
384
|
+
if(NIL_P(v_assoc_id))
|
385
|
+
assoc_id = NUM2INT(rb_iv_get(self, "@association_id"));
|
386
|
+
else
|
387
|
+
assoc_id = NUM2INT(v_assoc_id);
|
388
|
+
|
389
|
+
info.sinfo_stream = stream;
|
390
|
+
info.sinfo_flags = send_flags;
|
391
|
+
info.sinfo_ppid = ppid;
|
392
|
+
info.sinfo_context = context;
|
393
|
+
info.sinfo_timetolive = ttl;
|
394
|
+
info.sinfo_assoc_id = assoc_id;
|
395
|
+
|
396
|
+
sock_fd = NUM2INT(rb_iv_get(self, "@sock_fd"));
|
397
|
+
|
398
|
+
num_bytes = sctp_send(
|
399
|
+
sock_fd,
|
400
|
+
StringValueCStr(v_msg),
|
401
|
+
RSTRING_LEN(v_msg),
|
402
|
+
&info,
|
403
|
+
ctrl_flags
|
404
|
+
);
|
405
|
+
|
406
|
+
if(num_bytes < 0)
|
407
|
+
rb_raise(rb_eSystemCallError, "sctp_send: %s", strerror(errno));
|
408
|
+
|
409
|
+
return INT2NUM(num_bytes);
|
410
|
+
}
|
411
|
+
|
299
412
|
/*
|
300
413
|
* Transmit a message to an SCTP endpoint. The following hash of options
|
301
414
|
* is permitted:
|
@@ -351,12 +464,15 @@ static VALUE rsctp_sendmsg(VALUE self, VALUE v_options){
|
|
351
464
|
if(NIL_P(v_flags))
|
352
465
|
flags = 0;
|
353
466
|
else
|
354
|
-
flags = NUM2INT(
|
467
|
+
flags = NUM2INT(v_flags);
|
355
468
|
|
356
|
-
if(NIL_P(v_ttl))
|
469
|
+
if(NIL_P(v_ttl)){
|
357
470
|
ttl = 0;
|
358
|
-
|
471
|
+
}
|
472
|
+
else{
|
359
473
|
ttl = NUM2INT(v_ttl);
|
474
|
+
flags |= SCTP_PR_SCTP_TTL;
|
475
|
+
}
|
360
476
|
|
361
477
|
if(NIL_P(v_ppid))
|
362
478
|
ppid = 0;
|
@@ -634,7 +750,8 @@ static VALUE rsctp_recvmsg(int argc, VALUE* argv, VALUE self){
|
|
634
750
|
UINT2NUM(sndrcvinfo.sinfo_context),
|
635
751
|
UINT2NUM(sndrcvinfo.sinfo_timetolive),
|
636
752
|
UINT2NUM(sndrcvinfo.sinfo_assoc_id),
|
637
|
-
v_notification
|
753
|
+
v_notification,
|
754
|
+
convert_sockaddr_in_to_struct(&clientaddr)
|
638
755
|
);
|
639
756
|
}
|
640
757
|
|
@@ -693,7 +810,7 @@ static VALUE rsctp_set_initmsg(VALUE self, VALUE v_options){
|
|
693
810
|
* as follows:
|
694
811
|
*
|
695
812
|
* :association
|
696
|
-
* - A change has occurred to an
|
813
|
+
* - A change has occurred to an association, either a new one has begun or an existing one has end.
|
697
814
|
*
|
698
815
|
* :address
|
699
816
|
* - The state of one of the peer's addresses has experienced a change.
|
@@ -853,7 +970,7 @@ void Init_socket(){
|
|
853
970
|
|
854
971
|
v_sndrcv_struct = rb_struct_define(
|
855
972
|
"SendReceiveInfo", "message", "stream", "flags",
|
856
|
-
"ppid", "context", "ttl", "association_id", "notification", NULL
|
973
|
+
"ppid", "context", "ttl", "association_id", "notification", "client", NULL
|
857
974
|
);
|
858
975
|
|
859
976
|
v_assoc_change_struct = rb_struct_define(
|
@@ -895,6 +1012,10 @@ void Init_socket(){
|
|
895
1012
|
"AuthEvent", "type", "length", "key_number", "indication", "association_id", NULL
|
896
1013
|
);
|
897
1014
|
|
1015
|
+
v_sockaddr_in_struct = rb_struct_define(
|
1016
|
+
"SockAddrIn", "family", "port", "address", NULL
|
1017
|
+
);
|
1018
|
+
|
898
1019
|
rb_define_method(cSocket, "initialize", rsctp_init, -1);
|
899
1020
|
|
900
1021
|
rb_define_method(cSocket, "bind", rsctp_bind, -1);
|
@@ -905,6 +1026,7 @@ void Init_socket(){
|
|
905
1026
|
rb_define_method(cSocket, "listen", rsctp_listen, -1);
|
906
1027
|
rb_define_method(cSocket, "peeloff!", rsctp_peeloff, 1);
|
907
1028
|
rb_define_method(cSocket, "recvmsg", rsctp_recvmsg, -1);
|
1029
|
+
rb_define_method(cSocket, "send", rsctp_send, 1);
|
908
1030
|
rb_define_method(cSocket, "sendmsg", rsctp_sendmsg, 1);
|
909
1031
|
rb_define_method(cSocket, "set_initmsg", rsctp_set_initmsg, 1);
|
910
1032
|
rb_define_method(cSocket, "shutdown", rsctp_shutdown, -1);
|
@@ -916,6 +1038,25 @@ void Init_socket(){
|
|
916
1038
|
rb_define_attr(cSocket, "association_id", 1, 1);
|
917
1039
|
rb_define_attr(cSocket, "port", 1, 1);
|
918
1040
|
|
919
|
-
/* 0.0.
|
920
|
-
rb_define_const(cSocket, "VERSION", rb_str_new2("0.0.
|
1041
|
+
/* 0.0.4: The version of this library */
|
1042
|
+
rb_define_const(cSocket, "VERSION", rb_str_new2("0.0.4"));
|
1043
|
+
|
1044
|
+
/* send flags */
|
1045
|
+
|
1046
|
+
/* Message is unordered */
|
1047
|
+
rb_define_const(cSocket, "SCTP_UNORDERED", INT2NUM(SCTP_UNORDERED));
|
1048
|
+
|
1049
|
+
/* Override the primary address */
|
1050
|
+
rb_define_const(cSocket, "SCTP_ADDR_OVER", INT2NUM(SCTP_ADDR_OVER));
|
1051
|
+
|
1052
|
+
/* Send an ABORT to peer */
|
1053
|
+
rb_define_const(cSocket, "SCTP_ABORT", INT2NUM(SCTP_ABORT));
|
1054
|
+
|
1055
|
+
/* Start a shutdown procedure */
|
1056
|
+
rb_define_const(cSocket, "SCTP_EOF", INT2NUM(SCTP_EOF));
|
1057
|
+
|
1058
|
+
/* Send to all associations */
|
1059
|
+
rb_define_const(cSocket, "SCTP_SENDALL", INT2NUM(SCTP_SENDALL));
|
1060
|
+
|
1061
|
+
rb_define_const(cSocket, "MSG_NOTIFICATION", INT2NUM(MSG_NOTIFICATION));
|
921
1062
|
}
|
data/sctp-socket.gemspec
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'sctp-socket'
|
3
|
-
spec.version = '0.0.
|
3
|
+
spec.version = '0.0.4'
|
4
4
|
spec.author = 'Daniel Berger'
|
5
5
|
spec.email = 'djberg96@gmail.com'
|
6
6
|
spec.summary = 'Ruby bindings for SCTP sockets'
|
7
|
-
spec.description = 'Ruby bindings for SCTP sockets'
|
8
7
|
spec.homepage = 'https://github.com/djberg96/sctp-socket'
|
9
8
|
spec.license = 'Apache-2.0'
|
10
9
|
spec.cert_chain = ['certs/djberg96_pub.pem']
|
@@ -15,8 +14,14 @@ Gem::Specification.new do |spec|
|
|
15
14
|
|
16
15
|
spec.extensions = ['ext/sctp/extconf.rb']
|
17
16
|
|
18
|
-
spec.add_development_dependency 'bundler'
|
19
|
-
spec.add_development_dependency 'rake'
|
20
|
-
spec.add_development_dependency 'rake-compiler'
|
21
|
-
spec.add_development_dependency 'rspec'
|
17
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
18
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
19
|
+
spec.add_development_dependency 'rake-compiler', '~> 1.1'
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
21
|
+
|
22
|
+
spec.description = <<-EOF
|
23
|
+
The sctp-socket library provides Ruby bindings for SCTP sockets. is a
|
24
|
+
message oriented, reliable transport protocol with direct support for
|
25
|
+
multihoming.
|
26
|
+
EOF
|
22
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sctp-socket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Berger
|
@@ -35,65 +35,68 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-12-
|
38
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: bundler
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '2.1'
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2.1'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: rake
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
60
|
+
version: '13.0'
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
67
|
+
version: '13.0'
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: rake-compiler
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '1.1'
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '1.1'
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rspec
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '3.9'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
96
|
-
description:
|
95
|
+
version: '3.9'
|
96
|
+
description: |2
|
97
|
+
The sctp-socket library provides Ruby bindings for SCTP sockets. is a
|
98
|
+
message oriented, reliable transport protocol with direct support for
|
99
|
+
multihoming.
|
97
100
|
email: djberg96@gmail.com
|
98
101
|
executables: []
|
99
102
|
extensions:
|
metadata.gz.sig
CHANGED
Binary file
|