예제 #1
0
파일: etherfun.c 프로젝트: MarginC/kame
int
do_get_file () 
{
  int fail = 0, oldlen;
  char *loadat = (char *)LOAD_ADDR;
  last_ack = 0;

  do_send_tftp( READ );
  while (1) {
    if ( le_get(buf, sizeof(buf), 5) == 0) { /* timeout occured */
      if ( last_ack ) {                          
	do_send_tftp( last_ack );
      } else {
	do_send_tftp( READ );
      }
      fail++;
      if ( fail > 5 ) {
        printf("\n");
	return 1;
      }
    } else {
      printf("%x \r", tftp->info.block*512);
      if ((eh->ether_type != ETYPE_IP) || (iph->ip_p != IPP_UDP)) {
	fail++;
	continue;
      }
      if (servport == FTP_PORT) servport = udph->uh_sport;
      if (tftp->info.op_code == FTPOP_ERR) {
	printf("TFTP: Download error %d: %s\n", 
	       tftp->info.block, tftp->data);
        return 1;
      }
      if (tftp->info.block != last_ack + 1) { /* we recieved the wrong block */
	if (tftp->info.block < last_ack +1) {
	  do_send_tftp(tftp->info.block); /* ackn whatever we recieved */
	} else {
	  do_send_tftp( last_ack );       /* ackn the last confirmed block */
        }
	fail++;
      } else {                /* we got the right block */
	fail = 0;
	last_ack++;
        oldlen = udph->uh_ulen;
	do_send_tftp( last_ack );
	/*printf("bcopy %x %x %d\n", &tftp->data, loadat, oldlen - 12);*/
	bcopy(&tftp->data, loadat, oldlen - 12);
	loadat += oldlen - 12;
	if (oldlen < (8 + 4 + 512)) {
          printf("\n");
	  return 0;
        }
      }
    }
  }
  printf("\n");
  return 0;
} 
예제 #2
0
/* Receive and disassemble the rev_arp reply */
int
get_rev_arp(void)
{
	le_get(buf, sizeof(buf), 6);
	if (eh->ether_type == ETYPE_RARP && rarp->ar_op == OPCODE_REPLY) {
		bcopy(rarp->arp_tpa, myip, sizeof(rarp->arp_tpa));
		bcopy(rarp->arp_spa, servip, sizeof(rarp->arp_spa));
		bcopy(rarp->arp_sha, servea, sizeof(rarp->arp_sha));
		return (1);
	}
	return (0);
}
예제 #3
0
int
get_rev_arp(void) 
{

	le_get(buf, sizeof(buf), 6);
	if (eh->ether_type == ETYPE_RARP && rarp->ar_op == OPCODE_REPLY) {
		memcpy(myip, rarp->arp_tpa, sizeof(rarp->arp_tpa));
		memcpy(servip, rarp->arp_spa, sizeof(rarp->arp_spa));
		memcpy(servea, rarp->arp_sha, sizeof(rarp->arp_sha));
		return 1;
	}
	return 0;
}