Thread (55 messages) 55 messages, 2 authors, 2012-01-09

recv list

From: Wolfgang <hidden>
Date: 2012-01-04 16:29:03

Hi,

OK, I create 1 socket for one source address (what is the maximum of pgns per 
socket?). 
So if I use recvfrom for one specific pgn - while waiting for that specific pgn
the other pgns from that src address are stored in the buffer of the socket and
will be later "recvfrom"? So no can frame will be lost?

Am I right, with this, only the j1939 frame with id<0x19233000> should be
received, but nothing is done, (just waiting for anything), what have I done 
wrong?

#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>



int main (void)
{
	int s;
	s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
	    
	struct sockaddr_can addr;

    memset(&addr, 0, sizeof(addr));
    addr.can_ifindex = if_nametoindex("can0");
    addr.can_addr.j1939.name = J1939_NO_NAME;    
    addr.can_addr.j1939.addr = 0x00;
    addr.can_addr.j1939.pgn = J1939_NO_PGN;
    addr.can_family = AF_CAN;  
   
   
    if (bind(s, (void *)&addr, sizeof(addr))<0)
    	{
    		perror ("bind failed");
        	}
   
   
	struct can_frame frame      	
   
   struct sockaddr_can dest_addr;
   
   memset(&dest_addr, 0, sizeof(dest_addr));
   dest_addr.can_family = AF_CAN;
   dest_addr.can_addr.j1939.name = J1939_NO_NAME;
   dest_addr.can_addr.j1939.addr = 0x30;
   dest_addr.can_addr.j1939.pgn = 0x12300;
   
    	if (recvfrom(s, frame.data, sizeof(frame.data), 0, (void *)&dest_addr,\
 sizeof(dest_addr))<0)
		{
  	 	perror ("recvfrom failed");
  	 	}
   		 
  return 0;
}


Wolfgang


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help