コード例 #1
0
ファイル: graph.c プロジェクト: Alecs94/DSA-lab
void bfsLst(int startingNode, node** lst, int size)
{
    int* visited = (int*)malloc(sizeof(int)*size);
    int i;
    for(i = 0; i < size; i++)
        visited[i] = UNVISITED;

    visited[startingNode] = VISITED;
    printf("%d ", startingNode);
    node* head = NULL;
    node* tail = NULL;
    int temp;
    enq(&tail, startingNode, &temp);
    head = tail;

    while(head != NULL)
    {
        int v = head->data;
        deq(&head);
        node* aux = lst[v];
        while(aux != NULL)
        {
            if(visited[aux->data] == UNVISITED)
            {
                visited[aux->data] = VISITED;
                printf("%d ", aux->data);
                enq(&tail, aux->data, &temp);
                if(head == NULL)
                    head = tail;
            }
            aux = aux->next;
        }
    }
    printf("\n");
}
コード例 #2
0
ファイル: my_board.c プロジェクト: anish198519851985/Hacking
int main()
{
	int i, level=0,j;
	qu *q=malloc(sizeof(qu)*100);
	memset(q, 0, sizeof(qu)*100);

	for(i=0;i<100;i++)
		for(j=0;j<100;j++)
			distance[i][j]=INFINITY;
	enq(q, 0, 0);
	distance[0][0] = 0;
	while(iE(q)) {
		int i, j, x_, y_;
		struct q_i *e = deq(q);
		printf("%d %d\n", e->i, e->j);
		x_ = e->i;y_=e->j;
		if(e->i == 7 && e->j == 7) {
			printf("found %d\n", distance[7][7]+1);
			return;	
		}
		for(i=0;i+1<sizeof(po)/sizeof(po[0]);i+=2) {
			int x, y;
			x=x_+po[i];
			y=y_+po[i+1];
			if(x >= 0 && x < 8 && y >= 0 && y < 8) {
				if(distance[x][y] == INFINITY) {
					distance[x][y]	= 1+ distance[x_][y_];
					enq(q, x, y);
				}
			}
		}
	}
	return 0;
}
コード例 #3
0
ファイル: graph.c プロジェクト: Alecs94/DSA-lab
void bfsMat(int startingNode, int** mat, int size)
{
    int* visited = (int*)malloc(sizeof(int)*size);
    int i;
    for(i = 0; i < size; i++)
        visited[i] = UNVISITED;

    visited[startingNode] = VISITED;
    printf("%d ", startingNode);
    node* head = NULL;
    node* tail = NULL;
    int temp;
    enq(&tail, startingNode, &temp);
    head = tail;

    while(head != NULL)
    {
        int v = head->data;
        deq(&head);
        for(i = 0; i < size; i++)
            if(mat[v][i] > 0 && visited[i] == UNVISITED)
            {
                visited[i] = VISITED;
                printf("%d ", i);
                enq(&tail, i, &temp);
                if(head == NULL)
                    head = tail;
            }
    }
    printf("\n");
}
コード例 #4
0
ファイル: problem_6.c プロジェクト: binhqnguyen/cs5460
int main(){
	queue_t *queue;
	int i = 0;
	int v = 0;
	queue = create_queue();
	if (queue == NULL){
		fprintf(stderr,"Error creating queue\n");
		return -EXIT_FAILURE;
	}
	assert (deq(&v,queue)==0);	/*deque an empty queue, print "Queue is empty"*/

	for (i = 0; i < 32; ++i)
		assert (enq(5,queue)==1);	/*fill the queue with 5*/

	for (i = 0; i < 32; ++i)
		assert (queue->value[i]==5);	/*check the entire queue*/

	assert (enq(5, queue)==0);	/*enque a full queue, print "Queue is full"*/

	assert (deq(&v, queue)==1);	/*deque the first element*/

	assert (enq(6, queue)==1);	/*enque 6*/

	for (i = 0; i < 32; i++)
		assert(deq(&v,queue)==1);
	assert (v==6);	/*the last element should be 6*/
	
	return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: lockers.c プロジェクト: rroart/freevms
int volume_lock(char * prefix, char *volname)
{
    int sts = 0;
    int acmode = 1;
    int parid = 0;
    long blkastadr = 0;
    long astadr = continue_thread;
    astadr = 0; // not yet
    int astprm = 0;
    int flags = 0;
    struct dsc$descriptor resnam;
    char name[256];

    sprintf(name, "%s%s", prefix, volname);
    resnam.dsc$a_pointer = name;
    resnam.dsc$w_length = strlen(name);

    struct _lksb lksb;

    while (sts == 0)
    {
        sts = sys$enq (0, LCK$K_NLMODE, &lksb, flags, &resnam, parid, astadr, astprm, blkastadr, acmode, 0);
    }
    sts = 0;
    flags |= LCK$M_CONVERT;
    while (sts == 0)
    {
        sts = sys$enq (0, LCK$K_PWMODE, &lksb, flags, &resnam, parid, astadr, astprm, blkastadr, acmode, 0);
    }

    int lkid = lksb.lksb$l_lkid;

    return lkid;
}
コード例 #6
0
ファイル: bfs.c プロジェクト: shylesh/mycode
void
bfs (NODE *tptr)
{
	NODE 	*current = NULL;

	current = tptr;

	printf ("%d", current->data);

	while (current) {

			if (current->left)
				enq (&q, (long long) current->left);

			if (current->right)
				enq (&q, (long long) current->right);


		printf ("%d ", current->data);

		current = (NODE *) deq (&q);
	}


}
コード例 #7
0
ファイル: dna_ab.c プロジェクト: juangil/programmingContests
int main(void)
{
  int n,i,l,k,m,who,next,wlen,par,ismore;
  
  scanf("%d",&n);
  while(n--)
  {
    scanf("%s",&S);
    scanf("%s",&T);
    sl=strlen(S);
    tl=strlen(T);
    
    for (i=0;i<=tl;i++)
      fstart[0][i]=fstop[0][i]=fstart[1][i]=fstop[1][i]=0;
    
    for (l=0;l<(1<<tl);l++)
      vis[l]=-1;
    vis[0]=0;
    
    enq(0,0,0);
    ismore=1;
    par=0;
    while (ismore)
    {
      ismore=0;
      who=deq(par,&wlen);
      while (who>-1 && who!=((1<<tl)-1))
      {
        int alen=0;
        for (i=0;i<tl;i++)
        {
          int len,len2;
          len=issubst(T,tl,who,T,i,who);
          len2=issubst(S,sl,((1<<sl)-1),T,i,who);
          if (len2>len) len=len2;
          if (len>alen) // only append maximal substrings
          {
            next=who|((1<<(i+len))-(1<<i));
            if (vis[next]==-1)
            { 
              vis[next]=vis[who]+1;
              enq(1-par,next,wlen+len);
              ismore=1;
            } 
            alen=len;
          }
          alen--;
        }
        who=deq(par,&wlen);
      }
      if (who==((1<<tl)-1)) ismore=0;
      par=1-par;
    }
    
    if (vis[(1<<tl)-1]==-1) printf("impossible\n"); else printf("%d\n",vis[(1<<tl)-1]);
  }
  return 0;
}
コード例 #8
0
ファイル: test_queue.c プロジェクト: gideonla/w2014
/*
 * Following four functions perform the enqueuing of integers 1..n
 * in a manner perscribed by delay_mode (see above)
 */
static void eqr0(struct l_queue *q, int n) {

    for (long i = 1; i <= n; i++) {
        if (enq (q, (void *) i)) {
            // If enq hits a full queue for some reason...
            i -= 1;
        }
    }
    while (enq (q, NULL)) {}; // Stick a zero into the queue.
    return;
}
コード例 #9
0
int main()
{
	queue_t q;
	init(&q);
	enq(&q, 1);
	deq(&q);
	enq(&q, 3);
	enq(&q, 2);
	deq(&q);
	deq(&q);
	deq(&q);
	deq(&q);
	enq(&q, 2);
}
コード例 #10
0
ファイル: queue.cpp プロジェクト: MYounas/Data_Structures_Hub
int main(){
	Node* front=NULL,*rear = NULL;
	enq(&front, &rear, 1);
	enq(&front, &rear, 3);
	enq(&front, &rear, 6);
	enq(&front, &rear, 4);
	disp(front);
	puts("");
	deque(&front);
	deque(&front);
	disp(front);
	getchar();
	return 0;
}
コード例 #11
0
void * thread_func1(int idx, queue_t q, char * a,
		    int n_items, int n_enq_threads, int n_deq_threads) {
  if (idx < n_enq_threads) {
    /* 挿入するスレッド. n_enq_threads スレッドで分担して, 
       0, 1, 2, ..., n_items-1 を一度ずつ挿入する */
    int i;
    /* [my_items_beg,my_items_end) = 自分が挿入する範囲 */
    int my_items_beg = (n_items * idx)       / n_enq_threads;
    int my_items_end = (n_items * (idx + 1)) / n_enq_threads;
    /* 挿入(enq) */
    for (i = my_items_beg; i < my_items_end; i++) {
      enq(q, i);
    }
  } else {
    /* 削除(deq) */
    int deq_idx = idx - n_enq_threads;
    /* n_deq_threadsスレッドが分担して合計, n_items 回 deq を発効する.
       挿入した全要素が一度ずつとり出されるはずである */
    int my_items_beg = (n_items * deq_idx)       / n_deq_threads;
    int my_items_end = (n_items * (deq_idx + 1)) / n_deq_threads;
    int i;
    for (i = my_items_beg; i < my_items_end; i++) {
      int x = deq(q);
      assert(x != -1);	      /* (i) 空であってはいけない */
      assert(a[x] == 0); /* (ii) 同じ要素が2度とり出されてはいけない */
      a[x] = 1;	      /* xが取り出されたと記録 */
    }
  }
  return 0;
}
コード例 #12
0
void lca(tree_t *t,int arr[],int n1,int n2,int *index)
{
    q_t *q=newQueue(20);
    tree_t *temp=t;
    while(temp)
    {
        arr[*index]=temp->data;
        (*index)++;
        if(temp->left)
            enq(q,temp->left);
        if(temp->right)
            enq(q,temp->right);
        temp=dequeue(q);
    }
    printLca(arr,index,n1,n2);
}
コード例 #13
0
ファイル: ipsend.c プロジェクト: m3y54m/32bitmicro
/*------------------------------------------------------------------------
 *  ipsend  -  send an IP datagram to the specified address
 *------------------------------------------------------------------------
 */
int
ipsend(IPaddr faddr, struct ep *pep, unsigned datalen,
	u_char proto, u_char ptos, u_char ttl)
{
	struct	ip *pip = (struct ip *) pep->ep_data;

	pep->ep_type = EPT_IP;
	pep->ep_order |= EPO_IP|EPO_NET;
	pip->ip_verlen = (IP_VERSION<<4) | IP_MINHLEN;
	pip->ip_tos = ptos;
	pip->ip_len = datalen+IP_HLEN(pip);
	pip->ip_id = ipackid++;
	pip->ip_fragoff = 0;
	pip->ip_ttl = ttl;
	pip->ip_proto = proto;
	pip->ip_dst = faddr;

	/*
	 * special case for ICMP, so source matches destination
	 * on multi-homed hosts.
	 */
	if (pip->ip_proto != IPT_ICMP)
		pip->ip_src = ip_anyaddr;

	if (enq(nif[NI_LOCAL].ni_ipinq, pep, 0) < 0) {
		freebuf(pep);
		IpOutDiscards++;
	}
	send(ippid, NI_LOCAL);
	IpOutRequests++;
	return OK;
}
コード例 #14
0
ファイル: main.c プロジェクト: zyxstar/exam_c
int main(void)
{
	int arr[] = {3,2,1,6,7,8,9,0,};
	int i, j;
	int data;
	int ret;

	for (j = 0; j < 5; j++) {
		for (i = 0; i < 3; i++) {
			ret = enq(arr[i] + j * 3);
			if (ret == -1) {
				printf("stack full, i = %d\n", i);
				break;
			}
		}

		for (i = 0; i < 7; i++) {
			ret = deq(&data);
			if (ret == -1) {
				break;
			}

			printf("%d ", data);
		}
		printf("\n");
	}

	return 0;
}
コード例 #15
0
ファイル: q.c プロジェクト: chungae9ri/dsa
int main()
{
	int c, age;
	char name[16];
	struct qnode el;
	struct qnode *pel;

	c = getchar();
	while(c != 'q') {
		if(c=='p') {
			printf("input name : ");
			scanf("%s", el.name);
			printf("input age : ");
			scanf("%d", &el.age);
			enq(el);
		} else if(c=='d') {
			pel = deq();
			printf("dequeue name : %s\n", pel->name);
			printf("dequeue age : %d\n", pel->age);
			free(pel);
		}
		c=getchar();
	}
	xfree();
	return 0;
}
コード例 #16
0
ファイル: pingtest.c プロジェクト: beekhof/dlm
static int convert_lock(int mode)
{
    int status;
    int old_mode = cur_mode;

    printf("converting to %d\n", mode);

    /* Lock it */
    status = sys$enq(0,
		     mode,
		     &our_lksb,
		     LCK$M_CONVERT | LCK$M_VALBLK,
		     NULL,
		     0, /* parent */
		     compast_routine,
		     0, /* astp */
		     blockast_routine,
		     PSL$C_USER,
		     RSDM$K_PROCESS_RSDM_ID,
		     0);

    if (status != SS$_NORMAL)
    {
        printf("convert enq failed : %s\n", strerror(EVMSERR, status));
	sys$wake();
    }
    else
    {
	cur_mode = mode;
	status = 0; /* simulate Unix retcodes */
    }
    return status;
}
コード例 #17
0
ファイル: main.c プロジェクト: zyxstar/exam_c
int main(void)
{
	int arr[] = {11,22,33,44,55,66,77,88};
	int i, j;
	int data;
	int ret;

	for (j = 0; j < 4; j++) {
		for (i = 0; i < sizeof(arr) / sizeof(*arr); i++) {
			ret = enq(arr[i]);
			if (ret == -1) {
				printf("queue is full.\n");
				break;
			}
		}

		for (i = 0; i < sizeof(arr) / sizeof(*arr); i++) {
			ret = deq(&data);
			if (ret == -1) {
				printf("queue is empty.\n");
				break;
			}
			printf("%d ", data);
		}
		printf("\n");
	}

	return 0;
}
コード例 #18
0
/*------------------------------------------------------------------------
 *  lsr_queue - generate Link State Request packets
 *------------------------------------------------------------------------
 */
int
lsr_queue(struct ospf_if *pif, struct ospf_nb *pnb, struct ep *pepin)
{
	struct	ep	*pep = 0;
	struct	ip	*pipin = (struct ip *)pepin->ep_data;
	struct	ospf	*poin = (struct ospf *)pipin->ip_data;
	struct	ospf_dd	*pdd = (struct ospf_dd *)poin->ospf_data;
	struct	ospf_lss *plss;
	struct	ospf_db	*pdb;
	int		i, nlss;

	nlss = (poin->ospf_len - MINDDLEN) / LSSHDRLEN;
	plss = pdd->dd_lss;
	for (i=0; i<nlss; ++i, ++plss) {
		pdb = db_lookup(pif->if_area, plss->lss_type,
			plss->lss_lsid);
		if (pdb == 0)
			pep = lsr_add(pif, plss, pep);

/* if plss newer, pep = lsr_add(pif, plss, pep); */
	}
	if (pep && enq(pnb->nb_lsrl, pep, 0) < 0)
		freebuf(pep);
	lsr_xmit(pif, pnb);
}
コード例 #19
0
ファイル: packets6.c プロジェクト: GNS3/vpcs
int sub_udp(pcs *pc, struct packet *m)
{
	ethdr *eh;
	ip6hdr *ip;
	udphdr *ui;	
	struct packet *p;

	eh = (ethdr *)(m->data);
	ip = (ip6hdr *)(eh + 1);
	
	ui = (udphdr *)(ip + 1);
	
	if (IN6_IS_MULTICAST(&(ip->dst)))
		return PKT_DROP;
		
	/* udp echo reply */	
	char *data = ((char*)(ui + 1));
	if (memcmp(data, eh->dst, 6) == 0)
		return PKT_UP;
	
	p = (ip->ip6_hlim != 1) ? udp6Reply(m) :
	    icmp6Reply(pc, m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT);
		
	/* push m into the background output queue 
	   which is watched by pth_output */
	if (p != NULL)
		enq(&pc->bgoq, p);

	/* anyway tell caller to drop this packet */
	return PKT_DROP;		
}
コード例 #20
0
ファイル: command6.c プロジェクト: dlintott/vpcs
int ipauto6(void)
{
	struct packet *m = NULL;
	char buf6[INET6_ADDRSTRLEN + 1];
	struct in6_addr ipaddr;
	int n = 100;
	
	m = nbr_sol(&vpc[pcid]);
	vpc[pcid].ip6auto = 1;
	if (m != NULL)
		enq(&vpc[pcid].oq, m);
	do {
		usleep(10000);
		if (vpc[pcid].ip6.ip.addr32[0] != 0 || vpc[pcid].ip6.ip.addr32[1] != 0 || 
		    vpc[pcid].ip6.ip.addr32[2] != 0 || vpc[pcid].ip6.ip.addr32[3] != 0) {	
			memset(buf6, 0, INET6_ADDRSTRLEN + 1);
			memcpy(ipaddr.s6_addr, vpc[pcid].ip6.ip.addr8, 16);
			vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1);
			printf("GLOBAL SCOPE      : %s/%d\n", buf6, vpc[pcid].ip6.cidr);
			printf("ROUTER LINK-LAYER : ");
			PRINT_MAC(vpc[pcid].ip6.gmac);
			printf("\n");
			return 1;
		}
	} while (--n > 0);
	
	printf("No router answered ICMPv6 Router Solicitation\n");
	return 1;
}
コード例 #21
0
ファイル: t_lib.c プロジェクト: wtaylor45/Thread-Library
/*
 * Creates a new thread with it's own context, a given id & given priority
 * Enqueues it into the ready queue
 */
