CrossCore XA
Revision: 1.0
Programmers Guide
Date: Jul 1, 10
if
((sl = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror(
"inetsocket"
);
exit(1);
}
/* open “regular” network socket */
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = htons(PORT);
while
(bind(sl,(
struct
sockaddr*)&saddr,
sizeof
(saddr)) < 0) {
printf(".");fflush(NULL);
usleep(100000);
}
/* Listen socket for a connection */
if
(listen(sl,3) != 0) {
perror(
"listen"
);
exit(1);
}
while
(1) {
sa = accept(sl,(
struct
sockaddr *)&clientaddr, &sin_size);
if (sa > 0 ){
if (fork())
close(sa);
else
break
;
}
}
/* open BCM socket */
if
((sc = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
perror(
"bcmsocket"
);
return
1;
}
/* Connect socket */
if
(connect(sc, (
struct
sockaddr *)&caddr,
sizeof
(caddr)) < 0) {
perror(
"connect"
);
return
1;
}
caddr.can_family = PF_CAN;
caddr.can_ifindex = ifr.ifr_ifindex;
while(1){
FD_ZERO(&readfds);
FD_SET(sc, &readfds);
FD_SET(sa, &readfds);
www.crosscontrol.com
20