Segmentation fault error

  • @i have a structure as follows
    @struct image_data
    int msgid;
    const char * fname;

    am assigning values to this structure as msgid =6 and fname = a.bmp
    then am sending the structure on udp to some other application on different machine
    and also am doing the qftp of this bmp file

    am able to get this file on other machine

    now my motto is to display the image file
    so what am doing is am displaying the fname which is filename of the image on the gui of other application.

    so when am displaying the structure data at the console am getting segmentation fault error
    when i have tried file name with the single char am getting the filename with single char at receiving end but when am trying with char * it is showing segmentation fault error

    am attaching the code here

    @#include "GroundThread.h"

    struct Message
    int message_id;

    struct img_file
    int msg_id;
    const char* fname;

    GroundThread::GroundThread(QObject *parent)
    //restart = false;
    //abort = false;


    void GroundThread::run()

    void GroundThread::process_data()
    std::cerr<<"am in thread"<<std::endl;
    Message msg;
    int fd;

    struct sockaddr_in servaddr, cliaddr;

    void **status;

    fd = socket(AF_INET,SOCK_DGRAM,0);

    if(fd <0)
    cout<<"Socket creation Failed"<<endl;

    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = inet_addr(""); //server ip addr
    servaddr.sin_port = htons(12000); //server poet no.
    if(bind(fd,(const struct sockaddr *)&servaddr,sizeof(servaddr))<0)
    cout<<"BIND FAILED"<<endl;
    unsigned char buffer[MAX_DATA_SIZE];

    socklen_t len=sizeof(cliaddr);



    int n= recvfrom(fd,buffer,sizeof(buffer),0,(struct sockaddr *)&cliaddr,&len);


    cout<<"Received : bytes"<<n<<" "<<msg.message_id<<endl;
    if(msg.message_id ==6)
    cout<<"img msgid:"<<imgData.msg_id<<endl;
    cout<<"img filename:"<<imgData.fname<<endl;


    if(n<1) continue;

    // emit received_data(buffer);

    // return NULL;


    please tell me how should i solve this

    thank u

  • Lifetime Qt Champion


    Please enclose your code with coding tags, otherwise it's really hard to read.

    Since you are using Qt, why not use QUdpSocket and Qt's container (i.e QByteArray) ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.