0

here are the code folks :

#include <stdio.h>
#include <stdlib.h>
#include <gnokii.h>
#include <signal.h>
/*
 * 
 */

#define _(x) x

struct gn_statemachine *state = NULL;

void busterminate(void) {
    gn_lib_phone_close(state);
    gn_lib_phoneprofile_free(&state);
    gn_lib_library_free();
}

void businit(void) {
    gn_error    error;

    atexit(busterminate);

    error = gn_lib_phoneprofile_load(NULL, &state);
    if (GN_ERR_NONE == error) {
        error = gn_lib_phone_open(state);
    }

    if (GN_ERR_NONE != error) {
        fprintf(stderr, "%s\n", gn_error_print(error));
        exit(-1);
    }
}

void signal_handler(int signal) {
    (void)signal;
    exit(-2);
}

int main(int argc, char *argv[]) {
    gn_data     *data;
        gn_sms          sms;
    gn_error    error;


    businit();

    signal(SIGINT, signal_handler);

    gn_data_clear(data);

        sprintf(sms.remote.number,"%s","+628571641111");
        sprintf(sms.user_data[0].u.text,"%s","tesss");

        data->message_center    = calloc(1, sizeof(gn_sms_message_center));
        data->message_center->id= 1;

    error = gn_sm_functions(GN_OP_GetSMSCenter, data, state);
    if(error == GN_ERR_NONE)
    {
        snprintf(sms.smsc.number,sizeof(sms.smsc.number),"%s",data->sms->smsc.number); // set to sms.smsc.number from data.sms.smsc.number
        sms.smsc.type = data->message_center->smsc.type;
        //g_slice_free(gn_sms_message_center,data->message_center); // free the ram
        free(data->message_center);
    }
    if(!sms.smsc.number[0])
    {
        printf("failed once getting sms center number\n");

    }
    if(!sms.smsc.type)
    {
        sms.smsc.type = GN_GSM_NUMBER_Unknown;
    }

     data->sms = &sms;

    //send the message
    error = gn_sms_send(data,state);

    if(error == GN_ERR_NONE)
    {
        if(sms.parts > 1)
        {
            int j;
            printf("sms sent with : %d parts, and reference number is : ", sms.parts);

            for(j=0; j < sms.parts; j++)
            {
                printf("%d\n",sms.reference[j]);
            }
        }
        else
        {
            printf("one sms sent with reference number : %d\n",sms.reference[0]);
        }
    }
    else
    {
        printf("libgnokii error : %s\n",gn_error_print(error));
    }

    free(sms.reference);

    return 0;
}

im gonna send an sms to +628571641111, with the text "tesss", but unfortunately the OS said it segmentation fault, thus, where is my fault ?

$ gnokii --identify
GNOKII Version 0.6.29
IMEI         : 3556XXXXX509XXX
Manufacturer : ZTE INCORPORATED
Model        : MF627
Product name : MF627
Revision     : BD_3GHAP673A4V1.0.0
$ gdb -q ./gnokii_send_sms 
Reading symbols from /root/gnokii_send_sms...(no debugging symbols found)...done.
(gdb) r
Starting program: /root/gnokii_send_sms 
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00317334 in ?? () from /lib/libc.so.6
(gdb) 
capede
  • 945
  • 1
  • 13
  • 26

1 Answers1

1

You're passing to gn_data_clear a pointer you haven't initialized yet. In the beginning of your main function you need to have

gn_data     data;

Not

gn_data     *data;

Here's the function implementation:

GNOKII_API void gn_data_clear(gn_data *data)
{
        memset(data, 0, sizeof(gn_data));
}
ThePosey
  • 2,734
  • 2
  • 19
  • 20
  • your answer is true, but after that the compiler seems appear to be pointed the error on function gn_sms_send, which mean the required structure is not complete in order to get the sms send, do you have any idea what is un-initialize var on data which is necessary in order to do send sms ? – capede Mar 17 '11 at 20:15
  • I've been looking at the code on this site: http://www.sfr-fresh.com/linux/misc/gnokii-0.6.30.tar.gz/dox/index.html In gn_sms_send it of course does alot of dereferencing and writing to the data pointer so it would crash there as well. Try the change and see what happens. – ThePosey Mar 18 '11 at 11:26
  • its more a lot than we could believe... i've set destination number with its type, smsc number, txt, and so forth, but still segmentation error though, now im feel dizzy while looking deeply inside gnokii source for gn_sms_send() and these function really work and what he is really need ... hhhh – capede Mar 18 '11 at 14:56
  • ahh i found the worst, i just forget to intialize gn_sms to zero , memset() will done it.... – capede Mar 19 '11 at 05:39