Relative Content

Tag Archive for clinuxsendtosocketcanj1939

Receiving and Sending J1939 CAN message on Linux in C

I am trying to open a SocketCAN J1939 and receive and send J1939 messages. I am very confused with type “sockaddr_can”. This structure has j1939.addr, j1939.pgn, j1939.name etc. When I receive a message with
recvfrom(s, &lCANFrame.data, sizeof(lCANFrame.data), 0x0, (struct sockaddr*)&j1939_addr, &recv_data_len)
where sockaddr_can j1939_addr;, the address of the sender is in j1939_addr.can_addr.j1939.addr and PGN of received message is in j1939_addr.can_addr.j1939.pgn. However, I assigned the these values to be my SRC address and NAME as seen below when I am initializing the socket.