在Qt线程里面如何给一个结构体分配套接字地址结构
该代码源自于traceroute功能中的片段,在linux终端能正确运行,但是写进Qt里面就报错:
invalid conversion from ‘void*’ to ‘sockaddr*’,求大神指点怎么修改此处。
其中红色字体错位错误代码(在Qt中报错):
pr->sasend = ai->ai_addr; /* contains destination address */
pr->sarecv = calloc(1, ai->ai_addrlen);
pr->salast = calloc(1, ai->ai_addrlen);
pr->sabind = calloc(1, ai->ai_addrlen);
pr->salen = ai->ai_addrlen;
pr结构体的定义:
struct proto
{
const char *(*icmpcode)(int);
int (*recv)(int, struct timeval *);
struct sockaddr *sasend;
struct sockaddr *sarecv;
struct sockaddr *salast;
struct sockaddr *sabind;
socklen_t salen;
int icmpproto;
int ttllevel;
int ttloptname;
} *pr;
Qt 多线程
[解决办法]
pr->sarecv = (struct sockaddr *) calloc(1, ai->ai_addrlen);