Changeset 1cc8b42 in mainline
- Timestamp:
- 2012-02-27T20:34:58Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f9d3dd4
- Parents:
- 56792a2
- Location:
- uspace/srv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ethip/ethip.c
r56792a2 r1cc8b42 223 223 break; 224 224 default: 225 log_msg(LVL_DEBUG, "Unknown ethertype %" PRIu16,225 log_msg(LVL_DEBUG, "Unknown ethertype 0x%" PRIx16, 226 226 frame.etype_len); 227 227 } -
uspace/srv/ethip/pdu.c
r56792a2 r1cc8b42 49 49 50 50 /** Encode Ethernet PDU. */ 51 #include <stdio.h> 51 52 int eth_pdu_encode(eth_frame_t *frame, void **rdata, size_t *rsize) 52 53 { … … 69 70 frame->size); 70 71 72 log_msg(LVL_DEBUG, "Encoding Ethernet frame src=%llx dest=%llx etype=%x", 73 frame->src, frame->dest, frame->etype_len); 74 log_msg(LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size); 75 size_t i; 76 for (i = 0; i < size; i++) { 77 printf("%02x ", ((uint8_t *)(data))[sizeof(eth_header_t) + i]); 78 } 79 printf("\n"); 80 81 71 82 *rdata = data; 72 83 *rsize = size; … … 101 112 frame->size); 102 113 103 log_msg(LVL_DEBUG, " Ethernet frame src=%llx dest=%llx etype=%x",114 log_msg(LVL_DEBUG, "Decoding Ethernet frame src=%llx dest=%llx etype=%x", 104 115 frame->src, frame->dest, frame->etype_len); 105 log_msg(LVL_DEBUG, " Ethernet frame payload (%zu bytes)", frame->size);116 log_msg(LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size); 106 117 size_t i; 107 118 for (i = 0; i < frame->size; i++) { … … 200 211 } 201 212 202 if (uint16_t_be2host(pfmt->proto_addr_space) != ETYPE_IP) {213 if (uint16_t_be2host(pfmt->proto_addr_space) != 0x0800) { 203 214 log_msg(LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")", 204 215 ETYPE_IP, uint16_t_be2host(pfmt->proto_addr_space)); -
uspace/srv/inet/pdu.c
r56792a2 r1cc8b42 39 39 #include <byteorder.h> 40 40 #include <errno.h> 41 #include <fibril_synch.h> 41 42 #include <io/log.h> 42 43 #include <mem.h> … … 46 47 #include "inet_std.h" 47 48 #include "pdu.h" 49 50 static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock); 51 static uint16_t ip_ident = 0; 52 53 #define INET_CHECKSUM_INIT 0xffff 54 55 /** One's complement addition. 56 * 57 * Result is a + b + carry. 58 */ 59 static uint16_t inet_ocadd16(uint16_t a, uint16_t b) 60 { 61 uint32_t s; 62 63 s = (uint32_t)a + (uint32_t)b; 64 return (s & 0xffff) + (s >> 16); 65 } 66 67 static uint16_t inet_checksum_calc(uint16_t ivalue, void *data, size_t size) 68 { 69 uint16_t sum; 70 uint16_t w; 71 size_t words, i; 72 uint8_t *bdata; 73 74 sum = ~ivalue; 75 words = size / 2; 76 bdata = (uint8_t *)data; 77 78 for (i = 0; i < words; i++) { 79 w = ((uint16_t)bdata[2*i] << 8) | bdata[2*i + 1]; 80 sum = inet_ocadd16(sum, w); 81 } 82 83 if (size % 2 != 0) { 84 w = ((uint16_t)bdata[2*words] << 8); 85 sum = inet_ocadd16(sum, w); 86 } 87 88 return ~sum; 89 } 48 90 49 91 /** Encode Internet PDU. … … 56 98 size_t hdr_size; 57 99 size_t data_offs; 100 uint16_t chksum; 101 uint16_t ident; 102 103 fibril_mutex_lock(&ip_ident_lock); 104 ident = ++ip_ident; 105 fibril_mutex_unlock(&ip_ident_lock); 58 106 59 107 hdr_size = sizeof(ip_header_t); … … 69 117 hdr->tos = packet->tos; 70 118 hdr->tot_len = host2uint16_t_be(size); 71 hdr->id = host2uint16_t_be( 42);119 hdr->id = host2uint16_t_be(ident); 72 120 hdr->flags_foff = host2uint16_t_be(packet->df ? 73 121 BIT_V(uint16_t, FF_FLAG_DF) : 0); … … 78 126 hdr->dest_addr = host2uint32_t_be(packet->dest.ipv4); 79 127 128 chksum = inet_checksum_calc(INET_CHECKSUM_INIT, (void *)hdr, hdr_size); 129 hdr->chksum = host2uint16_t_be(chksum); 130 80 131 memcpy((uint8_t *)data + data_offs, packet->data, packet->size); 81 132
Note:
See TracChangeset
for help on using the changeset viewer.