Subversion Repositories HelenOS

Rev

Rev 4707 | Rev 4711 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4707 Rev 4708
Line 231... Line 231...
231
    uint16_t    checksum;
231
    uint16_t    checksum;
232
 
232
 
233
    checksum = compact_checksum(compute_checksum( 0, data, length ));
233
    checksum = compact_checksum(compute_checksum( 0, data, length ));
234
 
234
 
235
    // flip, zero is returned as 0xFFFF (not flipped)
235
    // flip, zero is returned as 0xFFFF (not flipped)
236
    return ( ~ checksum ) ? ~ checksum : IP_HEADER_CHECKSUM_ZERO;
236
    return ( ~ checksum ) ? ( uint16_t ) ( ~ checksum ) : IP_HEADER_CHECKSUM_ZERO;
237
}
237
}
238
 
238
 
239
int ip_initialize( async_client_conn_t client_connection ){
239
int ip_initialize( async_client_conn_t client_connection ){
240
    ERROR_DECLARE;
240
    ERROR_DECLARE;
241
 
241
 
Line 904... Line 904...
904
    ip_header_ref   header;
904
    ip_header_ref   header;
905
    ip_header_ref   middle_header;
905
    ip_header_ref   middle_header;
906
    ip_header_ref   last_header;
906
    ip_header_ref   last_header;
907
    uint8_t *       src;
907
    uint8_t *       src;
908
    uint8_t *       dest;
908
    uint8_t *       dest;
909
    int             address_length;
909
    size_t          address_length;
-
 
910
    int             result;
910
 
911
 
911
    address_length = packet_get_addr( packet, & src, & dest );
912
    result = packet_get_addr( packet, & src, & dest );
912
    if( address_length <= 0 ) return EINVAL;
913
    if( result <= 0 ) return EINVAL;
-
 
914
    address_length = ( size_t ) result;
913
    if( packet_get_data_length( packet ) <= sizeof( ip_header_t )) return ENOMEM;
915
    if( packet_get_data_length( packet ) <= sizeof( ip_header_t )) return ENOMEM;
914
    // get header
916
    // get header
915
    header = ( ip_header_ref ) packet_get_data( packet );
917
    header = ( ip_header_ref ) packet_get_data( packet );
916
    if( ! header ) return EINVAL;
918
    if( ! header ) return EINVAL;
917
    // fragmentation forbidden?
919
    // fragmentation forbidden?
Line 992... Line 994...
992
    memcpy( last, first, sizeof( ip_header_t ));
994
    memcpy( last, first, sizeof( ip_header_t ));
993
    length = sizeof( ip_header_t );
995
    length = sizeof( ip_header_t );
994
    next = sizeof( ip_header_t );
996
    next = sizeof( ip_header_t );
995
    // process all ip options
997
    // process all ip options
996
    while( next < first->ihl ){
998
    while( next < first->ihl ){
997
        option = ( ip_option_ref ) ((( void * ) first ) + next );
999
        option = ( ip_option_ref ) ((( uint8_t * ) first ) + next );
998
        // skip end or noop
1000
        // skip end or noop
999
        if(( option->type == IPOPT_END ) || ( option->type == IPOPT_NOOP )){
1001
        if(( option->type == IPOPT_END ) || ( option->type == IPOPT_NOOP )){
1000
            ++ next;
1002
            ++ next;
1001
        }else{
1003
        }else{
1002
            // copy if said so or skip
1004
            // copy if said so or skip
1003
            if( IPOPT_COPIED( option->type )){
1005
            if( IPOPT_COPIED( option->type )){
1004
                memcpy((( void * ) last ) + length, (( void * ) first ) + next, option->length );
1006
                memcpy((( uint8_t * ) last ) + length, (( uint8_t * ) first ) + next, option->length );
1005
                length += option->length;
1007
                length += option->length;
1006
            }
1008
            }
1007
            // next option
1009
            // next option
1008
            next += option->length;
1010
            next += option->length;
1009
        }
1011
        }
1010
    }
1012
    }
1011
    // align 4 byte boundary
1013
    // align 4 byte boundary
1012
    if( length % 4 ){
1014
    if( length % 4 ){
1013
        bzero((( void * ) last ) + length, 4 - ( length % 4 ));
1015
        bzero((( uint8_t * ) last ) + length, 4 - ( length % 4 ));
1014
        last->ihl = length / 4 + 1;
1016
        last->ihl = length / 4 + 1;
1015
    }else{
1017
    }else{
1016
        last->ihl = length / 4;
1018
        last->ihl = length / 4;
1017
    }
1019
    }
1018
    last->header_checksum = 0;
1020
    last->header_checksum = 0;