# arm_udp **Repository Path**: wsxiot/arm_udp ## Basic Information - **Project Name**: arm_udp - **Description**: 这是arm开发板上实现的udp协议,以及与winsock2的通信 - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-12-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # arm_udp 这是arm开发板上实现的udp协议,以及与winsock2的通信 ### 概述 - arm的种类是S3C2410A - 使用以太网控制器DM9000 - udp文件夹中是arm程序,用的MDK4 - socket是winsock2程序,用codeblocks - arm运行时要先进行5.5_RTC_Test校准时间,然后再使用7.2_TFTP_Test程序 - arm与主机之间要时用网线连接,arm的ip为192.168.2.111,所以主机的ip应该设置为同一网段,在这里设置为192.168.2.112 - socket文件夹是在arm运行起来后,进行运行,总的来说,arm既做server又做client,所以socket文件夹中的都可以运行 ### udp协议栈的实现 | 分层 | 协议 | | ----- | --------------- | | 应用层 | tftp | | 传输层 | udp | | 网络层 | ICMP IP ARP | | 数据链路层 | eth | | 物理层 | | ```c typedef struct arp_entry { unsigned char ar_ha[ETH_ALEN]; unsigned long ar_ip; } arp_entry; //arp的表 ``` `eth_init();` 网卡初始化 `eth_get_addr(eth_addr);` 获取本机MAC地址,存放于eth_addr中 `ip_init(give_ip);` 将give_ip中的地址放到ip.h中的local_ip中 `udp_init();` 直接return 0,没用 `arp_add_entry(eth_addr, give_ip);` 将eth_addr和give_ip加入arp_entrys `download_addr = 0x30008000;` 将文件下载到这个地址 | 协议包名     | 协议   | | ------- | ---- | | tftphdr | tftp | | icmphdr | icmp | | udphdr | udp | | iphdr | ip | | ethhdr | eth | - int tftp_put_begin(void) - int tftp_rcv_wrq(struct sk_buff *skb) int tftp_rcv_data(struct sk_buff *skb) - int tftp_rcv_packet(struct sk_buff *skb) ```c __packed struct tftphdr {//tftp的协议包 short th_opcode; /* packet type */ __packed union { unsigned short tu_block; /* block # */ short tu_code; /* error code */ char tu_stuff[1]; /* request packet stuff */ } th_u; //char th_data[0]; /* data or error string */ //char th_data[1]; }; ``` - int udp_rcv_packet(struct sk_buff *skb) int icmp_rcv_packet(struct sk_buff *skb) ```c __packed struct udphdr {//udp的协议包 unsigned short source; unsigned short dest; unsigned short len; unsigned short check; };//__attribute__ ((packed)); ``` - int ip_rcv_packet(struct sk_buff *skb) int arp_rcv_packet(struct sk_buff *skb) ```c __packed struct iphdr {//ip协议包 unsigned ihl:4, version:4; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned long saddr; unsigned long daddr; /*The options start here. */ };//__attribute__ ((packed)); ``` - int eth_rcv(struct sk_buff *skb) ```c __packed struct ethhdr//以太网协议包 { unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */ unsigned short h_proto; /* packet type ID field */ }; ``` - int net_handle(void)//收包处理