我使用http://www.abc.se/~m6695/udp.html上的代码
代码工作正常,我可以看到消息已发送并且服务器接收到它。但是,当我构建程序时,对于“”行,我得到以下“从不兼容的指针类型 [默认启用] 传递 'sendto' 的参数 5 if (sendto(s, buf, BUFSIZE, 0, &si_other, slen)==-1){
”。如果有人能告诉我如何解决,我将不胜感激。谢谢你
#define MAXSTRINGLENGTH 128
#define BUFSIZE 512
void log_msg_send(char *message, char *next_hop);
void log_msg_send(char *message, char *next_hop);
int main(int argc, char** argv) {
char hello[] = "hello bitches";
char next_hop[]= "192.168.1.178";
log_msg_send(hello, next_hop);
}
void log_msg_send(char *message, char *next_hop){
char SRV_IP[16];
strcpy(SRV_IP, next_hop);
struct sockaddr_in si_other;
int s, i, slen=sizeof(si_other);
char buf[50] ;
strcpy(buf, message);
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
si_other.sin_port = htons(33333);
if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}
printf("Sending the packet %d\n", i);
if (sendto(s, buf, BUFSIZE, 0, &si_other, slen)==-1){
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}
close(s);
}