Uboot ARP Address resolution

Source: Internet
Author: User
Tags htons

Common/cmd_cache.c

int Do_getmac (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {//usend d43d7e45371c 192.168.1.134 1234 1234 Hhaachar ET  Hsrc[6]={0xff, 0xFF, 0xFF, 0xFF, 0xFF, 0xff};char ethdst[6]={0xff, 0xFF, 0xFF, 0xFF, 0xFF, 0xff};_getmac (ARGV[2],ETHSRC); Getmacfromipaddress (ARGV[1],ETHDST,ARGV[3],ETHSRC);//printf ("%s mac  is%x%x%x%x\n", argv[1],eth[0],eth[1] , Eth[2],eth[3],eth[4],eth[5]); return 0;}  U_boot_cmd (Getmac, 6, 1, Do_getmac, "loadable FPGA image Support", "[Operation type] [device number] [image address] [image Size]\n ");
Common/tftp.c
int global_raw_reveive = 0;void getmacfromipaddress (const char*  remoteip, char* remoteeth,const char* ourip,char* Oureth) {/* and do the ARP request */ipaddr_t Remoteip;   ipaddr_t MyIP;   remoteip=  string_to_ip (REMOTEIP);  MyIP = String_to_ip (Ourip);  Arprequestsend (REMOTEIP,OURETH,MYIP); global_raw_reveive = 1;eth_rx (); global_raw_reveive = 0;//NetRxPacket = inpkt;// Netrxpacketlen = Len;//printbuffer ((unsigned char*) netrxpacket,netrxpacketlen);//_printarp ((unsigned char*) Netrxpacket,netrxpacketlen); return 1;/* waiting */}

Net/net.c
void arprequestsend (ipaddr_t remoteip,char* oureth,ipaddr_t ourip) {int I;volatile Uchar *PKT; arp_t *ARP;PKT = nettxpacket;pkt + = Netsetether (PKT, netbcastaddr, prot_arp); arp = (arp_t *) pkt;arp->ar_hrd = htons (ar P_ether); Arp->ar_pro = Htons (prot_ip); arp->ar_hln = 6;ARP->AR_PLN = 4;arp->ar_op = Htons (arpop_request);/* SOURCE ET addr */memcpy (&arp->ar_data[0], oureth, 6);/* source IP addr */netwriteip ((Uchar *) &arp->ar_data [6], Ourip); for (i = ten; i <; ++i) {/* dest ET addr = 0 */arp->ar_data[i] = 0;} NETWRITEIP ((Uchar *) &arp->ar_data[16], REMOTEIP);(void) Eth_send (Nettxpacket, (pkt-nettxpacket) + ARP_HDR_ SIZE);} 
Voidnetreceive (volatile uchar *inpkt, int len) {ethernet_t *et;ip_t*ip; arp_t*arp;ipaddr_t tmp;ipaddr_t Src_ip;intx;uchar *pkt; #if defined (CONFIG_CMD_CDP) int iscdp; #endifushort CTI = 0, Vlanid = Vlan_none, Myvlanid, Mynvlanid;debug ("Packet received.%d\n", Len); Netrxpacket = INPKT; Netrxpacketlen = Len;et = (ethernet_t *) inpkt;<span style= "color: #FF0000;" >if (global_raw_reveive) {//global_raw_reveive=0;printpacket ((ethernet_t *) netrxpacket,len); return;} </span>

Driver/net/cpsw.c
void Printbuffer (unsigned char* buffer, int len) {int i;for (i=0;i<len;i++) {printf ("%2.2x", buffer[i]); if ((i&15) ==15) printf ("\ n");} printf ("\ n");} #define PRINTHEX (A, b) printf (#b # # "=%x\n", a->b); void Printarp (arp_t * arp,int len) {//ushortar_hrd;/* Format of Hardware address*///ushortar_pro;/* Format of protocol address*///ucharar_hln;/* Length of hardware address*///Ucharar_ pln;/* Length of protocol address*///ushortar_op;/* operation*///ucharar_data[0];p rinthex (ARP,AR_HRD);p Rinthex (ARP, Ar_pro);p Rinthex (ARP,AR_HLN);p Rinthex (ARP,AR_PLN);p Rinthex (arp,ar_op);p rintf ("mac_src%x%x-%x%x\n",arp-> AR_DATA[0],ARP-&GT;AR_DATA[1],ARP-&GT;AR_DATA[2],ARP-&GT;AR_DATA[3],ARP-&GT;AR_DATA[4],ARP-&GT;AR_DATA[5]); printf ("Ip_src%x%x%x\n", arp->ar_data[6],arp->ar_data[7],arp->ar_data[8],arp->ar_data[9]);p rintf ( "Mac_dst%x%x%x%x%x\n", arp->ar_data[10],arp->ar_data[11],arp->ar_data[12],arp->ar_data[13],arp- &GT;AR_DATA[14],ARP-&GT;AR_DATA[15]);p rintf ("IP_DST%x%x%x%x\n ", arp->ar_data[16],arp->ar_data[17],arp->ar_data[18],arp->ar_data[19]);} int Printpacket (ethernet_t* eth,int len) {//typedef struct {//ucharet_dest[6];/* Destination node*///ucharet_src[6];/* Source node*///ushortet_protlen;/* Protocol or length*///ucharet_dsap;/* 802 dsap*///ucharet_ssap;/* 802 SSAP*///Uchar et_ctl;/* 802 control*///ucharet_snap1;/* snap*///ucharet_snap2;//ucharet_snap3;//ushortet_prot;/* 802 protocol*/// } ethernet_t;printbuffer ((unsigned char*) eth,len);p rintf ("\net_dest%.2x%.2x%.2x%.2x%.2x%.2x\n", eth->et_dest[0 ],ETH-&GT;ET_DEST[1],ETH-&GT;ET_DEST[2],ETH-&GT;ET_DEST[3],ETH-&GT;ET_DEST[4],ETH-&GT;ET_DEST[5]);p rintf ("et_ SRC%.2x%.2x%.2x%.2x%.2x%.2x\n ", eth->et_src[0],eth->et_src[1],eth->et_src[2],eth->et_src[3],eth- &GT;ET_SRC[4],ETH-&GT;ET_SRC[5]), if (Isnotvlan ()) {printf ("Et_protlen%x", Eth->et_protlen);p rintf ("Et_dsap%x\n ", Eth->et_dsap);p rintf (" Et_ssap%x\n ", Eth->et_ssap);p rintf (" Et_ctl%x\n ", etH-&GT;ET_CTL);p rintf ("Et_snap1%x\n", Eth->et_snap1);p rintf ("Et_snap2%x\n", ETH-&GT;ET_SNAP2);p rintf ("et_snap3 %x\n ", eth->et_snap3);p rintf (" Et_prot%x\n ", Eth->et_prot); switch (eth->et_protlen) {Case 0x608:printf (" Prot_arp ");p rintarp ((arp_t *) ((unsigned char*) eth+ether_hdr_size); Len-ether_hdr_size break;case (" 0x8:printf _ip ");p Rintip ((ip_t *) ((unsigned char*) eth+ether_hdr_size); Len-ether_hdr_size break;case (" 0x3680:printf RARP ");p rintarp ((arp_t *) ((unsigned char*) eth+ether_hdr_size); Len-ether_hdr_size break;case (" 0x81:printf VLAN "); break;} printf ("\ n"); return ether_hdr_size;} else{vlan_ethernet_t *veth = (vlan_ethernet_t *) eth;//ucharvet_dest[6];/* Destination node*///ucharvet_src[6];/* Source node*///ushortvet_vlan_type;/* prot_vlan*///ushortvet_tag;/* tag of vlan*///ushortvet_type;/* protocol type*/ printf ("Vet_vlan_type%x\n", Veth->vet_vlan_type);p rintf ("Vet_tag%x\n", Veth->vet_tag);p rintf ("Vet_type%x\n ", Veth->vet_type); return VLAN_ETHER_HDR_size;}} void Printip (ip_t* ip,int len) {//typedef struct {//ucharip_hl_v;/* header length and version*///ucharip_tos;/* type of service*///ushortip_len;/* Total length*///ushortip_id;/* identification*///ushortip_off;/* fragment offset field*// /ucharip_ttl;/* time to live*///ucharip_p;/* protocol*///ushortip_sum;/* checksum*///ipaddr_tip_src;/* Source IP addre  ss*///ipaddr_tip_dst;/* Destination IP address*///ushortudp_src;/* UDP source port*///ushortudp_dst;/* UDP Destination port*///ushortudp_len;/* Length of UDP packet*///ushortudp_xsum;/* checksum*///} ip_t;printf ("Ip_hl_v%x\n", Ip->ip _hl_v);p rintf ("Ip_tos%x\n", Ip->ip_tos);p rintf ("Ip_len%x\n", Ip->ip_len);p rintf ("ip_id%x\n", ip->ip_id); printf ("Ip_off%x\n", Ip->ip_off);p rintf ("Ip_ttl%x\n", Ip->ip_ttl);p rintf ("Ip_p%x\n", ip->ip_p);p rintf (" Ip_sum%x\n ", ip->ip_sum), if (17==ip->ip_p) {unsigned char* p1;printf (" udp\n ");p rintf (" Udp_src%x\n ", ip->udp _SRC);p rintf ("Udp_dst%x\n", IP-&GT;UDP_DST);p RinTF ("Udp_len%x\n", Ip->udp_len);p rintf ("Udp_xsum%x\n", ip->udp_xsum);p 1 = (unsigned char*) &ip->ip_src; printf ("Ip_src%d%d%d%d\n", p1[0],p1[1],p1[2],p1[3]);p 1 = (unsigned char*) &ip->ip_dst;printf ("Ip_dst%d%d%d%d") \ n ", p1[0],p1[1],p1[2],p1[3]);} else if (1==ip->ip_p) {printf ("icmp\n");}}
static int cpsw_send (struct eth_device *dev, volatile void *packet, int length) {struct Cpsw_priv*priv = dev->priv;void *buffer;int len;int status;int i;<span style= "color: #FF0000;" >unsigned char* p= (unsigned char*) packet;  ethernet_t *et = (ethernet_t *) p;ip_t *IP = (ip_t *) (p+ether_hdr_size);p rintf ("cpsw_send:length=%x\n", length);//00 0c 29 6a 4e//p[0]=0;//p[1]=0xc;//p[2]=0x29;//p[3]=0x6a;//p[4]=0x86;//p[5]=0x4e;printpacket (et,length);p rintf (" beging send ... \ n ");</span>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Uboot ARP Address resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.