Changeset 03c971f in mainline for uspace/srv/net/ethip/pdu.c
- Timestamp:
- 2013-08-15T14:20:16Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bb2a5b2
- Parents:
- f2c19b0 (diff), 2921602 (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/srv/net/ethip/pdu.c
rf2c19b0 r03c971f 46 46 #include "pdu.h" 47 47 48 #define MAC48_BYTES 649 50 48 /** Encode Ethernet PDU. */ 51 49 int eth_pdu_encode(eth_frame_t *frame, void **rdata, size_t *rsize) … … 62 60 63 61 hdr = (eth_header_t *)data; 64 mac48_encode(&frame->src, hdr->src);65 mac48_encode(&frame->dest, hdr->dest);62 addr48(frame->src, hdr->src); 63 addr48(frame->dest, hdr->dest); 66 64 hdr->etype_len = host2uint16_t_be(frame->etype_len); 67 65 … … 69 67 frame->size); 70 68 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "Encoding Ethernet frame "72 "src=%" PRIx64 " dest=%" PRIx64 " etype=%x",73 frame->src.addr, frame->dest.addr, frame->etype_len);74 69 log_msg(LOG_DEFAULT, LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size); 75 70 … … 98 93 return ENOMEM; 99 94 100 mac48_decode(hdr->src, &frame->src);101 mac48_decode(hdr->dest, &frame->dest);95 addr48(hdr->src, frame->src); 96 addr48(hdr->dest, frame->dest); 102 97 frame->etype_len = uint16_t_be2host(hdr->etype_len); 103 98 … … 105 100 frame->size); 106 101 107 log_msg(LOG_DEFAULT, LVL_DEBUG, "Decoding Ethernet frame "108 "src=%" PRIx64 " dest=%" PRIx64 " etype=%x",109 frame->src.addr, frame->dest.addr, frame->etype_len);110 102 log_msg(LOG_DEFAULT, LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size); 111 103 112 104 return EOK; 113 }114 115 void mac48_encode(mac48_addr_t *addr, void *buf)116 {117 uint64_t val;118 uint8_t *bbuf = (uint8_t *)buf;119 int i;120 121 val = addr->addr;122 for (i = 0; i < MAC48_BYTES; i++)123 bbuf[i] = (val >> (8 * (MAC48_BYTES - i - 1))) & 0xff;124 }125 126 void mac48_decode(void *data, mac48_addr_t *addr)127 {128 uint64_t val;129 uint8_t *bdata = (uint8_t *)data;130 int i;131 132 val = 0;133 for (i = 0; i < MAC48_BYTES; i++)134 val |= (uint64_t)bdata[i] << (8 * (MAC48_BYTES - i - 1));135 136 addr->addr = val;137 105 } 138 106 … … 168 136 pfmt->proto_addr_size = IPV4_ADDR_SIZE; 169 137 pfmt->opcode = host2uint16_t_be(fopcode); 170 mac48_encode(&packet->sender_hw_addr, pfmt->sender_hw_addr);138 addr48(packet->sender_hw_addr, pfmt->sender_hw_addr); 171 139 pfmt->sender_proto_addr = 172 host2uint32_t_be(packet->sender_proto_addr .ipv4);173 mac48_encode(&packet->target_hw_addr, pfmt->target_hw_addr);140 host2uint32_t_be(packet->sender_proto_addr); 141 addr48(packet->target_hw_addr, pfmt->target_hw_addr); 174 142 pfmt->target_proto_addr = 175 host2uint32_t_be(packet->target_proto_addr .ipv4);143 host2uint32_t_be(packet->target_proto_addr); 176 144 177 145 *rdata = data; … … 227 195 } 228 196 229 mac48_decode(pfmt->sender_hw_addr, &packet->sender_hw_addr);230 packet->sender_proto_addr .ipv4=197 addr48(pfmt->sender_hw_addr, packet->sender_hw_addr); 198 packet->sender_proto_addr = 231 199 uint32_t_be2host(pfmt->sender_proto_addr); 232 mac48_decode(pfmt->target_hw_addr, &packet->target_hw_addr);233 packet->target_proto_addr .ipv4=200 addr48(pfmt->target_hw_addr, packet->target_hw_addr); 201 packet->target_proto_addr = 234 202 uint32_t_be2host(pfmt->target_proto_addr); 235 203 log_msg(LOG_DEFAULT, LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); … … 238 206 } 239 207 240 241 208 /** @} 242 209 */
Note:
See TracChangeset
for help on using the changeset viewer.