Changes in uspace/lib/socket/packet/packet_client.c [29fa68b:7c8267b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/socket/packet/packet_client.c
r29fa68b r7c8267b 46 46 #include <packet/packet_client.h> 47 47 48 int packet_copy_data(packet_t packet, const void * data, size_t length) 49 { 50 if (!packet_is_valid(packet)) 48 int packet_copy_data(packet_t packet, const void * data, size_t length){ 49 if(! packet_is_valid(packet)){ 51 50 return EINVAL; 52 53 if (packet->data_start + length >= packet->length)51 } 52 if(packet->data_start + length >= packet->length){ 54 53 return ENOMEM; 55 54 } 56 55 memcpy((void *) packet + packet->data_start, data, length); 57 if (packet->data_start + length > packet->data_end)56 if(packet->data_start + length > packet->data_end){ 58 57 packet->data_end = packet->data_start + length; 59 58 } 60 59 return EOK; 61 60 } 62 61 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)) { 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)){ 68 64 return NULL; 69 65 } 70 71 66 packet->data_start -= length; 72 67 return (void *) packet + packet->data_start; 73 68 } 74 69 75 void *packet_suffix(packet_t packet, size_t length) 76 { 77 if ((!packet_is_valid(packet)) || 78 (packet->data_end + length >= packet->length)) { 70 void * packet_suffix(packet_t packet, size_t length){ 71 if((! packet_is_valid(packet)) || (packet->data_end + length >= packet->length)){ 79 72 return NULL; 80 73 } 81 82 74 packet->data_end += length; 83 75 return (void *) packet + packet->data_end - length; 84 76 } 85 77 86 int packet_trim(packet_t packet, size_t prefix, size_t suffix) 87 { 88 if (!packet_is_valid(packet)) 78 int packet_trim(packet_t packet, size_t prefix, size_t suffix){ 79 if(! packet_is_valid(packet)){ 89 80 return EINVAL; 90 91 if (prefix + suffix > PACKET_DATA_LENGTH(packet))81 } 82 if(prefix + suffix > PACKET_DATA_LENGTH(packet)){ 92 83 return ENOMEM; 93 84 } 94 85 packet->data_start += prefix; 95 86 packet->data_end -= suffix; … … 97 88 } 98 89 99 packet_id_t packet_get_id(const packet_t packet) 100 { 90 packet_id_t packet_get_id(const packet_t packet){ 101 91 return packet_is_valid(packet) ? packet->packet_id : 0; 102 92 } 103 93 104 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest) 105 { 106 if (!packet_is_valid(packet)) 94 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest){ 95 if(! packet_is_valid(packet)){ 107 96 return EINVAL; 108 if (!packet->addr_len) 97 } 98 if(! packet->addr_len){ 109 99 return 0; 110 if (src) 100 } 101 if(src){ 111 102 *src = (void *) packet + packet->src_addr; 112 if (dest) 103 } 104 if(dest){ 113 105 *dest = (void *) packet + packet->dest_addr; 114 106 } 115 107 return packet->addr_len; 116 108 } 117 109 118 size_t packet_get_data_length(const packet_t packet) 119 { 120 if (!packet_is_valid(packet)) 110 size_t packet_get_data_length(const packet_t packet){ 111 if(! packet_is_valid(packet)){ 121 112 return 0; 122 113 } 123 114 return PACKET_DATA_LENGTH(packet); 124 115 } 125 116 126 void *packet_get_data(const packet_t packet) 127 { 128 if (!packet_is_valid(packet)) 117 void * packet_get_data(const packet_t packet){ 118 if(! packet_is_valid(packet)){ 129 119 return NULL; 130 120 } 131 121 return (void *) packet + packet->data_start; 132 122 } … … 170 160 } 171 161 172 packet_t packet_get_copy(int phone, packet_t packet) 173 { 162 packet_t packet_get_copy(int phone, packet_t packet){ 174 163 packet_t copy; 175 164 uint8_t * src = NULL; … … 177 166 size_t addrlen; 178 167 179 if (!packet_is_valid(packet))168 if(! packet_is_valid(packet)){ 180 169 return NULL; 181 170 } 182 171 // get a new packet 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) 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){ 187 174 return NULL; 188 175 } 189 176 // get addresses 190 177 addrlen = packet_get_addr(packet, &src, &dest); 191 178 // copy data 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))) { 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))){ 197 182 copy->order = packet->order; 198 183 copy->metric = packet->metric; 199 184 return copy; 200 } else{185 }else{ 201 186 pq_release_local(phone, copy->packet_id); 202 187 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.