예제 #1
0
파일: dns.c 프로젝트: epok76/lanmap2
static size_t dump(const parse_frame *f, int options, FILE *out)
{
  const dns *d = (dns *)f->off;
  const char *buf = (char *)d + sizeof *d;
  size_t len = f->len - sizeof *d;
  u16 cnt;
  int bytes = fprintf(out, /* header */
    "%s %s "
    "op=%u aa=%u tc=%u rd=%u ra=%u aauth=%u "
    "cnt(qd=%u an=%u ns=%u ar=%u)\n",
    Iface_DNS.shortname, QRStr[d->qr][0],
    d->opcode, d->aa, d->tc, d->rd, d->ra, d->aauth,
    d->qdcnt, d->ancnt, d->nscnt, d->arcnt);
  cnt = d->qdcnt; /* queries */
  while (cnt--) {
    size_t l = dns_calc_len_qd(buf, len);
    bytes += dump_qd(buf, len, out);
    buf += l, len -= l;
  }
  cnt = d->ancnt; /* answers */
  while (cnt--) {
    size_t l = dns_calc_len_rr(buf, len);
    bytes += dump_rr(DNS_RR_AN, f, buf, len, out);
    buf += l, len -= l;
  }
  cnt = d->nscnt; /* nameserver */
  while (cnt--) {
    size_t l = dns_calc_len_rr(buf, len);
    bytes += dump_rr(DNS_RR_NS, f, buf, len, out);
    buf += l, len -= l;
  }
  cnt = d->arcnt; /* additional */
  while (cnt--) {
    size_t l = dns_calc_len_rr(buf, len);
    bytes += dump_rr(DNS_RR_AR, f, buf, len, out);
    buf += l, len -= l;
  }

  return (size_t)bytes;
}
예제 #2
0
파일: isovfy.c 프로젝트: ajinkya93/OpenBSD
check_tree(int file_addr, int file_size, int parent_addr){
  unsigned char buffer[2048];
  unsigned int k;
  int rflag;
  int i, i1, j, goof;
  int extent, size;
  int line;
  int orig_file_addr, parent_file_addr;
  struct iso_directory_record * idr;

  i1 = 0;

  orig_file_addr = file_addr / blocksize;  /* Actual extent of this directory */
  parent_file_addr = parent_addr / blocksize;

  if((dir_count % 100) == 0) printf("[%d %d]\n", dir_count, dir_size_count);
#if 0
  printf("Starting directory %d %d %d\n", file_addr, file_size, parent_addr);
#endif

  dir_count++;
  dir_size_count += file_size / blocksize;

  if(file_size & 0x3ff) printf("********Directory has unusual size\n");

  for(k=0; k < (file_size / sizeof(buffer)); k++){
	  lseek(fileno(infile), file_addr, 0);
	  read(fileno(infile), buffer, sizeof(buffer));
	  i = 0;
	  while(1==1){
		  goof = iline=0;
		  idr = (struct iso_directory_record *) &buffer[i];
		  if(idr->length[0] == 0) break;
		  sprintf(&lbuffer[iline],"%3d ", idr->length[0]);
		  iline += strlen(lbuffer + iline);
		  extent = isonum_733(idr->extent);
		  size = isonum_733(idr->size);
		  sprintf(&lbuffer[iline],"%5x ", extent);
		  iline += strlen(lbuffer + iline);
		  sprintf(&lbuffer[iline],"%8d ", size);
		  iline += strlen(lbuffer + iline);
		  sprintf (&lbuffer[iline], "%c", (idr->flags[0] & 2) ? '*' : ' '); 
		  iline += strlen(lbuffer + iline);

		  if(idr->name_len[0] > 33)
		    {
		      sprintf(&lbuffer[iline],"File name length=(%d)",
			      idr->name_len[0], goof++);
		      iline += strlen(lbuffer + iline);
		    }
		  else if(idr->name_len[0] == 1 && idr->name[0] == 0) {
			  sprintf(&lbuffer[iline],".             ");
			  iline += strlen(lbuffer + iline);
			  rflag = 0;
			  if(orig_file_addr !=isonum_733(idr->extent) + isonum_711((char *) idr->ext_attr_length))
			    {
			      sprintf(&lbuffer[iline],"***** Directory has null extent.", goof++);
			      iline += strlen(lbuffer + iline);
			    }
			  if(i1)
			    {
			      sprintf(&lbuffer[iline],"***** . not  first entry.", rr_goof++);
			      iline += strlen(lbuffer + iline);
			    }
		  } else if(idr->name_len[0] == 1 && idr->name[0] == 1) {
			  sprintf(&lbuffer[iline],"..            ");
			  iline += strlen(lbuffer + iline);
			  rflag = 0;
			  if(parent_file_addr !=isonum_733(idr->extent) + isonum_711((char *) idr->ext_attr_length))
			    {
			      sprintf(&lbuffer[iline],"***** Directory has null extent.", goof++);
			      iline += strlen(lbuffer + iline);
			    }
			  if(i1 != 1)
			    {
			      sprintf(&lbuffer[iline],"***** .. not second entry.", rr_goof++);
			      iline += strlen(lbuffer + iline);
			    }
			  
		  } else {
		          if(i1 < 2) 
			    {
			      sprintf(&lbuffer[iline]," Improper sorting.", rr_goof++);
			    }
			  for(j=0; j<idr->name_len[0]; j++) 
			    {
			      sprintf(&lbuffer[iline],"%c", idr->name[j]);
			    }
			  for(j=0; j<14 - (int) idr->name_len[0]; j++) 
			    {
			      sprintf(&lbuffer[iline]," ");
			      iline += strlen(lbuffer + iline);
			    }
			  rflag = 1;
		  };

		  if(size && extent == 0) 
		    {
		      sprintf(&lbuffer[iline],"****Extent==0, size != 0", goof++);
		      iline += strlen(lbuffer + iline);
		    }
#if 0
		  /* This is apparently legal. */
		  if(size == 0 && extent) 
		    {
		      sprintf(&lbuffer[iline],"****Extent!=0, size == 0", goof++);
		      iline += strlen(lbuffer + iline);
		    }
#endif

		  if(idr->flags[0] & 0xf5)
		    {
			  sprintf(&lbuffer[iline],"Flags=(%x) ", idr->flags[0], goof++);
			  iline += strlen(lbuffer + iline);
		    }
		  if(idr->interleave[0])
		    {
			  sprintf(&lbuffer[iline],"Interleave=(%d) ", idr->interleave[0], goof++);
			  iline += strlen(lbuffer + iline);
		    }

		  if(idr->file_unit_size[0])
		    {
			sprintf(&lbuffer[iline],"File unit size=(%d) ", idr->file_unit_size[0], goof++);
			iline += strlen(lbuffer + iline);
		    }


		  if(idr->volume_sequence_number[0] != 1)
		    {
		      sprintf(&lbuffer[iline],"Volume sequence number=(%d) ", idr->volume_sequence_number[0], goof++);
		      iline += strlen(lbuffer + iline);
		    }

		  goof += dump_rr(idr);
		  sprintf(&lbuffer[iline],"\n");
		  iline += strlen(lbuffer + iline);


		  if(goof){
		          ngoof++;
			  lbuffer[iline++] = 0;
			  printf("%x: %s", orig_file_addr, lbuffer);
		  };



		  if(rflag && (idr->flags[0] & 2)) check_tree((isonum_733(idr->extent) + isonum_711((char *)idr->ext_attr_length)) * blocksize,
						   isonum_733(idr->size),
						   orig_file_addr * blocksize);
		  i += buffer[i];
		  i1++;
		  if (i > 2048 - sizeof(struct iso_directory_record)) break;
	  };
	  file_addr += sizeof(buffer);
  };
  fflush(stdout);
}