int t_create(void (*fct)(int), int id, int pri)
{
  size_t sz = 0x10000;
  
  tcb *new_tcb = malloc(sizeof(tcb));
  
  ucontext_t *uc;
  uc = (ucontext_t *) malloc(sizeof(ucontext_t));

  getcontext(uc);

  uc->uc_stack.ss_sp = mmap(0, sz,
       PROT_READ | PROT_WRITE | PROT_EXEC,
       MAP_PRIVATE | MAP_ANON, -1, 0);
  uc->uc_stack.ss_size = sz;
  uc->uc_stack.ss_flags = 0;
  uc->uc_link = running; 
  makecontext(uc, (void *)fct, 1, id);
  
  new_tcb->thread_id = id;
  new_tcb->thread_priority = pri;
  new_tcb->thread_context = uc;
  new_tcb->next = NULL;
 
  enq(new_tcb);
}
コード例 #22
0
ファイル: ue_write.c プロジェクト: m3y54m/32bitmicro
/*------------------------------------------------------------------------
 * ue_write - write a single packet to an SMC Ultra Ethernet
 *------------------------------------------------------------------------
 */
int
ue_write(struct devsw *pdev, unsigned char *pep0, unsigned len)
{
	struct ep	*pep = (struct ep *)pep0;
	struct utdev	*pud;

	pud = (struct utdev *)pdev->dvioblk;
	if (len > EP_MAXLEN) {
		nif[pud->ud_ifnum].ni_odiscard++;
		freebuf(pep);
		return SYSERR;
	}
	/* subtract the local header */
	len -= (int)&pep->ep_eh - (int)pep;
	if (len < EP_MINLEN)
		len = EP_MINLEN;
	memcpy(pep->ep_src, pud->ud_paddr, EP_ALEN);
	pep->ep_len = len;
	pep->ep_type = hs2net(pep->ep_type);
	pep->ep_order &= ~EPO_NET;
		
	if (enq(pud->ud_outq, pep, 0) < 0) {
		nif[pud->ud_ifnum].ni_odiscard++;
		freebuf(pep);
		ue_wstrt(pud);
		return SYSERR;
	}
	ue_wstrt(pud);
	return OK;
}
コード例 #23
0
ファイル: kdebug.c プロジェクト: aunali1/exopc
/* ************************************************
 * this function is the entry point for kernel
 * debuging.  It is called by xokpkt_recv in pkt.h
 * It is assumed that data "kdebug_is_debug_pkt".
 * *************************************************/
