gpt4 book ai didi

编译器警告 "differ in signedness"

转载 作者:行者123 更新时间:2023-11-30 21:45:47 27 4
gpt4 key购买 nike

编译器警告“符号不同”

comm.c: In function ‘new_descriptor’:
comm.c:1017: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness
comm.c: In function ‘get_ident’:
comm.c:4043: warning: pointer targets in passing argument 3 of ‘getsockname’ differ in signedness
comm.c:4044: warning: pointer targets in passing argument 3 of ‘getpeername’ differ in signedness

void new_descriptor(int control)
{
static DESCRIPTOR_DATA d_zero;
DESCRIPTOR_DATA *dnew;
struct sockaddr_in sock;
BAN_DATA *pban;
char buf[MAX_STRING_LENGTH];
int desc;
int size;
int addr;
int hostcount;
DESCRIPTOR_DATA *d;

NORESOLVE_DATA *pnoresolve;
bool doresolve;

size = sizeof(sock);
if ((desc = accept(control, (struct sockaddr *) &sock, &size)) < 0) {
perror("New_descriptor: accept");
return;
}

还有

char *get_ident(int desc, u_long ip)
{
struct sockaddr_in us;
struct sockaddr_in them;
static char uid[MAX_STRING_LENGTH];
char buf[MAX_STRING_LENGTH];
int id;
int size;

strcpy(uid, "(unknown)");

if ((id = start_socket(ip, IDENT_PORT)) < 0)
return uid;

size = sizeof(us);

if (getsockname(desc, (struct sockaddr *) &us, &size)
|| getpeername(desc, (struct sockaddr *) &them, &size)) {
CLOSE(id);
return uid;
}

sprintf(buf, "%u, %u\n", ntohs(them.sin_port), ntohs(us.sin_port));

WRITE(id, buf, strlen(buf) + 1);

memset(buf, '\0', sizeof(buf));

READ(id, buf, sizeof(buf) - 1);

if (sscanf(buf, "%*d , %*d : USERID : %*s : %[^\r\n]s", uid) != 1)
strcpy(uid, "(unknown)");

if (!strcmp(uid, "0"))
strcpy(uid, "root");

CLOSE(id);
return uid;
}
#endif

最佳答案

您正在使用int size;,您不应使用int数据类型作为accept的第三个参数。

accept 的语法是 -

int Accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);//注意第三个参数

所以你应该使用socklen_t数据类型。尝试将 size 声明为 socklen_t 变量并尝试-

socklen_t size; //like this

关于编译器警告 "differ in signedness",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25199567/

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