Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4727 → Rev 4728

/branches/network/uspace/srv/net/tl/udp/udp.c
271,7 → 271,7
// get udp header
header = ( udp_header_ref )( data + offset );
// find the destination socket
socket = socket_ports_find( & udp_globals.sockets, ntohs( header->dest ));
socket = socket_ports_find( & udp_globals.sockets, ntohs( header->destination_port ));
if( ! socket ){
tl_send_icmp_port_unreachable( udp_globals.net_phone, udp_globals.icmp_phone, packet, error );
return EADDRNOTAVAIL;
281,9 → 281,9
// count the received packet fragments
next_packet = packet;
fragments = 0;
total_length = ntohs( header->len );
total_length = ntohs( header->total_length );
// compute header checksum if set
if( header->check && ( ! error )){
if( header->checksum && ( ! error )){
result = packet_get_addr( packet, ( uint8_t ** ) & src, ( uint8_t ** ) & dest );
if( result <= 0 ){
return udp_release_and_return( packet, result );
296,7 → 296,7
free( ip_header );
}
}else{
header->check = 0;
header->checksum = 0;
checksum = 0;
}
do{
310,7 → 310,7
return udp_release_and_return( packet, ERROR_CODE );
}
// add partial checksum if set
if( header->check ){
if( header->checksum ){
checksum = compute_checksum( checksum, packet_get_data( packet ), packet_get_data_length( packet ));
}
// relese the rest of the packet fragments
325,16 → 325,16
}
total_length -= length;
// add partial checksum if set
if( header->check ){
if( header->checksum ){
checksum = compute_checksum( checksum, packet_get_data( packet ), packet_get_data_length( packet ));
}
}while(( next_packet = pq_next( next_packet )) && ( total_length > 0 ));
// check checksum
if( header->check ){
if( header->checksum ){
if( flip_checksum( compact_checksum( checksum ))){
// TODO checksum error ICMP?
// TODO remove debug dump
printf("udp check failed %x => %x\n", header->check, flip_checksum( compact_checksum( checksum )));
printf("udp check failed %x => %x\n", header->checksum, flip_checksum( compact_checksum( checksum )));
return udp_release_and_return( packet, EINVAL );
}
}
536,10 → 536,10
}
}
// set the udp header
header->source = htons( socket->port );
header->dest = htons( dest_port );
header->len = htons( total_length + sizeof( udp_header_t ));
header->check = 0;
header->source_port = htons( socket->port );
header->destination_port = htons( dest_port );
header->total_length = htons( total_length + sizeof( udp_header_t ));
header->checksum = 0;
if( udp_globals.checksum_computing ){
if( ERROR_OCCURRED( ip_get_route_req( udp_globals.ip_phone, IPPROTO_UDP, addr, addrlen, & device_id, & ip_header, & headerlen ))){
return udp_release_and_return( packet, ERROR_CODE );
554,7 → 554,7
printf( "ip_header:\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", headerlen, data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ] );
*/ checksum = compute_checksum( checksum, ip_header, headerlen );
checksum = compute_checksum( checksum, ( uint8_t * ) header, sizeof( * header ));
header->check = htons( flip_checksum( compact_checksum( checksum )));
header->checksum = htons( flip_checksum( compact_checksum( checksum )));
free( ip_header );
}else{
device_id = -1;
600,7 → 600,7
 
// set the source address port
result = packet_get_addr( packet, ( uint8_t ** ) & addr, NULL );
if( ERROR_OCCURRED( tl_set_address_port( addr, result, ntohs( header->source )))){
if( ERROR_OCCURRED( tl_set_address_port( addr, result, ntohs( header->source_port )))){
pq_release( udp_globals.net_phone, packet_id );
return ERROR_CODE;
}