I am trying to send a UDP-datagram to an IP camera from a computer running on Linux in order to discover it. All devices are connected via a switch.
There is a windows app that is compatible with this camera, that sends out a UDP datagram to a multicast group and gets an answer from the camera via the same group. I found out this via Wireshark and decided to try and send the same datagram from a C program on my Linux machine. I am able to get the correct response if my C program sends it directly to the camera's IP-address, but not if I send it to the multicast group.
I therefor made a listener program on my Linux computer and tried to send it to the multicast address. This succeeded, but I did not catch anything in Wireshark.
So it seems that my C-program is able to send the datagram correctly, just not out on to the network. Can this be some kind of Linux configuration?
EDIT: As requested, here is the code. FYI: As of now, I am only trying to send data to the camera and examine the response in Wireshark.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include "udp_socket.h"
int main( void )
{
//int s = udp_socket(50000);
int s = socket(AF_INET,SOCK_DGRAM,0);
printf("Socket: %d\r\n", s);
char buffer[48] = {0x67,0x45,0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x67,0x45,0x00,0x00,0x14,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0xea,0xc8,0xc8,0xc8,0xf4,0xe6,0x00,0x00};
struct sockaddr_in serveraddr;
memset( &serveraddr, 0, sizeof(serveraddr) );
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons( 59125 );
serveraddr.sin_addr.s_addr = inet_addr("234.200.200.200");
udp_socket_tx(s, buffer, sizeof(buffer), &serveraddr );
close(s);
}
udp_socket_tx() from udp_socket.h:
int udp_socket_tx(int socket_fd, char * tx_buffer, int tx_buffer_len, const struct sockaddr_in * to_addr) {
return sendto(
socket_fd,
tx_buffer,
tx_buffer_len,
0,
(const struct sockaddr *)to_addr,
sizeof(struct sockaddr_in)
);
}
ifconfig eth0 multicast
(replace eth0 with your adapter id). – Marian