Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 807177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:21:49+00:00 2026-05-15T00:21:49+00:00

I’m designing a protocol (in C) to implement the layered OSI network structure, using

  • 0

I’m designing a protocol (in C) to implement the layered OSI network structure, using cnet (http://www.csse.uwa.edu.au/cnet/). I’m getting a SIGSEGV error at runtime, however cnet compiles my source code files itself (I can’t compile it through gcc) so I can’t easily use any debugging tools such as gdb to find the error.

Here’s the structures used, and the code in question:

typedef struct {
    char *data;
} DATA;

typedef struct {
    CnetAddr src_addr;
    CnetAddr dest_addr;
    PACKET_TYPE type;           
    DATA data;
} Packet;

typedef struct {
    int length;         
    int checksum;   
    Packet datagram;
} Frame;


static void keyboard(CnetEvent ev, CnetTimerID timer, CnetData data)
    {
    char line[80];
    int length;

    length = sizeof(line);
    CHECK(CNET_read_keyboard((void *)line, (unsigned int *)&length)); // Reads input from keyboard

    if(length > 1)
        {           /* not just a blank line */
        printf("\tsending %d bytes - \"%s\"\n", length, line);

        application_downto_transport(1, line, &length);
        }
    }

void application_downto_transport(int link, char *msg, int *length)
    {
    transport_downto_network(link, msg, length);
    }

void transport_downto_network(int link, char *msg, int *length)
    {
    Packet *p;
    DATA *d;

    p = (Packet *)malloc(sizeof(Packet));
    d = (DATA *)malloc(sizeof(DATA));

    d->data = msg;
    p->data = *d;

    network_downto_datalink(link, (void *)p, length);
    }

void network_downto_datalink(int link, Packet *p, int *length)
    {
    Frame *f;

    // Encapsulate datagram and checksum into a Frame.
    f = (Frame *)malloc(sizeof(Frame));

    f->checksum = CNET_crc32((unsigned char *)(p->data).data, *length); // Generate 32-bit CRC for the data.
    f->datagram = *p;
    f->length = sizeof(f);

    //Pass Frame to the CNET physical layer to send Frame to the require link.
    CHECK(CNET_write_physical(link, (void *)f, (size_t *)f->length));
    free(p->data);
    free(p);
    free(f);
    }

I managed to find that the line: CHECK(CNET_write_physical(link, (void *)f, (size_t *)f->length)); is causing the segfault but I can’t work out why.
Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:21:50+00:00Added an answer on May 15, 2026 at 12:21 am

    I think is the third parameter. Try this:

    CHECK(CNET_write_physical(link, (void *)f, (size_t *)(&f->length)));
    

    In this line, I assume third parameter expects a pointer, because you are casting a value to a (size_t *). But the value you are casting is a simple integer value. So, whenever the function dereferences the address contained in that value, is when you probably get a SIGSEGV.

    With the code I suggested, you are casting a pointer (&f->length). So you should be good to go, assuming the function is effectively expecting a pointer to a variable holding a size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 426k
  • Answers 426k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It means you are already in screen named "bash" Just… May 15, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer The context itself is not a part of the context,… May 15, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer When you reload manually, most browsers disregard the caching headers,… May 15, 2026 at 12:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.