資源簡介
xsbase270開發(fā)板boot,可運(yùn)行,pxa270intel最后一款A(yù)RM,性能強(qiáng)勁,這是XSBASE270-EDR實(shí)驗(yàn)箱的BOOT
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#define?PORT_BOOTPS 67 //?BOOTP?server?UDP?port.
#define?PORT_BOOTPC 68 //?BOOTP?client?UDP?port.
static?void?bootp_usage(void);
static?bool?do_bootp(int?argc?char?**argv);
static?int?set_bootp_header(void?*packet);
static?bool?wait?=?false;
static?uint32?bootp_id;
struct?command_t?cmd_bootp?=?{
.name??=?“bootp“
.run???=?do_bootp
.usage?=?bootp_usage
};
static?void?bootp_usage(void){
usage_format(“bootp“?“run?bootp.?get?ip?and?host?infomation“);
return;
}
static?bool?do_bootp(int?argc?char?**argv){
int?i?n?len;
bool?res;
uchar?pktbuff[1024]?*txpkt;
time_t?start?now;
const?uchar?broadcast_mac[]?=?{?0xFF?0xFF?0xFF?0xFF?0xFF?0xFF?};
const?uint32?broadcast_ip?=?0xFFFFFFFF;
/*?create?boop?packet?*/
memset(pktbuff?0?sizeof(pktbuff));
txpkt?=?pktbuff?+?100;
len?=?set_bootp_header(txpkt);
n?=?set_udp_header(txpkt?PORT_BOOTPS?PORT_BOOTPC?len);
txpkt?-=?n;?len?+=?n;
n?=?set_ip_header(txpkt?0x00?broadcast_ip?IP_P_UDP?len);
txpkt?-=?n;?len?+=?n;
n?=?set_ether_header(txpkt?broadcast_mac?PROT_IP);
txpkt?-=?n;?len?+=?n;
/*?view?information?*/
printf(“?my?mac?address?is?%s\n“?mac_ntoa(setup->myhaddr));
printf(“?try?to?send?bootp?packet“);
/*?send?request?packet?and?wait?reply?packet?*/
wait?=?true;
setup->myipaddr?=?0;
for?(i=0;?i?5;?i++){
res?=?net_send_packet(txpkt?len);
if?(!res)?break;
printf(“.“);
time(&start);
while?(time(&now)?-?start?1){
net_recv_poll();
if?(!wait)?return?true;
}
}
printf(“\n?failed?:?bootp?packet?is?not?received.\n“);
wait?=?false;
return?false;
}
extern?bool?bootp_recv(void?*packet?int?len){
struct?bootp?*bhp?=?(struct?bootp?*)packet;
if?(len? if?(!wait)?goto?invalid;
if?(bhp->bh_opcode?!=?OP_BOOTREPLY)?goto?invalid;
if?(bhp->bh_htype?!=?HWT_ETHER)?goto?invalid;
if?(bhp->bh_hlen?!=?HWL_ETHER)?goto?invalid;
if?(memcmp(&bhp->bh_tid?&bootp_id?4))?goto?invalid;
//if?(memcmp(&bhp->bh_chaddr?net_get_mac_addr(0)?6))?goto?invalid;
if?(memcmp(&bhp->bh_chaddr?setup->myhaddr?6))?goto?invalid;
printf(“\n“);
printf(“?reply?packet?is?received?from?%s?(%s)\n“?bhp->bh_sname?inet_ntoa(bhp->bh_siaddr));
printf(“?my?ip?address?is?%s\n“?inet_ntoa(bhp->bh_yiaddr));
????//????printf(“the?ip?is?0x%08x?serip?is?0x%08x\n“?bhp->bh_yiaddr?bhp->bh_siaddr);
setup->myipaddr?=?bhp->bh_yiaddr;
setup->destipaddr?=?bhp->bh_siaddr;
wait?=?false;
return?true;
invalid?:
return?false;
}
static?int?set_bootp_header(void?*packet){
uchar?*smac;
time_t?now;
struct?bootp?*bhp?=?(struct?bootp?*)packet;
bhp->bh_opcode?=?OP_BOOTREQUEST; //?1?:?request 2?:?reply.
bhp->bh_htype??=?HWT_ETHER; //?10?base?Ethernet?:?1.
bhp->bh_hlen???=?HWL_ETHER; //?10?base?Ethernet?:?6.
bhp->bh_hops???=?0; //?client俊輯?0欄肺?setting.?gateway啊?葷儈.
bhp->bh_secs???=?htons(time(&now));
評論
共有 條評論