X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/blobdiff_plain/2cf7241a2ec32fd51b6d859c2eb0317b23739609..f5186e12ed5aedf98d0fa0d8299a73c830046c75:/src/main.c?ds=inline diff --git a/src/main.c b/src/main.c index 18df512..60ed5db 100644 --- a/src/main.c +++ b/src/main.c @@ -32,8 +32,10 @@ void main(void) { byte buf[64]; //XXX byte i; //XXX + byte len; - if (!netdev_recv_start()) // no recibimos nada (válido) + len = netdev_recv_start(); + if (!len) // no recibimos nada (válido) continue; // Probamos de nuevo // Tenemos algo! @@ -72,21 +74,27 @@ void main(void) //printb(udp_dgram_len, 0x40); // TODO // Nuestro protocolo, por ahora un simple echo! - netdev_read_start(udp_dgram_len-UDP_HEADER_SIZE); - for (i = 0; i < udp_dgram_len-UDP_HEADER_SIZE; ++i) - buf[i] = netdev_read_byte(); + len = udp_dgram_len - UDP_HEADER_SIZE; + netdev_read_start(len); + for (i = 0; i < len; ++i) + buf[i] = udp_read_byte(); netdev_read_end(); + if (!udp_checksum_ok()) + goto drop; netdev_recv_end(); // Respuesta netdev_send_start(); eth_write_frame_header(); + //udp_dgram_len = UDP_HEADER_SIZE+len; + //ip_packet_len = IP_HEADER_SIZE+udp_dgram_len; ip_write_packet_header(); udp_write_dgram_header(); - netdev_write_start(udp_dgram_len-UDP_HEADER_SIZE); - for (i = 0; i < udp_dgram_len-UDP_HEADER_SIZE; ++i) - netdev_write_byte(buf[i]); + netdev_write_start(len); + for (i = 0; i < len; ++i) + udp_write_byte(buf[i]); netdev_write_end(); + udp_write_checksum(ETH_HEADER_SIZE+IP_HEADER_SIZE); netdev_send_end(ETH_HEADER_SIZE+IP_HEADER_SIZE+udp_dgram_len); } }