I want to write a program which simulate the behaviour of CSMA/CD protocol over Ethernet.

I want CSMA/CD program in c or c++ language.please sent this pragram on my email SNIP

I am confused. First you say you want to write the program. Then you say you want somebody to send the code for such a program to you.

I am confused. First you say you want to write the program. Then you say you want somebody to send the code for such a program to you.

those were two different people.

but as to that second guy, welcome to Daniweb. it's pretty much the reason why the long-term users here are often cynical and jaded towards noobs.

#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/time.h>
int x=0;
void capture()
{
	exit(0);
	}
int get()
{
	return x;
	}
void put()
{
	x++;
	}
void node(char *p)
{
	int name;
	int seq1,seq2,i=0;
	long t;
	struct timeval tv;
	struct timezone tz;
	name=atoi(p);
while(1)
{
	seq1=get();
	seq2=get();
	if(seq1==seq2)
	{
		put();
		seq1=get();
		gettimeofday(&tv,&tz);
		printf("station %d transmitting frame %d at %ld \n",name,++i,tv,tz);
		usleep(10);
		seq2=get();
		if(seq1!=seq2)
		{
		printf("station %d collision occured %d \n",name,i--);
		usleep(100);
			}
		else
		{
		printf("station %d transmission of frame %d success \n",name,i);
			}
		}
	usleep(200);
	}
}
main()
{
	pthread_t t1,t2,t3;
	signal(SIGINT,capture);
	pthread_create(&t1,0,(void *)node,"1");
	pthread_create(&t2,0,(void *)node,"2");
	pthread_create(&t3,0,(void *)node,"3");
	while(1);
	}
This article has been dead for over six months. Start a new discussion instead.