Example #1
0
static void test3(void)
{
    static bit_array bits[SIZE(20)] = {0};

    char2bits(bits, 0, 'B');
    char2bits(bits, 8, 'C');

    assert(bits2char(bits, 0) == 'B');
    assert(bits2char(bits, 8) == 'C');

    for (size_t i = 16; i < 20; i++) {
        assert(get_bit(bits, i) == 0);
    }
    printf("Test3 Passed!\n");
}
//Function helps create tree header to write to compressed file
void Tree_headerHelper(TreeNode * tn, FILE * outfptr, unsigned char * whichbit, unsigned char * curbyte)
{
  if (tn == NULL)
    {
      return;
    }
  TreeNode * lc = tn -> left;
  TreeNode * rc = tn -> right;
  if((lc == NULL) && (rc == NULL))
    {
      writeBit(outfptr, 1, whichbit, curbyte);
      char2bits(outfptr, tn -> character, whichbit, curbyte);
      return;
    }
  Tree_headerHelper(lc, outfptr, whichbit, curbyte);
  Tree_headerHelper(rc, outfptr, whichbit, curbyte);
  writeBit(outfptr, 0, whichbit, curbyte);
}
Example #3
0
int cmd_bpdu_flags (struct cli_def *cli, const char *command, char *argv[], int argc)
{
   struct mops_ext_bpdu * pd = clipkt->p_desc;
   int i;
   char str[16];
   
   if ( (strcmp(argv[argc-1],"?")==0) || (argc>8) )
     {
	cli_print(cli, "Specify the BPDU flags by keyword.\r");
	cli_print(cli, "Note that not-mentioned flags will be set to zero!\n");
	cli_print(cli, "General keywords:\n");
	cli_print(cli, "  ack     .... Topology Change Acknowledgement\r");
	cli_print(cli, "  tcn     .... Topology Change Notification\r");
	cli_print(cli, "\r");
	cli_print(cli, "RSTP-specific keywords:\n");
	cli_print(cli, "  agree   .... Agreement\r");
	cli_print(cli, "  prop    .... Proposal\r");
	cli_print(cli, "  fwd     .... Forward State\r");
	cli_print(cli, "  learn   .... Learn State\r");
	cli_print(cli, "\r");
	cli_print(cli, "  Port roles:\n");
	cli_print(cli, "  unknown .... Unknown\r");
	cli_print(cli, "  alt     .... Alternate or Backup\r");
	cli_print(cli, "  root    .... Root\r");
	cli_print(cli, "  desg    .... Designated\r");
	cli_print(cli, "\n");
	return CLI_OK;
     }

   //    7     6    5   4        3   2     1      0
   // tcnack agree fwd learn     X   X  proposal TCN
   // where XX is 00 unknown
   //             01 alternate or backup
   //             10 root
   //             11 designated
   
   if (argc)
     {
	pd->flags = 0x00; // always reset to zero (= normal Configuration BPDU)
	
	for (i=0; i<argc; i++)
	  {
	     if (mz_strcmp(argv[i], "ack", 2)==0) pd->flags |= 0x80;
	     else
	       if (mz_strcmp(argv[i], "tcn", 2)==0) pd->flags |= 0x01;
	     else
	       if (mz_strcmp(argv[i], "agree", 2)==0) pd->flags |= 0x40;
	     else
	       if (mz_strcmp(argv[i], "fwd", 2)==0) pd->flags |= 0x20;
	     else
	       if (mz_strcmp(argv[i], "learn", 2)==0) pd->flags |= 0x10;
	     else
	       if (mz_strcmp(argv[i], "proposal", 2)==0) pd->flags |= 0x02;
	     else
	       if (mz_strcmp(argv[i], "unknown", 2)==0) pd->flags &= 0xf3;
	     else
	       if (mz_strcmp(argv[i], "alt", 2)==0) { pd->flags &= 0xf7; pd->flags |= 0x04; } 
	     else
	       if (mz_strcmp(argv[i], "root", 2)==0) { pd->flags &= 0xfb; pd->flags |= 0x08; }
	     else
	       if (mz_strcmp(argv[i], "desg", 2)==0) pd->flags |= 0x0c;
	  }
	// Feedback
	char2bits(pd->flags, str);
	cli_print(cli, "Flags: %s\n", str);
     }
   else
     {
	cli_print(cli, "No flags configured (use '?')\n");
     }
      
   return CLI_OK;
}
Example #4
0
// Runs through all automops entries and dumps some basic info 
// Returns the number of used protocols
// 
int  automops_dump_all(struct automops* list)
{
	struct automops *head = list;
	struct automops *cur = list;
	struct fields *f=NULL;
	int anzmops=0, used=0;
	char str[64], ft[32];
	uint32_t SA=0, DA=0;
	uint8_t *x, *y;
	char bits_on[18], bits_off[18];
	int i=0, j=0;
		
	do {
		if (cur->used==-1) {
			fprintf(stderr, "AUTOMOPS: Initial element\n");
			if ((cur->next==cur)&&(cur->prev==cur))
				fprintf(stderr, "  No other elements found.\n");
			break;
		}
		if (cur->used>0) used++;
		anzmops++;
		SA=ntohl(cur->SA); x = (uint8_t*) &SA;
		DA=ntohl(cur->DA); y = (uint8_t*) &DA;
		char2bits(cur->layers_on, bits_on);
		char2bits(cur->layers_off, bits_off);
		fprintf(stderr, "Protocol %i: %s -- %s\n"
			" Layercodes:  X T U I M Q S E\n"
			"    requires  %s (0x%02x)\n" 
			"   conflicts  %s (0x%02x)\n"
			" L2: EtherType=%04x, sa=%02x:%02x:%02x:%02x:%02x:%02x, da=%02x:%02x:%02x:%02x:%02x:%02x\n"
			,
			anzmops, cur->name, cur->desc, 
			bits_on, cur->layers_on, bits_off, cur->layers_off,
			cur->etype, cur->sa[0], cur->sa[1], cur->sa[2], cur->sa[3], cur->sa[4], cur->sa[5],
			cur->da[0], cur->da[1], cur->da[2], cur->da[3], cur->da[4], cur->da[5]);
		if (cur->layers_on&MOPS_IP) {
			fprintf(stderr, " IP: proto=%i, SA=%u.%u.%u.%u, DA=%u.%u.%u.%u\n",
				cur->proto, *x, *(x+1), *(x+2), *(x+3), *y, *(y+1), *(y+2), *(y+3));
		} else {
			fprintf(stderr, " IP: ---\n");
		}
		// Walk through field data:
		f=cur->field; j=0;
		while (f!=NULL) {
			j++; // count number of fields
			if (verbose) {
				i=0;
				if (f->longdesc!=NULL) { 
					mz_strncpy(str, f->longdesc, 60);
					if (strnlen(str,60)>=59) i=1;
				}
				else {
					mz_strncpy(str, "-- no long description specified --", 60);
				}
				amp_type2str(f->type, ft);
				fprintf(stderr, "    %02i  Field [%i] '%s' -- %s\n"
					"        Description: %s%s\n"
					"        Type: %s %s %s (%lu/%lu) {%lu..%lu..%lu} shift: %i; %i chars\n"
					,f->i, f->index, f->name, f->shortdesc,
					str, (i) ? "..." : "", 
					ft, (f->constant) ? "FIXED" : "",
					(f->valname!=NULL) ? f->valname : "(no value name)" ,
					(long unsigned int) f->tlv_type, 
					(long unsigned int) f->tlv_len, 
					(long unsigned int) f->min, 
					(long unsigned int) f->val, 
					(long unsigned int) f->max,
					f->leftshift, f->str_s);
			}
			f=f->next;
		}
		if (verbose==0) fprintf(stderr, " %i fields defined.\n", j);
		//---------------------------------
		cur = cur->next;
	}  while (head != cur);
   
	return used;
}