简体   繁体   中英

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.

  1. How to assign a UDP port on my client to receive data on a particular port?
  2. How to assign two different ports - 1024 and 1025 to receive data?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM