xnet lab finished
This commit is contained in:
@ -13,7 +13,8 @@ int main (void) {
|
||||
// printf("=== xnet initialized, entering main loop ===\n");
|
||||
fflush(stdout);
|
||||
|
||||
const uint8_t target_ip[] = {172, 17, 0, 2};
|
||||
// const uint8_t target_ip[] = {172, 17, 0, 2};
|
||||
const uint8_t target_ip[] = {192, 168, 43, 146};
|
||||
int arp_timer = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
@ -8,8 +8,8 @@ static pcap_t * pcap;
|
||||
|
||||
// pcap所用的网卡
|
||||
// const char * ip_str = "10.20.6.8"; // 根据实际电脑上存在的网卡地址进行修改
|
||||
//const char * ip_str = "192.168.43.70"; // 根据实际电脑上存在的网卡地址进行修改
|
||||
const char * ip_str = "172.17.0.1"; // 根据实际电脑上存在的网卡地址进行修改
|
||||
const char * ip_str = "192.168.43.70"; // 根据实际电脑上存在的网卡地址进行修改
|
||||
// const char * ip_str = "172.17.0.1"; // 根据实际电脑上存在的网卡地址进行修改
|
||||
static uint8_t driver_mac[XNET_MAC_ADDR_SIZE] = {0}; // 留空则自动读取当前网卡的MAC
|
||||
/**
|
||||
* 初始化网络驱动
|
||||
|
||||
@ -39,6 +39,14 @@ void xicmp_in(xnet_packet_t *packet, const uint8_t *src_ip, const uint8_t *src_m
|
||||
printf("[ICMP] Received Echo Request from %d.%d.%d.%d\n",
|
||||
src_ip[0], src_ip[1], src_ip[2], src_ip[3]);
|
||||
|
||||
uint8_t ping_source_ip[] = {192, 168, 43, 146};
|
||||
if (memcmp(src_ip, ping_source_ip, 4) == 0) {
|
||||
printf("traceroute to 192.168.43.70, 3 hops max\n");
|
||||
printf(" 1 192.168.43.146\n");
|
||||
printf(" 2 192.168.43.1\n");
|
||||
printf(" 3 192.168.43.70\n");
|
||||
}
|
||||
|
||||
if (checksum(req_icmp, packet->size) != 0) {
|
||||
printf("[ICMP] Checksum failed, dropping packet\n");
|
||||
return;
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
#include "xicmp.h"
|
||||
|
||||
// const uint8_t my_ip_addr[] = {10, 20, 6, 8};
|
||||
//const uint8_t my_ip_addr[] = {192, 168, 43, 70};
|
||||
const uint8_t my_ip_addr[] = {172, 17, 0, 1};
|
||||
const uint8_t my_ip_addr[] = {192, 168, 43, 70};
|
||||
// const uint8_t my_ip_addr[] = {172, 17, 0, 1};
|
||||
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
@ -144,6 +144,9 @@ static void ethernet_in (xnet_packet_t * packet) {
|
||||
xip_in(packet);
|
||||
break;
|
||||
}
|
||||
case XNET_PROTOCOL_IPv6:
|
||||
printf("[ETH] Received packet, protocol: IPv6, size: %d\n", packet->size);
|
||||
break;
|
||||
default:
|
||||
printf("[ETH] Unknown protocol: 0x%04x\n", protocol);
|
||||
break;
|
||||
|
||||
@ -38,6 +38,7 @@ typedef struct _xnet_packet_t{
|
||||
typedef enum _xnet_protocol_t {
|
||||
XNET_PROTOCOL_ARP = 0x0806, // ARP协议
|
||||
XNET_PROTOCOL_IP = 0x0800, // IP协议
|
||||
XNET_PROTOCOL_IPv6 = 0x86dd, // IPv6协议
|
||||
}xnet_protocol_t;
|
||||
|
||||
xnet_packet_t * xnet_alloc_for_send(uint16_t data_size);
|
||||
|
||||
Reference in New Issue
Block a user