void kdebug_pkt (char *data, int size)
{
  int i, min; 
  char c;
  assert (kdebug_didinit);

  if(!kdebug_return_didinit)
    {
      kdebug_return_init(data);
      if (!in_exception_handler)
	{
	  asm("int $3"); 
	  /*
	   * When you connnect to the target from gdb
	   * you end up here.  
	   */
	  asm("nop");  /* Now, set the brkpts you want and continue. */
	}
    }

  /* the udp_len field might lie, so must be careful */     
  min = MIN(ntohs(UDP(data)->udp_len) - 8, size - 14 - 20 - 8);
  for (i=0 ; i < min; i++)
    {
      char c = UDP(data)->udp_data[i];
      if (c == '\003' && !in_exception_handler)
	asm ("int $3");  /* you end up here if you typed Ctrl-C, into gdb */
      else
	enq(c);
    }
}
コード例 #24
0
/*------------------------------------------------------------------------
 *  dd_queue - generate Data Description packets
 *------------------------------------------------------------------------
 */
void
dd_queue(struct ospf_if *pif, struct ospf_nb *pnb)
{
	struct	ep	*pep;
	struct	ip	*pip;
	struct	ospf	*po;
	struct	ospf_dd	*pdd;

	pep = ospfddtmpl(pif);
	if (pep == 0)
		return;
	pip = (struct ip *)pep->ep_data;
	po = (struct ospf *)pip->ip_data;
	pdd = (struct ospf_dd *)po->ospf_data;

	if (pnb->nb_state == NBS_EXSTART) {
		pdd->dd_control = DDC_INIT | DDC_MORE | DDC_MSTR;
		pdd->dd_seq = hl2net(pnb->nb_seq);
		if (enq(pnb->nb_dsl, pep, 0) < 0)
			freebuf(pep);
		dd_xmit(pif, pnb);
		pnb->nb_trexmt = pif->if_rintv;
		return;
	}
	/* else we're in EXCHANGE state */
	lss_build(pif, pnb, pep);
	dd_xmit(pif, pnb);
	if (pnb->nb_master)
		pnb->nb_trexmt = pif->if_rintv;
}
コード例 #25
0
ファイル: QUEUE.C プロジェクト: padmaceg/Datastructures
void main()
{
     int x,c,ch,no;
     //int que[100];
     clrscr();
     do
     {
     printf("\n1.Enqueue\n2.Dequeue : ");
     scanf("%d",&x);
     if(x==1)
     {
	if(size==99)
	   printf("\nStack is full...") ;

	else
	{
	    printf("\nEnter the number : ");
	    scanf("%d",&no);
	    enq(no);
	}
       //	disp(que,size);
     }
     else
     {
	   deq();

     }
       disp();
    printf("\nDo u wnt to conti ? 1.yes 2.no");
    scanf("%d",&ch);
    }while(ch!=2);
     getch();
}
コード例 #26
0
ファイル: t_lib.c プロジェクト: wtaylor45/Thread-Library
/*
 * Remove the first thread from the semaphore queue
 * Add it to the ready queue, as per Mesa Semantics
 */
