1
#include <stdio.h>
#include <sys/socket.h>
#include <netdb.h>
int main() {
char buf[4] = { 0xff, 0xff, 0xff, 0xff };
struct addrinfo adr, *res;
adr.ai_family = AF_INET;
adr.ai_socktype = SOCK_DGRAM;
getaddrinfo ("192.168.1.1", NULL, &adr, &res);
int sd = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
if (sendto (sd, buf, sizeof (buf), MSG_OOB, res->ai_addr, res->ai_addrlen) < 0)
perror ("ERROR sendto"); //I have added an if tag and an error message posiblility
return 0;
}
ERROE SENDTO:不支持的操作Linux UDP客戶端,如何?
這是所有的消息。 beej的指南網絡編程,我已經讀了getaddrinfo的第二個參數是NULL,並且我編譯了它,它會很好,這一行沒有問題。現在,問題是操作不支持的錯誤消息。
你在哪裏指定目標端口? – hek2mgl
你應該看看'sendto'之類的東西的返回值,並適當地檢查'errno'。 – Joe
請檢查http://www.abc.se/~m6695/udp.html – hek2mgl