CrossCore XA
Revision: 1.0
Programmers Guide
Date: Jul 1, 10
/* Select that CAN interface, and bind the socket to it. */
struct sockaddr_can addr;
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
bind( skt, (struct sockaddr*)&addr, sizeof(addr) );
/* Send a message to the CAN bus */
struct can_frame frame;
frame.can_id = 0x123;
strcpy( &frame.data,
"foo"
);
frame.can_dlc = strlen( &frame.data );
int
bytes_sent = write( skt, &frame,
sizeof
(frame) );
/* Read a message back from the CAN bus */
int
bytes_read = read( skt, &frame,
sizeof
(frame) );
3.3.2.
bind
Description
Bind a name to a socket.
Include files
#include <sys/socket.h>
Syntax
int bind(
int socket,
const struct sockaddr *address,
socklen_t address_len
)
Parameters
fd Socket
descriptor
address
Pointer to sockaddr structure containing address to be bound
address_len
Specifies the length of sockaddr structure
Return value
Returns zero on success. In case of errors, -1 is returned and errno is set appropriately.
Example
See example of socket.
3.3.3.
setsockopt
Description
Set socket options
Include files
#include <sys/socket.h>
www.crosscontrol.com
14