void sem_deq(sem_t *s){
	tmp = s->first;
	if(s->first->next){
		s->first = s->first->next;
	}else
		s->first = NULL;
	enq(tmp);
}
コード例 #27
0
/**
 * wxThreadのテスト
 */
void HelloWorld::OnTestLockedQueue(wxCommandEvent& event) {

     // キューを作成 サイズは2
     wxMutex mutex;
     wxCondition enq(mutex), deq(mutex);
     wxLockedQueue<int> lq(2, &mutex, &enq, &deq);
     //WorkerThread<int>* thread = new WorkerThread<int>(lq);
}
コード例 #28
0
void main(int argc, char *argv[])
{
    int no, ch, e;

    /* Serena's seed */
    int sseed;
    if (argc == 2) {
      sseed = atol(argv[1]);
    }
    srand(sseed);

    int max_actions = 100;
    int nactions = rand() % max_actions;
    
    /* printf("\n 1 - Enque");
    printf("\n 2 - Deque");
    printf("\n 3 - Front element");
    printf("\n 4 - Empty");
    printf("\n 5 - Exit");
    printf("\n 6 - Display");
    printf("\n 7 - Queue size"); */
    create();
    for (int i = 0; i < nactions; i++)
    {
        printf("\n Enter choice : ");
        ch = rand() % 7 + 1;
        switch (ch)
        {
        case 1:
            printf("Enter data : ");
            no=rand() % max_actions;
            enq(no);
            break;
        case 2:
            deq();
            break;
        case 3:
            e = frontelement();
            if (e != 0)
                printf("Front element : %d", e);
            else
                printf("\n No front element in Queue as queue is empty");
            break;
        case 4:
            empty();
            break;
        case 6:
            display();
            break;
        case 7:
            queuesize();
            break;
        default:
            printf("Wrong choice, Please enter correct choice  ");
            break;
        }
    }
}
コード例 #29
0
ファイル: packets6.c プロジェクト: GNS3/vpcs
int sub_nbsol(pcs *pc, struct packet *m)
{
	ethdr *eh;
	ip6hdr *ip;
	ndhdr *nshdr;
	ndopt *nsopt;
	ip6 *tip6 = NULL;
	
	eh = (ethdr *)(m->data);
	ip = (ip6hdr *)(eh + 1);
	nshdr = (ndhdr *)(ip + 1);
	nsopt = (ndopt *)(nshdr + 1);
	
	if (eh->dst[0] != 0x33 || 
	    eh->dst[1] != 0x33 ||
	    eh->dst[2] != 0xff ||
	    ip->ip6_hlim != 255 ||
	    ip->dst.addr16[0] != IPV6_ADDR_INT16_MLL ||
	    ip->dst.addr32[1] != 0 ||
	    ip->dst.addr32[2] != IPV6_ADDR_INT32_ONE ||
	    ip->dst.addr8[12] != 0xff) {
		return PKT_DROP;
	}
	
	if (eh->dst[3] != pc->ip6.ip.addr8[13] ||
	    eh->dst[4] != pc->ip6.ip.addr8[14] ||
	    eh->dst[5] != pc->ip6.ip.addr8[15] ||
	    ip->dst.addr32[3] != (pc->ip6.ip.addr32[3] | 0xff)) {
		if (eh->dst[3] != pc->link6.ip.addr8[13] ||
		    eh->dst[4] != pc->link6.ip.addr8[14] ||
		    eh->dst[5] != pc->link6.ip.addr8[15] ||
		    ip->dst.addr32[3] != (pc->link6.ip.addr32[3] | 0xff)) {
			return PKT_DROP;
		} else
			tip6 = &pc->link6.ip;	
	} else
		tip6 = &pc->ip6.ip;			

	/* send advertisement */
	memcpy(ip->dst.addr8, ip->src.addr8, 16);
	memcpy(ip->src.addr8, tip6->addr8, 16);
		
	nshdr->hdr.type = ND_NEIGHBOR_ADVERT;
	nshdr->hdr.code = 0;
	nshdr->nd_na_flags = ND_RA_FLAG_OTHER | ND_RA_FLAG_HA;
	nsopt->type = 2;
	memcpy(nsopt->mac, pc->ip4.mac, ETH_ALEN);
		
	nshdr->hdr.cksum = 0;
	nshdr->hdr.cksum = cksum6(ip, IPPROTO_ICMPV6, ntohs(ip->ip6_plen));
	
	memcpy(eh->dst, eh->src, ETH_ALEN);
	memcpy(eh->src, pc->ip4.mac, ETH_ALEN);	

	enq(&pc->oq, m);
	
	return PKT_ENQ;
}
コード例 #30
0
ファイル: fila.c プロジェクト: edgardpn/ED_2014
void geraval(int *vetor,int tamvet)
{
    int i;
    
    srand( (unsigned)time(NULL) );

    for(i=0 ; i < tamvet ; i++)
        enq(rand()%100);
}