ext/sctp/socket.c
/*
 * Connect the socket to a multihomed peer via the provided array of addresses
 * using the domain specified in the constructor. You must also specify the port.
 *
 * Example:
 *
 *   socket = SCTP::Socket.new
 *   socket.connect(:port => 62354, :addresses => ['10.0.4.5', '10.0.5.5'])
 *
 * Note that this will also set/update the object's association_id.
 */
Connect the socket to a multihomed peer via the provided array of addresses
using the domain specified in the constructor. You must also specify the port.





Note that this will also set/update the object's association_id.
Connect the socket to a multihomed peer via the provided array of addresses using the domain specified in the constructor . You must also specify the port . Note that this will also set / update the object ' s association_id .
static VALUE rsctp_connect(int argc, VALUE* argv, VALUE self){
  struct sockaddr_in addrs[8];
  int i, num_ip, sock_fd;
  sctp_assoc_t assoc;
  VALUE v_address, v_domain, v_options, v_addresses, v_port;
  rb_scan_args(argc, argv, "01", &v_options);
  if(NIL_P(v_options))
    rb_raise(rb_eArgError, "you must specify an array of addresses");
  Check_Type(v_options, T_HASH);
  v_addresses = rb_hash_aref2(v_options, "addresses");
  v_port = rb_hash_aref2(v_options, "port");
  if(NIL_P(v_addresses) || RARRAY_LEN(v_addresses) == 0)
    rb_raise(rb_eArgError, "you must specify an array of addresses containing at least one address");
  if(NIL_P(v_port))
    rb_raise(rb_eArgError, "you must specify a port");
  v_domain = rb_iv_get(self, "@domain");
  num_ip = RARRAY_LEN(v_addresses);
  bzero(&addrs, sizeof(addrs));
  for(i = 0; i < num_ip; i++){
    v_address = RARRAY_PTR(v_addresses)[i];
    addrs[i].sin_family = NUM2INT(v_domain);
    addrs[i].sin_port = htons(NUM2INT(v_port));
    addrs[i].sin_addr.s_addr = inet_addr(StringValueCStr(v_address));
  }
  sock_fd = NUM2INT(rb_iv_get(self, "@sock_fd"));
  if(sctp_connectx(sock_fd, (struct sockaddr *) addrs, num_ip, &assoc) < 0)
    rb_raise(rb_eSystemCallError, "sctp_connectx: %s", strerror(errno));
  rb_iv_set(self, "@association_id", INT2NUM(assoc));
  return self;
}
static VALUE rsctp_connect ( int argc , VALUE * argv , VALUE self ) { struct sockaddr_in addrs [ 8 ] ; int i , num_ip , sock_fd ; sctp_assoc_t assoc ; VALUE v_address , v_domain , v_options , v_addresses , v_port ; rb_scan_args ( argc , argv , " " , & v_options ) ; if ( NIL_P ( v_options ) ) rb_raise ( rb_eArgError , " " ) ; Check_Type ( v_options , T_HASH ) ; v_addresses = rb_hash_aref2 ( v_options , " " ) ; v_port = rb_hash_aref2 ( v_options , " " ) ; if ( NIL_P ( v_addresses ) || RARRAY_LEN ( v_addresses ) == 0 ) rb_raise ( rb_eArgError , " " ) ; if ( NIL_P ( v_port ) ) rb_raise ( rb_eArgError , " " ) ; v_domain = rb_iv_get ( self , " " ) ; num_ip = RARRAY_LEN ( v_addresses ) ; bzero ( & addrs , sizeof ( addrs ) ) ; for ( i = 0 ; i < num_ip ; i ++ ) { v_address = RARRAY_PTR ( v_addresses ) [ i ] ; addrs [ i ] . sin_family = NUM2INT ( v_domain ) ; addrs [ i ] . sin_port = htons ( NUM2INT ( v_port ) ) ; addrs [ i ] . sin_addr . s_addr = inet_addr ( StringValueCStr ( v_address ) ) ; } sock_fd = NUM2INT ( rb_iv_get ( self , " " ) ) ; if ( sctp_connectx ( sock_fd , ( struct sockaddr * ) addrs , num_ip , & assoc ) < 0 ) rb_raise ( rb_eSystemCallError , " " , strerror ( errno ) ) ; rb_iv_set ( self , " " , INT2NUM ( assoc ) ) ; return self ; }
Connect the socket to a multihomed peer via the provided array of addresses
 using the domain specified in the constructor.
Connect the socket to a multihomed peer via the provided array of addresses using the domain specified in the constructor .