Esempio n. 1
0
void describe6(uint8_t *p, size_t nbytes, const char *dev)
{
  char fromaddr[INET6_ADDRSTRLEN];
  char toaddr[INET6_ADDRSTRLEN];
  inet_ntop(AF_INET6, p+SRC_OFFSET6, fromaddr, sizeof(fromaddr));
  inet_ntop(AF_INET6, p+DST_OFFSET6, toaddr, sizeof(toaddr));
  printf("proto=6 dev=%s src=%s dst=%s nbytes=%zu\n",
         dev, fromaddr, toaddr, nbytes);
  printbytes(p,40); // Just the header
}
/**
 * The  ioctl()  function  manipulates the underlying device parameters of
 * special files.  In particular, many operating characteristics of  character
 * special  files  (e.g., terminals) may be controlled with ioctl() requests.
 * The argument d must be an open file descriptor.
 */
int ioctl(int d, unsigned long int request, ...)
{
  static int (*orig_ioctl)(int, int, ...) = NULL;
  //static pthread_mutex_t mutexwrite;
  if(!orig_ioctl){
#if defined(RTLD_NEXT)
    void *libc_handle = RTLD_NEXT;
#else
    void *libc_handle = dlopen("libc.so.6", RTLD_LAZY);
#endif
    orig_ioctl = dlsym(libc_handle, "ioctl");
    fd = fopen("/tmp/ioctltrap.txt", "a");
    //pthread_mutex_init(&mutexwrite, NULL);
  }
  va_list opt;
  unsigned char *arg;
  va_start(opt, request);
  arg = va_arg(opt, unsigned char *);
  va_end(opt);
  //pthread_mutex_lock (&mutexwrite);
  fprintf(fd, "ioctl %d\tinode: %ld\tdir: %lu\ttype:%lu\tnr: %lu\tsize: %lu ", d,
          inode(d), _IOC_DIR(request),_IOC_TYPE(request), _IOC_NR(request),
          _IOC_SIZE(request));
  //if it's going to write, spit out the bytes
  if((_IOC_DIR(request) & _IOC_WRITE) && request != VIDIOC_G_CTRL){
    printbytes(request, arg);
  }
  if(request == I2C_SMBUS)
     printi2c_smbus(arg, 'W');
  if(request == I2C_SLAVE)
     fprintf(fd, "%p", arg);
  //pthread_mutex_unlock (&mutexwrite);
  int retval = orig_ioctl(d, request, arg);
  //if it's going to read, and didn't write, spit out the bytes
  if(_IOC_DIR(request) == _IOC_READ || request == VIDIOC_G_CTRL){
    printbytes(request, arg);
  }
  if(request == I2C_SMBUS)
     printi2c_smbus(arg, 'R');
  fprintf(fd, "\n");
  fflush(fd);
  return retval;
}
Esempio n. 3
0
/* Single General Summary line, bytes data */
void html_gensumlineb(FILE *outf, Outchoices *od, int namecode, double x,
		      double x7, logical isaverage) {
  char **lngstr = od->lngstr;

  unsigned int bm;
  char *c;

  fprintf(outf, "<br><b>%s%s</b> ",  lngstr[namecode], lngstr[colon_]);

  bm = (od->rawbytes)?0:findbmult(x, od->bytesdp);
  printbytes(outf, od, x, bm, 0, od->sepchar);

  if (bm > 0) {
    c = strchr(lngstr[xbytes_], '?');
    *c = '\0';
    fprintf(outf, " %s%s%s", lngstr[xbytes_], lngstr[byteprefix_ + bm], c + 1);
    *c = '?';
  }
  else
    fprintf(outf, " %s", lngstr[bytes_]);

  if (x7 != UNSET) {
    fputs(" (", outf);
    bm = (od->rawbytes)?0:findbmult(x7, od->bytesdp);
    printbytes(outf, od, x7, bm, 0, od->sepchar);
    if (bm > 0) {
      c = strchr(lngstr[xbytes_], '?');
      *c = '\0';
      fprintf(outf, " %s%s%s)", lngstr[xbytes_], lngstr[byteprefix_ + bm],
	      c + 1);
      *c = '?';
    }
    else
      fprintf(outf, " %s)", lngstr[bytes_]);
  }

  putc('\n', outf);
}
Esempio n. 4
0
/* "Busiest time period" line */
void html_busyprintf(FILE *outf, Outchoices *od, choice rep, char *datefmt,
		     unsigned long reqs, unsigned long pages, double bys,
		     datecode_t date, unsigned int hr, unsigned int min,
		     datecode_t newdate, unsigned int newhr,
		     unsigned int newmin, char graphby) {
  extern unsigned int *rep2busystr;

  char **lngstr = od->lngstr;
  char sepchar = od->sepchar;

  unsigned int bmult;
  char *s;

  fprintf(outf, "%s %s (", lngstr[rep2busystr[rep]],
	  datesprintf(od, datefmt, date, hr, min, newdate, newhr, newmin,
		      TRUE, UNSET));
  if (TOLOWER(graphby) == 'r') {
    f3printf(outf, od, (double)reqs, 0, sepchar);
    fprintf(outf, " %s).\n", (reqs == 1)?lngstr[request_]:lngstr[requests_]);
  }
  else if (TOLOWER(graphby) == 'p') {
    f3printf(outf, od, (double)pages, 0, sepchar);
    fprintf(outf, " %s).\n",
	    (pages == 1)?lngstr[pagereq_]:lngstr[pagereqs_]);
  }
  else /* TOLOWER(graphby) == 'b' */ {
    if (od->rawbytes)
      bmult = 0;
    else
      bmult = findbmult(bys, od->bytesdp);
    printbytes(outf, od, bys, bmult, 0, sepchar);
    putc(' ', outf);
    if (bmult >= 1) {
      s = strchr(lngstr[xbytes_], '?');  /* checked in initialisation */
      *s = '\0';
      fprintf(outf, "%s%s%s).\n", lngstr[xbytes_],
	      lngstr[byteprefix_ + bmult], s + 1);
      *s = '?';
    }
    else
      fprintf(outf, "%s).\n", lngstr[bytes_]);
  }
}
Esempio n. 5
0
/* "Busiest time period" line */
void xml_busyprintf(FILE *outf, Outchoices *od, choice rep, char *datefmt,
		     unsigned long reqs, unsigned long pages, double bys,
		     datecode_t date, unsigned int hr, unsigned int min,
		     datecode_t newdate, unsigned int newhr,
		     unsigned int newmin, char graphby)
{
	unsigned int year, month, day;

	XML_TRACE(0);

	code2date( date, &day, &month, &year);
	XML_OUT( XMLDBG"<busiest time=\"%04d%02d%02d%02d%02d\" ", 
		year, month+1, day, hr, min );

	switch( graphby ) {
	case 'R':
	case 'r':
		XML_OUT( "reqs=\"%lu\"", reqs );
		break;
	case 'P':
	case 'p':
		XML_OUT( "pages=\"%lu\"", pages );
		break;
	case 'B':
	case 'b':
		XML_OUT( "bytes=\"%f\"", bys );
		break;
	default:
		// what happens to busiest time when no graphby is set?
		assert(0); 
		break;
	}

	XML_OUT( "/>" );

#if 0
  extern unsigned int *rep2busystr;

  char **lngstr = od->lngstr;
  char sepchar = od->sepchar;

  unsigned int bmult;
  char *s;

  fprintf(outf, "%s %s (", lngstr[rep2busystr[rep]],
	  datesprintf(od, datefmt, date, hr, min, newdate, newhr, newmin,
		      TRUE, UNSET));

  if (TOLOWER(graphby) == 'r') {
    f3printf(outf, od, (double)reqs, 0, sepchar);
    fprintf(outf, " %s).\n", (reqs == 1)?lngstr[request_]:lngstr[requests_]);
  }
  else if (TOLOWER(graphby) == 'p') {
    f3printf(outf, od, (double)pages, 0, sepchar);
    fprintf(outf, " %s).\n",
	    (pages == 1)?lngstr[pagereq_]:lngstr[pagereqs_]);
  }
  else /* TOLOWER(graphby) == 'b' */ {
    if (od->rawbytes)
      bmult = 0;
    else
      bmult = findbmult(bys, od->bytesdp);
    printbytes(outf, od, bys, bmult, 0, sepchar);
    putc(' ', outf);
    if (bmult >= 1) {
      s = strchr(lngstr[xbytes_], '?');  /* checked in initialisation */
      *s = '\0';
      fprintf(outf, "%s%s%s).\n", lngstr[xbytes_],
	      lngstr[byteprefix_ + bmult], s + 1);
      *s = '?';
    }
    else
      fprintf(outf, "%s).\n", lngstr[bytes_]);
  }
#endif
}
Esempio n. 6
0
/* Single cell, listing bytes */
void html_bytescell(FILE *outf, Outchoices *od, choice rep, choice col,
		    double b, double bmult, unsigned int width) {
  printbytes(outf, od, b, bmult, width, od->repsepchar);
  fputs(": ", outf);
}
Esempio n. 7
0
ser_result_t ser_get(ser_t *ser, void *buf, size_t *len)
{
	DWORD	dwErrorFlags;
	DWORD	dwReadLength;
	BOOL	bContinue = TRUE;
	DWORD	start_tmp;

	while (bContinue) {
		if (LOOKING_FOR_HDR == ser->state) {
			if (RBUF_DATA(ser) >= sizeof(ser_hdr_t)) {
				/* printbytes((void *)(&(ser->rbuf[ser->start])), "ser_get:hdr:", sizeof(ser_hdr_t)); */
				if (ser_HDR_FRAME0 != ser->rbuf[ser->start]) {
					RBUF_INCREMENT_START(ser, 1); continue;
				}
				RBUF_INCREMENT_START(ser, 1);
				if (ser_HDR_FRAME1 != ser->rbuf[ser->start]) {
					RBUF_INCREMENT_START(ser, 1); continue;
				}
				RBUF_INCREMENT_START(ser, 1);
				ser->length = (ser->rbuf[RBUF_OFFSET(ser, 0)] & 0xff);
				if (((ser_HDR_FRAME0 + ser_HDR_FRAME1 + ser->length) & 0xff) != ser->rbuf[RBUF_OFFSET(ser, 1)]) {
					/* DPRINT(("ser_get:got ser->rbuf[RBUF_OFFSET(ser,1)] incorrect\n")); */
					continue;
				}
				ser->crc = ser->rbuf[RBUF_OFFSET(ser, 2)];
				ser->state = LOOKING_FOR_BODY;
			}
			else {
				/* DPRINT(("ser_get: RBUF_DATA len:%d is smaller than %d\n", RBUF_DATA(ser), sizeof(ser_hdr_t))); */
				bContinue = FALSE;
			}
		}
		if (LOOKING_FOR_BODY == ser->state) {
			if (RBUF_DATA(ser) >= ser->length + 3) {
				start_tmp = ser->start; RBUF_INCREMENT_START(ser, 3);
				if (RBUF_CRC(ser) == ser->crc) {
					if (ser->length > *len) {
						/* DPRINT(("ser_get: ser->length=%d > *len=%d\n", ser->length, *len)); */
						*len = (ser->length & 0xff); return ser_RES_FULL;
					} else {
						*len = (ser->length & 0xff);
						if (ser->start + ser->length <= ser->rbufsize) {
							memcpy(buf, ser->rbuf + ser->start, ser->length);
						} else {
							memcpy(buf, ser->rbuf + ser->start, ser->rbufsize - ser->start);
							memcpy((char *) buf + ser->rbufsize - ser->start, ser->rbuf, ser->length - (ser->rbufsize - ser->start));
						}
						/* printbytes(buf, "ser_get:buf:", ser->length); */
						RBUF_INCREMENT_START(ser, ser->length);
						ser->state = LOOKING_FOR_HDR;
						return ser_RES_OK;
					}
				} else {
					ser->start = start_tmp;
					ser->state = LOOKING_FOR_HDR; continue;
				}
			} else {
				/* DPRINT(("ser_get: RBUF_DATA len:%d is smaller than ser->len+3=%d\n", RBUF_DATA(ser), ser->length + 3)); */
				bContinue = FALSE;
			}
		}
		dwReadLength = RBUF_EMPTY(ser);
		if (dwReadLength > 0) {
			serio_res_t err;
			err = serio_read(&ser->serio, &ser->rbuf[ser->end], dwReadLength, &dwReadLength);
			if ((err != serio_RES_OK) && (err != serio_RES_EMPTY)) {
				DPRINT(("ser_get: serio_read failed %d\n", err));
			} else {
				/* check if got a modem not connected signal */
				{	DWORD i;
					int pos;
					unsigned char *p;
					pos = ser->sigpos;
					for (i = 1, p = &(ser->rbuf[ser->end]); i <= dwReadLength; i++, p++) {
						if (*p == SIGNAL_HANGUP[pos])  {
							pos++;
							if (pos >= sizeof(SIGNAL_HANGUP))
								return ser_RES_NO_RESPONSE;
						} else if (pos) {
							pos = 0;
							if (*p == SIGNAL_HANGUP[pos]) 
								pos++;
						}
					}
					ser->sigpos = pos;
				}
#if 0
				DPRINT(("ser_get: read %d bytes\n", dwReadLength));
				printbytes((void *)(&(ser->rbuf[ser->end])), "ser_get:readbuf:", dwReadLength);
#endif
				RBUF_INCREMENT_END(ser, dwReadLength); bContinue = TRUE;
			}
		}
	}
	return ser_RES_EMPTY;
}
Esempio n. 8
0
/* validate the given aspath */
static int
validate (struct aspath *as, const struct test_spec *sp)
{
  size_t bytes, bytes4;
  int fails = 0;
  const u_char *out;
  static struct stream *s;
  struct aspath *asinout, *asconfeddel, *asstr, *as4;
  
  out = aspath_snmp_pathseg (as, &bytes);
  asinout = make_aspath (out, bytes, 0);
  
  /* Excercise AS4 parsing a bit, with a dogfood test */
  if (!s)
    s = stream_new (4096);
  bytes4 = aspath_put (s, as, 1);
  as4 = make_aspath (STREAM_DATA(s), bytes4, 1);
  
  asstr = aspath_str2aspath (sp->shouldbe);
  
  asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout));
  
  printf ("got: %s\n", aspath_print(as));
  
  /* the parsed path should match the specified 'shouldbe' string.
   * We should pass the "eat our own dog food" test, be able to output
   * this path and then input it again. Ie the path resulting from:
   *
   *   aspath_parse(aspath_put(as)) 
   *
   * should:
   *
   * - also match the specified 'shouldbe' value
   * - hash to same value as original path
   * - have same hops and confed counts as original, and as the
   *   the specified counts
   *
   * aspath_str2aspath() and shouldbe should match
   *
   * We do the same for:
   *
   *   aspath_parse(aspath_put(as,USE32BIT))
   *
   * Confederation related tests: 
   * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
   * - aspath_delete_confed_seq should be idempotent.
   */
  if (strcmp(aspath_print (as), sp->shouldbe)
         /* hash validation */
      || (aspath_key_make (as) != aspath_key_make (asinout))
         /* by string */
      || strcmp(aspath_print (asinout), sp->shouldbe)
         /* By 4-byte parsing */
      || strcmp(aspath_print (as4), sp->shouldbe)
         /* by various path counts */
      || (aspath_count_hops (as) != sp->hops)
      || (aspath_count_confeds (as) != sp->confeds)
      || (aspath_count_hops (asinout) != sp->hops)
      || (aspath_count_confeds (asinout) != sp->confeds))
    {
      failed++;
      fails++;
      printf ("shouldbe:\n%s\n", sp->shouldbe);
      printf ("as4:\n%s\n", aspath_print (as4));
      printf ("hash keys: in: %d out->in: %d\n", 
              aspath_key_make (as), aspath_key_make (asinout));
      printf ("hops: %d, counted %d %d\n", sp->hops, 
              aspath_count_hops (as),
              aspath_count_hops (asinout) );
      printf ("confeds: %d, counted %d %d\n", sp->confeds,
              aspath_count_confeds (as),
              aspath_count_confeds (asinout));
      printf ("out->in:\n%s\nbytes: ", aspath_print(asinout));
      printbytes (out, bytes);
    }
         /* basic confed related tests */
  if ((aspath_print (asconfeddel) == NULL 
          && sp->shouldbe_delete_confed != NULL)
      || (aspath_print (asconfeddel) != NULL 
          && sp->shouldbe_delete_confed == NULL)
      || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed)
         /* delete_confed_seq should be idempotent */
      || (aspath_key_make (asconfeddel) 
          != aspath_key_make (aspath_delete_confed_seq (asconfeddel))))
    {
      failed++;
      fails++;
      printf ("confed_del: %s\n", aspath_print (asconfeddel));
      printf ("should be: %s\n", sp->shouldbe_delete_confed);
    }
      /* aspath_str2aspath test */
  if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL)
      || (aspath_print (asstr) != NULL && sp->shouldbe == NULL)
      || strcmp(aspath_print (asstr), sp->shouldbe))
    {
      failed++;
      fails++;
      printf ("asstr: %s\n", aspath_print (asstr));
    }
  
    /* loop, private and first as checks */
  if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0)
      || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0)
      || (aspath_private_as_check (as) != sp->private_as)
      || (aspath_firstas_check (as,sp->first)
          && sp->first == 0))
    {
      failed++;
      fails++;
      printf ("firstas: %d,  got %d\n", sp->first,
              aspath_firstas_check (as,sp->first));
      printf ("loop does: %d %d, doesnt: %d %d\n",
              sp->does_loop, aspath_loop_check (as, sp->does_loop),
              sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop));
      printf ("private check: %d %d\n", sp->private_as,
              aspath_private_as_check (as));
    }
  aspath_unintern (asinout);
  aspath_unintern (as4);
  
  aspath_free (asconfeddel);
  aspath_free (asstr);
  stream_reset (s);
  
  return fails;
}