Quote:
Originally Posted by xpi0t0s View Post
Please use code blocks when posting code. It preserves formatting and uses a monospaced font, thus making code easier to read. You did before so I'm not clear why you didn't this time.

From what I've seen of what you've posted (in code blocks, I didn't bother looking at the code that wasn't), I couldn't see any glaringly obvious mistakes.

But the only way I can know if the code is correct is by building and running it. However, I can't do that as I only have partial code. But you can, because you have the complete code.
So I suggest you should answer your own question by building and running the code. If it does what you expect, then yes the flow is correct. If the flow is wrong then the program won't do what you are expecting.

Sorry if this seems unhelpful but it's really difficult to read someone else's code and work out what their intent was from the code itself, particularly if they're a beginner. The best way to check if the code works is to run it. The only way I can check the code works is by running it myself, but (a) you need to provide complete code so that I can do that, and (b) why should I do it when you are perfectly capable of doing it?

Once you've built and run the code (or just attempted to build it if there were errors), cut the code down to the bare minimum, so for example just do the linked list stuff and keep the rest to a minimum, post the complete (stripped down) code, state precisely and in full detail what the problem is (so not "it doesn't work"), then I stand a chance of working out what might be wrong.

List flow in the thread-1 is given below. remaining text is omitted. It is only how each time a new packet comes and is being stored using the link list node and so the list extends.
Code:
pnode=pktlist; // START OF THE LIST

//Here is the data (packet len, original packet and other stuff) added to the node


if(pktlist == NULL)  // pktlist is the start of the list
        {

      
          pktlist=pnode;
          phead=pnode;
          pcurr=pnode;
        }
      else
        {
          
          pcurr->next =pnode;
          pcurr=pcurr->next;
}
Please check the following thread that
1. I have to take out the smallest packet from the list. I have to take it out only when the clock time reaches the smallest packet's time stamp.
2. When the smallest packet is retrieved, it should be sent when the current clock time reaches the time stamp value
3. How to remove the node from the list in the following thread when the packet is sent. Using demalloc() ??
4. How should i create the new nodes as after some time when all the nodes are removed from the list.

Full code of this thread is given ( header files are removed only).
Code:
pthread_mutex_t mutex_send=PTHREAD_MUTEX_INITIALIZER;

pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void* sender(void* ptr)
{
  printf("sender1....-4");
  printf("SENDER1 --I am inside the sender1 thread to send packets \n");
  printf("sender1...-3");
  //  rPos=-3;
  printf("sender1... -2");
  sendProcess *mySend;
  int Fd;
  int nics;
  printf("sender 1... -1");
  extern int semaphore;
  struct sembuf sWait={0,-1,0};
  union semun sSet;
  unsigned char destAddr[6];
  char* nic;
  struct timeval curr_time;
  mySend=(sendProcess*)ptr;

  int sentPkts=0;
  // pktCnt=cProc->pktCnt;
  int len1=0;
  int pktCnt=0;

  sSet.val=1;
  semaphore=mySend->semaphore;
  Fd=mySend->Fd;
  //   rPos=-1;
  //  printf("sender1 .. 1");
  unsigned char buf[4092];

  int retVal;
  printf("SENDER1--Fd is %d",Fd);

  printf("sender 1... 1");


  //  printf("sender1 .. 2");
 
  snode=scurr=pktlist;
 
  printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.snode=%d,scurr=%d,pktlist=%d",snode,scurr,pktlist);
do
  {
  pthread_mutex_lock( &mut );


   //     pthread_mutex_lock( &mut );
      while(scurr->next!=NULL);
     {
       if(snode->ts.tv_sec < scurr->ts.tv_sec && snode->ts.tv_usec < scurr->ts.tv_usec)
	    {
	      TMPNode=snode;
	      snode=scurr;
	      scurr=TMPNode;
	    }
       
       scurr=scurr->next;
     }
   
	
	 
       gettimeofday(&curr_time,NULL);	  
       if(curr_time.tv_sec >= snode->ts.tv_sec  && curr_time.tv_usec >= snode->ts.tv_usec)
	 {
	   
	   struct sockaddr_ll destAddr;
	   memcpy(buf,&snode->pkt,snode->pkt_len);
	   memcpy(&(destAddr.sll_addr),&buf,MAC_ADDR_LEN);
	   destAddr.sll_family=PF_PACKET;
	   destAddr.sll_protocol=htons(ETH_P_ALL);
	   destAddr.sll_ifindex=2;
	   destAddr.sll_pkttype=PACKET_OTHERHOST;
	   destAddr.sll_halen=ETH_ALEN;
	   if(snode2->rFlag==0 && snode2->wFlag==1)
	     {
	       
	       if((retVal=write(Fd,snode->pkt,snode->pkt_len))==-1)
		 {
		   printf("retVal is %d",retVal);
		   printf("sendto() error \n");
		 }
	       printf("SENDER 1 --- packet number is %d OF length %d Sent \n",snode2->pkt_id,retVal);
	       snode2->rFlag=1;
	       snode2->wFlag=0;
	     }
	   
	 }
  pthread_mutex_unlock( &mut );
       snode=snode->next;
  }while(snode->next != NULL);
Please don't mind my things as I am new to C and new to forums also and I need to do the task in a short time so that did not follow the rules.