gpt4 book ai didi

c - 使用 gnokii gn_sms_send 发送消息时出现段错误

转载 作者:行者123 更新时间:2023-11-30 16:02:25 29 4
gpt4 key购买 nike

这里是代码人员:

#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;
}

我要发送一条短信到+628571641111,文本为“tesss”,但不幸的是操作系统说它段错误,那么,我的错在哪里?

$ 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)

最佳答案

您正在向 gn_data_clear 传递一个尚未初始化的指针。在你的主要功能的开始,你需要有

gn_data     data;

不是

gn_data     *data;

函数实现如下:

GNOKII_API void gn_data_clear(gn_data *data)
{
memset(data, 0, sizeof(gn_data));
}

关于c - 使用 gnokii gn_sms_send 发送消息时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5343719/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com