编译器警告"签名不同"
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
答案 0 :(得分:4)
您正在使用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