[英]Destination port unreachable in my udp client socket
int udp_sock() {
//Create socket
sock = socket(AF_INET , SOCK_DGRAM , 0);
if (sock == -1) {
printf("Could not create socket\n");
}
puts("Socket created.......\n");
server1.sin_addr.s_addr = inet_addr("172.210.110.10");
server1.sin_family = AF_INET;
server1.sin_port = htons(PORT);
//Connect to remote server
con= connect(sock , (struct sockaddr *)&server1 , sizeof(server1));
if(con<0) {
perror("connect failed. Error\n");
return con;
}
puts("Connected\n");
return 0;
}
The packet is reaching server mentioned, but the error "destination port unreachable" comes up in Wireshark.数据包正在到达提到的服务器,但在 Wireshark 中出现错误“目标端口无法访问” 。
Any suggestions will be helpful.任何建议都会有所帮助。
There needs to be a server waiting on the other end.需要有一个服务器在另一端等待。 A simple way for testing is to use netcat.
一种简单的测试方法是使用 netcat。
nc -lu 8053
Alternatively set up a utility that is designed for udp testing, such as echo server.或者设置一个专为 udp 测试而设计的实用程序,例如回声服务器。 This is normally built into an inetd or xinetd server
这通常内置在 inetd 或 xinetd 服务器中
If you want to intercept incoming udp packets you will need to use bind() select()/poll()/epoll() and recvfrom()如果要拦截传入的 udp 数据包,则需要使用 bind() select()/poll()/epoll() 和 recvfrom()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.