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 8009995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:36:25+00:00 2026-06-04T18:36:25+00:00

I get the SIGSEGV – Segmentation Fault on the run-time for the code below

  • 0

I get the SIGSEGV – Segmentation Fault on the run-time for the code below when the function (log_msg_send) is called. I read that it is about memory violation but I could not find the reason. I would appreciate for the any suggestions/help.

 #define  MAXSTRINGLENGTH 128
#define BUFSIZE 512

void log_msg_send(char *message, char *next_hop);

struct routing {
        int hop_distance;
        char sender_ID[16]; 
};

struct routing user_list[40]  =  { [0]={0,0,0,0}};


int main(int argc,char *argv[]){
    strcpy(user_list[0].sender_ID,"192.168.001.102");
    char message[1000];
    strcpy(message,"123456123456");
     log_msg_send(message, user_list[0].sender_ID);

    return 0;
}

void log_msg_send(char *message, char *next_hop){
    char *SRV_IP;
    strcpy(SRV_IP,  next_hop);

    if (sizeof(SRV_IP) == 16){
         struct sockaddr_in si_other;
         int s, i, slen=sizeof(si_other);
         char buf[60] ;
         strcpy(buf, message);

        if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
          fprintf(stderr, "socket() failed \n");
          exit(1);
        }

        memset((char *) &si_other, 0, sizeof(si_other));
        si_other.sin_family = AF_INET;
        si_other.sin_port = htons(33333);
        if (inet_aton(SRV_IP, &si_other.sin_addr) == 0) {
          fprintf(stderr, "inet_aton() failed \n");
          exit(1);
        }

          if (sendto(s, buf, BUFSIZE, 0,(struct sockaddr *) &si_other, slen)==-1){
          fprintf(stderr, "sendto() failed \n");
          exit(1);
        }

        close(s);
    }
}

PS. For the people who have the SIGSEGV problem. Most common reasons for SIGSEV problem:
– attempting to execute a program that does not compile correctly. Note that most compilers will not output a binary given a compile-time error.
– a buffer overflow.
– using uninitialized pointers.
– dereferencing NULL pointers.
– attempting to access memory the program does not own.
– attempting to alter memory the program does not own (storage violation).
– exceeding the allowable stack size (possibly due to runaway recursion or an infinite loop)

  • 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-06-04T18:36:26+00:00Added an answer on June 4, 2026 at 6:36 pm

    You don’t allocate memory for SRV_IP

    char *SRV_IP;
    strcpy(SRV_IP,  next_hop);
    

    so the strcpy tries to access invalid memory.

    char *SRV_IP = malloc(strlen(next_hop)+1);
    if (!SRV_IP) exit(1);
    strcpy(SRV_IP,  next_hop);
    

    Then you check

    if (sizeof(SRV_IP) == 16){
    

    but SRV_IP is a char*, so its size is whatever size char pointers have, usually 8 or 4 bytes. You probably meant the length, so would have to use strlen.

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

Sidebar

Related Questions

I will below describe the error that I get when calling the function sscanf
When I run the following function I get a SIGSEGV. I can't figure out
Trying to run a C++ program , I get segmentation faults which appear to
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -177935456 (LWP 5483)] 0xf79ff2ca in
I have the following code. I get a SIGSEGV occasionally. I have a feeling
Get sunrise time and sun set times from xml from web. This is the
//get the lat and loni throgh the loaddata function.java.util.ConcurrentModificationException at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64) How to resolve
I get this exception in my code: ...IllegalArgumentException...Cant use FLAG_RECEIVER_BOOT_UPGRADE here... Looking into the
when i try to assign values to dynamic array using function scanf, i'll get
According to various sourcess Linux at x86 tries to get rid of segmentation by

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.