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.
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.
nc -lu 8053
Alternatively set up a utility that is designed for udp testing, such as echo server. This is normally built into an inetd or xinetd server
If you want to intercept incoming udp packets you will need to use bind() select()/poll()/epoll() and recvfrom()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.