troubleshooting Question

How do I solve this segmentation fault in my C programon Reliable Protocol Implementation

Avatar of dinoguy
dinoguy asked on
5 Comments1 Solution243 ViewsLast Modified:
hi Everyone,

Please find below a listing of my program protocol.cpp.
When I compile the program using the make command in Linux, it compiles without errors but it halts when run giving a segmentation fault. Can someone plese be kidn enough to point out ot me wher ethis problem is coming from and how to solve it. Many Thanks.

// protocol.cpp
#include "protocol.h"
#include "simul.h"
#include "timer.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXDATA 10 //define the maxvalue of the data size which is 10.
#define MAX_SEQ 7 /*should be 2^n-1*/

struct HEADER {       // header which has info and frame
  short checksum;
  char type;

enum frameTypes{DATA,ACK,NAK};

struct FRAME{
      HEADER header;
      char data[MAXDATA];

struct NODE{
      NODE *next; //This is a link to the next item in the quque
      int length;
      FRAME frame;

struct protocolInfo {
  // control information
  NODE *head, *tail;
  int seqnum;
  int acknum;
  short checksum;
  char data[10];
} protoInfo[2];

short checksum(const char *data,int length){
      int i;short cs=0;
      for(i=0; i<length;i++){
      return cs;

void init(char side) {
      protocolInfo *ptr=&protoInfo[side-'A'];

void send(char side, const char *message, int length) {
      // From here on ONLY use the pointer pi
      protocolInfo *ptr=&protoInfo[side-'A'];
      NODE *p=(NODE *)malloc(sizeof(NODE));

      // Simplistic solution transmits the data "as is"
      output(side,(char*)&(ptr->head->frame), ptr->head->length+sizeof(HEADER));
void input(char side, const char *frame, int length) {
      protocolInfo *ptr=&protoInfo[side-'A'];
      FRAME *f=(FRAME*)frame;
            //The checksum is wrong!
            printf("The Checksum is wrong!\n");

       protocolInfo *Nptr = &protoInfo[side - 'B'];

            printf("The Checksum is correct!\n");


void timerInterrupt(char side) {}

also what are some lines of codes that I can write in the function void Timer Interrupt?



Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros