Rev 4327 | Rev 4350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4327 | Rev 4332 | ||
|---|---|---|---|
| Line 280... | Line 280... | ||
| 280 | if( index < 0 ){ |
280 | if( index < 0 ){ |
| 281 | rwlock_write_unlock( & arp_globals.lock ); |
281 | rwlock_write_unlock( & arp_globals.lock ); |
| 282 | free( proto ); |
282 | free( proto ); |
| 283 | return index; |
283 | return index; |
| 284 | } |
284 | } |
| - | 285 | printf( "New protocol added:\n\tdevice id\t= %d\n\tproto\t= %d", device_id, protocol ); |
|
| 285 | } |
286 | } |
| 286 | printf( "Cache of the existing device %d cleaned\n", device->device_id ); |
- | |
| 287 | }else{ |
287 | }else{ |
| 288 | index = hardware_map( service ); |
288 | index = hardware_map( service ); |
| 289 | if( ! index ) return ENOENT; |
289 | if( ! index ) return ENOENT; |
| 290 | // create a new device |
290 | // create a new device |
| 291 | device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
291 | device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
| Line 348... | Line 348... | ||
| 348 | free( device->broadcast_data ); |
348 | free( device->broadcast_data ); |
| 349 | arp_protos_destroy( & device->protos ); |
349 | arp_protos_destroy( & device->protos ); |
| 350 | free( device ); |
350 | free( device ); |
| 351 | return ERROR_CODE; |
351 | return ERROR_CODE; |
| 352 | } |
352 | } |
| 353 | printf( "New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n", device->device_id, device->hardware, device->service ); |
353 | printf( "New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n\tproto\t= %d\n", device->device_id, device->hardware, device->service, protocol ); |
| 354 | } |
354 | } |
| 355 | rwlock_write_unlock( & arp_globals.lock ); |
355 | rwlock_write_unlock( & arp_globals.lock ); |
| 356 | return EOK; |
356 | return EOK; |
| 357 | } |
357 | } |
| 358 | 358 | ||
| Line 430... | Line 430... | ||
| 430 | return EINVAL; |
430 | return EINVAL; |
| 431 | } |
431 | } |
| 432 | memcpy( hw_source->value, src_hw, hw_source->length ); |
432 | memcpy( hw_source->value, src_hw, hw_source->length ); |
| 433 | } |
433 | } |
| 434 | // is my protocol address? |
434 | // is my protocol address? |
| 435 | if( proto->addr->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )){ |
435 | if( proto->addr->length != CONVERT_SIZE( uint8_t, char, header->protocol_length )){ |
| 436 | return EINVAL; |
436 | return EINVAL; |
| 437 | } |
437 | } |
| 438 | if( ! str_lcmp( proto->addr->value, ( char * ) des_proto, proto->addr->length )){ |
438 | if( ! str_lcmp( proto->addr->value, ( char * ) des_proto, proto->addr->length )){ |
| 439 | // not already upadted? |
439 | // not already upadted? |
| 440 | if( ! hw_source ){ |
440 | if( ! hw_source ){ |
| Line 444... | Line 444... | ||
| 444 | } |
444 | } |
| 445 | if( ntohs( header->operation ) == ARPOP_REQUEST ){ |
445 | if( ntohs( header->operation ) == ARPOP_REQUEST ){ |
| 446 | header->operation = htons( ARPOP_REPLY ); |
446 | header->operation = htons( ARPOP_REPLY ); |
| 447 | memcpy( des_proto, src_proto, header->protocol_length ); |
447 | memcpy( des_proto, src_proto, header->protocol_length ); |
| 448 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
448 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
| 449 | memcpy( src_hw, des_hw, header->hardware_length ); |
449 | memcpy( src_hw, device->addr->value, device->addr_len ); |
| 450 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
450 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
| 451 | packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
451 | packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
| 452 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
452 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
| 453 | }else{ |
453 | }else{ |
| 454 | pq_release( arp_globals.net_phone, packet_get_id( packet )); |
454 | pq_release( arp_globals.net_phone, packet_get_id( packet )); |