Example #1
0
int
arp_request(u32bits dst)
{
	unsigned waiting;

#ifdef	ARPDEBUG
	PPRINT(("Start arp_request(0x%x)\n", dst));
#endif
	arp_waiting = dst;
	(void)arp_output();
	settimeout(ARP_RETRANSMIT);
	waiting = ARP_RETRANSMIT;

	while (arp_waiting != 0 && waiting <= 60000) {
		if (isatimeout()) {
#ifdef	ARPDEBUG
			PPRINT(("ARP request sent\n"));
#endif
			arp_output();
			settimeout(ARP_RETRANSMIT);
			waiting += ARP_RETRANSMIT;
		}
		if (is_intr_char())
			return (NETBOOT_ABORT);
		(*dlink.dl_input)(arp_buffer, sizeof(arp_buffer));
	}
	return (arp_waiting == 0 ? NETBOOT_SUCCESS : NETBOOT_ERROR);
}
Example #2
0
File: ip.c Project: tongban/eos
/* ----------------------------------------------------------------------
 *                             ip_output()
 * 功能:由IP模块发送一个数据包
 * 参数: 
 * 返回值:无
 * 说明:无
 * --------------------------------------------------------------------- */
void ip_output( pbuf_t * pbuf, ip_addr_t dest, uint16 len, uint8 pro, uint8 ttl )
{
    uint8   i;
    ip_hdr_t * hdr;
    
    if( pbuf == ( pbuf_t * )0 )
        return;

    /* 填充头部 */
    pbuf->app_data -= sizeof( ip_hdr_t );
    hdr = (ip_hdr_t *)( pbuf->app_data );
    hdr->hlen = sizeof( ip_hdr_t ) / 4;
    hdr->version = IPV4;
    hdr->tos = 0;
    hdr->to_len = htons( len + sizeof( ip_hdr_t ) );
    hdr->id = htons( seq++ );        
    hdr->flag = 0;                          
    hdr->offset = 0;
    hdr->ttl = ttl;
    hdr->protocol = pro;
    hdr->chksum = 0;
    hdr->src_ip = htonl( local_ip );
    hdr->dest_ip = htonl( dest );
    hdr->chksum = chksum( (uint16 *)hdr, sizeof( ip_hdr_t ) );

    /* 直接由网络接口发出或发至网关 */
    if( (dest & net_mask) == (local_ip & net_mask) ) 
        arp_output( pbuf, dest );
    else
        arp_output( pbuf, gate_way );
}