We have a requirement for UDP multicasting in our project using Linux 4.1 kernel with static ip address.
Basic UDP multicasting by the use of the sendto function to send data works fine with device static ip 10.13.204.100; the issue comes when I change the ip address of the device to 10.13.204.101 or to any other ip in the same series, the udp multicasting starts showing the error:
sendto: network unreachable The UDP has been initialized by the following function:
int udp_init() { char multicastTTL = 10; // Create UDP socket: memset(&socket_desc, 0, sizeof(socket_desc)); socket_desc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (socket_desc < 0) { perror("socket"); return 1; } udp_socket_fd = socket_desc; printf("udp_socket_fd=>%d\nsocket_desc==>%d\n", udp_socket_fd, socket_desc); /* Set the TTL (time to live/hop count) for the send */ // if (setsockopt(socket_desc, IPPROTO_IP, IP_MULTICAST_TTL, &multicastTTL, sizeof(multicastTTL)) < 0) if (setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, &multicastTTL, sizeof(multicastTTL)) < 0) { perror("setsockopt"); exit(1); } memset(&server_addr, 0, sizeof(server_addr)); /* Zero out structure */ server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr(EXAMPLE_GROUP); // INADDR_ANY; server_addr.sin_port = htons(EXAMPLE_PORT); // htons(udp_port); // bind to receive address // if (bind(socket_desc, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("bind"); printf("line %s-->%s:%d\n", __FILE__, __FUNCTION__, __LINE__); return 1; } } Once the ip has been changed, the UDP socket is closed by the instruction:
close(socket_desc) Once again the udp_init function (showed above) is used to initialize the UDP socket and then it is used the sendto function to transmit the data but this causes the error:
sendto:network unreachable thanks in advance
ip addressandip routecommands please ? Are both devices on the same LAN or is there some routing achieved between ?