Subversion Repositories HelenOS

Rev

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

Rev 4307 Rev 4395
Line 83... Line 83...
83
packet_id_t packet_get_id( const packet_t packet ){
83
packet_id_t packet_get_id( const packet_t packet ){
84
    return packet_is_valid( packet ) ? packet->packet_id : 0;
84
    return packet_is_valid( packet ) ? packet->packet_id : 0;
85
}
85
}
86
 
86
 
87
int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest ){
87
int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest ){
88
    if( !( packet_is_valid( packet ) && src && dest )) return EINVAL;
88
    if( ! packet_is_valid( packet )) return EINVAL;
89
    if( ! packet->addr_len ) return 0;
89
    if( ! packet->addr_len ) return 0;
90
    * src = ( void * ) packet + packet->src_addr;
90
    if( src ) * src = ( void * ) packet + packet->src_addr;
91
    * dest = ( void * ) packet + packet->dest_addr;
91
    if( dest ) * dest = ( void * ) packet + packet->dest_addr;
92
    return packet->addr_len;
92
    return packet->addr_len;
93
}
93
}
94
 
94
 
95
size_t packet_get_data_length( const packet_t packet ){
95
size_t packet_get_data_length( const packet_t packet ){
96
    if( ! packet_is_valid( packet )) return 0;
96
    if( ! packet_is_valid( packet )) return 0;
Line 102... Line 102...
102
    return ( void * ) packet + packet->data_start;
102
    return ( void * ) packet + packet->data_start;
103
}
103
}
104
 
104
 
105
int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){
105
int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){
106
    size_t  padding;
106
    size_t  padding;
-
 
107
    size_t  allocated;
107
 
108
 
108
    if( ! packet_is_valid( packet )) return EINVAL;
109
    if( ! packet_is_valid( packet )) return EINVAL;
-
 
110
    allocated = packet->dest_addr - packet->src_addr;
109
    if( packet->addr_len < addr_len ) return ENOMEM;
111
    if( allocated < addr_len ) return ENOMEM;
-
 
112
    padding = allocated - addr_len;
110
    padding = packet->addr_len - addr_len;
113
    packet->addr_len = addr_len;
111
    if( src ){
114
    if( src ){
112
        memcpy(( void * ) packet + packet->src_addr, src, addr_len );
115
        memcpy(( void * ) packet + packet->src_addr, src, addr_len );
113
        if( padding ) bzero(( void * ) packet + packet->src_addr + addr_len, padding );
116
        if( padding ) bzero(( void * ) packet + packet->src_addr + addr_len, padding );
114
    }else{
117
    }else{
115
        bzero(( void * ) packet + packet->src_addr + addr_len, packet->addr_len );
118
        bzero(( void * ) packet + packet->src_addr, allocated );
116
    }
119
    }
117
    if( dest ){
120
    if( dest ){
118
        memcpy(( void * ) packet + packet->dest_addr, dest, addr_len );
121
        memcpy(( void * ) packet + packet->dest_addr, dest, addr_len );
119
        if( padding ) bzero(( void * ) packet + packet->dest_addr + addr_len, padding );
122
        if( padding ) bzero(( void * ) packet + packet->dest_addr + addr_len, padding );
120
    }else{
123
    }else{
121
        bzero(( void * ) packet + packet->dest_addr + addr_len, packet->addr_len );
124
        bzero(( void * ) packet + packet->dest_addr, allocated );
122
    }
125
    }
123
    return EOK;
126
    return EOK;
124
}
127
}
125
 
128
 
126
/** @}
129
/** @}