Rev 4505 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4505 | Rev 4731 | ||
---|---|---|---|
Line 69... | Line 69... | ||
69 | return ( void * ) packet + packet->data_end - length; |
69 | return ( void * ) packet + packet->data_end - length; |
70 | } |
70 | } |
71 | 71 | ||
72 | int packet_trim( packet_t packet, size_t prefix, size_t suffix ){ |
72 | int packet_trim( packet_t packet, size_t prefix, size_t suffix ){ |
73 | if( ! packet_is_valid( packet )) return EINVAL; |
73 | if( ! packet_is_valid( packet )) return EINVAL; |
74 | if( prefix + suffix > packet->data_end - packet->data_start ) return ENOMEM; |
74 | if( prefix + suffix > PACKET_DATA_LENGTH( packet )) return ENOMEM; |
75 | packet->data_start += prefix; |
75 | packet->data_start += prefix; |
76 | packet->data_end -= suffix; |
76 | packet->data_end -= suffix; |
77 | return EOK; |
77 | return EOK; |
78 | } |
78 | } |
79 | 79 | ||
Line 89... | Line 89... | ||
89 | return packet->addr_len; |
89 | return packet->addr_len; |
90 | } |
90 | } |
91 | 91 | ||
92 | size_t packet_get_data_length( const packet_t packet ){ |
92 | size_t packet_get_data_length( const packet_t packet ){ |
93 | if( ! packet_is_valid( packet )) return 0; |
93 | if( ! packet_is_valid( packet )) return 0; |
94 | return packet->data_end - packet->data_start; |
94 | return PACKET_DATA_LENGTH( packet ); |
95 | } |
95 | } |
96 | 96 | ||
97 | void * packet_get_data( const packet_t packet ){ |
97 | void * packet_get_data( const packet_t packet ){ |
98 | if( ! packet_is_valid( packet )) return NULL; |
98 | if( ! packet_is_valid( packet )) return NULL; |
99 | return ( void * ) packet + packet->data_start; |
99 | return ( void * ) packet + packet->data_start; |
Line 102... | Line 102... | ||
102 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){ |
102 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){ |
103 | size_t padding; |
103 | size_t padding; |
104 | size_t allocated; |
104 | size_t allocated; |
105 | 105 | ||
106 | if( ! packet_is_valid( packet )) return EINVAL; |
106 | if( ! packet_is_valid( packet )) return EINVAL; |
107 | allocated = packet->dest_addr - packet->src_addr; |
107 | allocated = PACKET_MAX_ADDRESS_LENGTH( packet ); |
108 | if( allocated < addr_len ) return ENOMEM; |
108 | if( allocated < addr_len ) return ENOMEM; |
109 | padding = allocated - addr_len; |
109 | padding = allocated - addr_len; |
110 | packet->addr_len = addr_len; |
110 | packet->addr_len = addr_len; |
111 | if( src ){ |
111 | if( src ){ |
112 | memcpy(( void * ) packet + packet->src_addr, src, addr_len ); |
112 | memcpy(( void * ) packet + packet->src_addr, src, addr_len ); |
Line 121... | Line 121... | ||
121 | bzero(( void * ) packet + packet->dest_addr, allocated ); |
121 | bzero(( void * ) packet + packet->dest_addr, allocated ); |
122 | } |
122 | } |
123 | return EOK; |
123 | return EOK; |
124 | } |
124 | } |
125 | 125 | ||
- | 126 | packet_t packet_get_copy( int phone, packet_t packet ){ |
|
- | 127 | packet_t copy; |
|
- | 128 | uint8_t * src; |
|
- | 129 | uint8_t * dest; |
|
- | 130 | size_t addrlen; |
|
- | 131 | ||
- | 132 | if( ! packet_is_valid( packet )) return NULL; |
|
- | 133 | // get a new packet |
|
- | 134 | copy = packet_get_4( phone, PACKET_DATA_LENGTH( packet ), PACKET_MAX_ADDRESS_LENGTH( packet ), packet->max_prefix, PACKET_MIN_SUFFIX( packet )); |
|
- | 135 | if( ! copy ) return NULL; |
|
- | 136 | // get addresses |
|
- | 137 | addrlen = packet_get_addr( packet, & src, & dest ); |
|
- | 138 | // copy data |
|
- | 139 | if(( packet_copy_data( copy, packet_get_data( packet ), PACKET_DATA_LENGTH( packet )) == EOK ) |
|
- | 140 | // copy addresses if present |
|
- | 141 | && (( addrlen <= 0 ) || ( packet_set_addr( copy, src, dest, addrlen ) == EOK ))){ |
|
- | 142 | copy->order = packet->order; |
|
- | 143 | copy->metric = packet->metric; |
|
- | 144 | return copy; |
|
- | 145 | }else{ |
|
- | 146 | pq_release( phone, copy->packet_id ); |
|
- | 147 | return NULL; |
|
- | 148 | } |
|
- | 149 | } |
|
- | 150 | ||
126 | /** @} |
151 | /** @} |
127 | */ |
152 | */ |