Changeset ec1bdc8 in mainline for uspace/lib/socket/packet/packet_client.c
- Timestamp:
- 2010-09-26T18:57:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3fe57ea7
- Parents:
- 2a786f9 (diff), 70ce016 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/socket/packet/packet_client.c
r2a786f9 rec1bdc8 46 46 #include <packet/packet_client.h> 47 47 48 int packet_copy_data(packet_t packet, const void * data, size_t length){ 49 if(! packet_is_valid(packet)){ 50 return EINVAL; 51 } 52 if(packet->data_start + length >= packet->length){ 48 int packet_copy_data(packet_t packet, const void * data, size_t length) 49 { 50 if (!packet_is_valid(packet)) 51 return EINVAL; 52 53 if (packet->data_start + length >= packet->length) 53 54 return ENOMEM; 54 } 55 55 56 memcpy((void *) packet + packet->data_start, data, length); 56 if (packet->data_start + length > packet->data_end){57 if (packet->data_start + length > packet->data_end) 57 58 packet->data_end = packet->data_start + length; 58 } 59 59 60 return EOK; 60 61 } 61 62 62 void * packet_prefix(packet_t packet, size_t length){ 63 if((! packet_is_valid(packet)) || (packet->data_start - sizeof(struct packet) - 2 * (packet->dest_addr - packet->src_addr) < length)){ 64 return NULL; 65 } 63 void *packet_prefix(packet_t packet, size_t length) 64 { 65 if ((!packet_is_valid(packet)) || 66 (packet->data_start - sizeof(struct packet) - 67 2 * (packet->dest_addr - packet->src_addr) < length)) { 68 return NULL; 69 } 70 66 71 packet->data_start -= length; 67 72 return (void *) packet + packet->data_start; 68 73 } 69 74 70 void * packet_suffix(packet_t packet, size_t length){ 71 if((! packet_is_valid(packet)) || (packet->data_end + length >= packet->length)){ 72 return NULL; 73 } 75 void *packet_suffix(packet_t packet, size_t length) 76 { 77 if ((!packet_is_valid(packet)) || 78 (packet->data_end + length >= packet->length)) { 79 return NULL; 80 } 81 74 82 packet->data_end += length; 75 83 return (void *) packet + packet->data_end - length; 76 84 } 77 85 78 int packet_trim(packet_t packet, size_t prefix, size_t suffix){ 79 if(! packet_is_valid(packet)){ 80 return EINVAL; 81 } 82 if(prefix + suffix > PACKET_DATA_LENGTH(packet)){ 86 int packet_trim(packet_t packet, size_t prefix, size_t suffix) 87 { 88 if (!packet_is_valid(packet)) 89 return EINVAL; 90 91 if (prefix + suffix > PACKET_DATA_LENGTH(packet)) 83 92 return ENOMEM; 84 } 93 85 94 packet->data_start += prefix; 86 95 packet->data_end -= suffix; … … 88 97 } 89 98 90 packet_id_t packet_get_id(const packet_t packet){ 99 packet_id_t packet_get_id(const packet_t packet) 100 { 91 101 return packet_is_valid(packet) ? packet->packet_id : 0; 92 102 } 93 103 94 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest) {95 if(! packet_is_valid(packet)){96 return EINVAL;97 }98 if (! packet->addr_len){104 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest) 105 { 106 if (!packet_is_valid(packet)) 107 return EINVAL; 108 if (!packet->addr_len) 99 109 return 0; 100 } 101 if(src){ 110 if (src) 102 111 *src = (void *) packet + packet->src_addr; 103 } 104 if(dest){ 112 if (dest) 105 113 *dest = (void *) packet + packet->dest_addr; 106 } 114 107 115 return packet->addr_len; 108 116 } 109 117 110 size_t packet_get_data_length(const packet_t packet){ 111 if(! packet_is_valid(packet)){ 118 size_t packet_get_data_length(const packet_t packet) 119 { 120 if (!packet_is_valid(packet)) 112 121 return 0; 113 } 122 114 123 return PACKET_DATA_LENGTH(packet); 115 124 } 116 125 117 void * packet_get_data(const packet_t packet){ 118 if(! packet_is_valid(packet)){ 119 return NULL; 120 } 126 void *packet_get_data(const packet_t packet) 127 { 128 if (!packet_is_valid(packet)) 129 return NULL; 130 121 131 return (void *) packet + packet->data_start; 122 132 } … … 160 170 } 161 171 162 packet_t packet_get_copy(int phone, packet_t packet){ 172 packet_t packet_get_copy(int phone, packet_t packet) 173 { 163 174 packet_t copy; 164 175 uint8_t * src = NULL; … … 166 177 size_t addrlen; 167 178 168 if (! packet_is_valid(packet)){169 return NULL; 170 } 179 if (!packet_is_valid(packet)) 180 return NULL; 181 171 182 // get a new packet 172 copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet)); 173 if(! copy){ 174 return NULL; 175 } 183 copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), 184 PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, 185 PACKET_MIN_SUFFIX(packet)); 186 if (!copy) 187 return NULL; 188 176 189 // get addresses 177 190 addrlen = packet_get_addr(packet, &src, &dest); 178 191 // copy data 179 if((packet_copy_data(copy, packet_get_data(packet), PACKET_DATA_LENGTH(packet)) == EOK) 180 // copy addresses if present 181 && ((addrlen <= 0) || (packet_set_addr(copy, src, dest, addrlen) == EOK))){ 192 if ((packet_copy_data(copy, packet_get_data(packet), 193 PACKET_DATA_LENGTH(packet)) == EOK) && 194 // copy addresses if present 195 ((addrlen <= 0) || 196 (packet_set_addr(copy, src, dest, addrlen) == EOK))) { 182 197 copy->order = packet->order; 183 198 copy->metric = packet->metric; 184 199 return copy; 185 } else{200 } else { 186 201 pq_release_local(phone, copy->packet_id); 187 202 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.