ruby/trema/vendor.c in trema-0.2.6 vs ruby/trema/vendor.c in trema-0.2.7
- old
+ new
@@ -108,11 +108,11 @@
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
if ( tmp != Qnil ) {
Check_Type( tmp, T_ARRAY );
uint16_t length = ( uint16_t ) RARRAY_LEN( tmp );
append_back_buffer( vendor, length );
- set_length( vendor, length );
+ set_length( vendor, ( uint16_t ) ( sizeof( struct ofp_vendor_header ) + length ) );
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
int i;
for ( i = 0; i < length; i++ ) {
data[ i ] = ( uint8_t ) FIX2INT( RARRAY_PTR( tmp )[ i ] );
}
@@ -163,11 +163,11 @@
uint16_t length = get_length( vendor );
if ( length > 0 ) {
VALUE data_array = rb_ary_new2( length );
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
- int i;
+ long i;
for ( i = 0; i < length; i++ ) {
rb_ary_push( data_array, INT2FIX( data[ i ] ) );
}
return data_array;
}
@@ -203,11 +203,16 @@
rb_hash_aset( attributes, ID2SYM( rb_intern( "datapath_id" ) ), ULL2NUM( datapath_id ) );
rb_hash_aset( attributes, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
rb_hash_aset( attributes, ID2SYM( rb_intern( "vendor" ) ), UINT2NUM( vendor ) );
- if ( data->length ) {
- rb_hash_aset( attributes, ID2SYM( rb_intern( "data" ) ), rb_str_new( data->data, ( long ) data->length ) );
+ if ( data != NULL && data->length > 0 ) {
+ VALUE data_array = rb_ary_new2( ( long ) data->length );
+ long i;
+ for ( i = 0; i < data->length; i++ ) {
+ rb_ary_push( data_array, INT2FIX( ( ( uint8_t * ) data->data)[ i ] ) );
+ }
+ rb_hash_aset( attributes, ID2SYM( rb_intern( "data" ) ), data_array );
}
VALUE vendor_r = rb_funcall( cVendor, rb_intern( "new" ), 1, attributes );
rb_funcall( controller, rb_intern( "vendor" ), 2, ULL2NUM( datapath_id ), vendor_r );
}