ext/sctp/socket.c
/*
 * Return an array of local addresses that are part of the association.
 *
 * Example:
 *
 *  socket = SCTP::Socket.new
 *  socket.bind(:addresses => ['10.0.4.5', '10.0.5.5'])
 *  socket.getlocalnames # => ['10.0.4.5', '10.0.5.5'])
 */
Return an array of local addresses that are part of the association.
Example.


Return an array of local addresses that are part of the association . Example .
static VALUE rsctp_getlocalnames(VALUE self){
  sctp_assoc_t assoc_id;
  struct sockaddr* addrs;
  int i, sock_fd, num_addrs;
  char str[16];
  VALUE v_array = rb_ary_new();
  bzero(&addrs, sizeof(addrs));
  sock_fd = NUM2INT(rb_iv_get(self, "@sock_fd"));
  assoc_id = NUM2INT(rb_iv_get(self, "@association_id"));
  num_addrs = sctp_getladdrs(sock_fd, assoc_id, &addrs);
  if(num_addrs < 0){
    sctp_freeladdrs(addrs);
    rb_raise(rb_eSystemCallError, "sctp_getladdrs: %s", strerror(errno));
  }
  for(i = 0; i < num_addrs; i++){
    inet_ntop(AF_INET, &(((struct sockaddr_in *)&addrs[i])->sin_addr), str, sizeof(str));
    rb_ary_push(v_array, rb_str_new2(str));
    bzero(&str, sizeof(str));
  }
  sctp_freeladdrs(addrs);
  return v_array;
}
static VALUE rsctp_getlocalnames ( VALUE self ) { sctp_assoc_t assoc_id ; struct sockaddr * addrs ; int i , sock_fd , num_addrs ; char str [ 16 ] ; VALUE v_array = rb_ary_new ( ) ; bzero ( & addrs , sizeof ( addrs ) ) ; sock_fd = NUM2INT ( rb_iv_get ( self , " " ) ) ; assoc_id = NUM2INT ( rb_iv_get ( self , " " ) ) ; num_addrs = sctp_getladdrs ( sock_fd , assoc_id , & addrs ) ; if ( num_addrs < 0 ) { sctp_freeladdrs ( addrs ) ; rb_raise ( rb_eSystemCallError , " " , strerror ( errno ) ) ; } for ( i = 0 ; i < num_addrs ; i ++ ) { inet_ntop ( AF_INET , & ( ( ( struct sockaddr_in * ) & addrs [ i ] ) -> sin_addr ) , str , sizeof ( str ) ) ; rb_ary_push ( v_array , rb_str_new2 ( str ) ) ; bzero ( & str , sizeof ( str ) ) ; } sctp_freeladdrs ( addrs ) ; return v_array ; }
Return an array of local addresses that are part of the association.
Return an array of local addresses that are part of the association .