Hello
I have the next net.
I execute the tcpdump -X -i br0, with th next result.
but, When I execute my program to receive the mesage, I don't receive any messsage. My program is the next.
int main(int argc, char *argv[]) {
struct sockaddr_in server;
uint16_t *buf2=malloc(1 * sizeof(uint16_t));
/* Create socket for sending/receiving datagrams */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
perror("socket() failed");
/* allow broadcast messages for the socket */
int true = 1;
rc=setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &true, sizeof(true));
/* Construct local address structure */
memset(&broadcastAddr, 0, sizeof(broadcastAddr)); /* Zero out structure */
broadcastAddr.sin_family = AF_INET; /* Internet address family */
broadcastAddr.sin_addr.s_addr = htonl(INADDR_ANY);
broadcastAddr.sin_port = htons(1000); /* Broadcast port */
localIPLen = sizeof(uint16_t); /* Find length of localIP */
mess=recvfrom(sock, buf2, localIPLen , 0, (struct sockaddr *) &broadcastAddr, sizeof(broadcastAddr));
}
I can't find the error. Can anyone help me.
Thanks.
Hi,
it seems to be ok, but after comparing the code agains other examples the only difference I could find was the binding of the socket to a port.
Have you tried that?
Alejandro
Hello
I did it, this is not my problem.
Now it works fine I resolved my problem, with the next code.
int main(){
int saddr_size , data_size,i;
struct sockaddr saddr;
uint16_t *buffer = (uint16_t *) malloc(65536);
printf("Starting...\n");
int sock_raw = socket( AF_PACKET , SOCK_RAW , htons(ETH_P_ALL)) ;
saddr_size = sizeof saddr;
data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &saddr , (socklen_t*)&saddr_size);
for (i=0;i<=data_size;){
printf("Data %02x\t%02x\t%02x\t%02x\t\t %c%c%c%c\n",buffer[i], buffer[i+1], buffer[i+2], buffer[i+3],buffer[i], buffer[i+1], buffer[i+2], buffer[i+3]);
i=i+4;
}
close(sock_raw);
return 0;
}
Thanks.