cansequence: main(): use C99 initializers for struct sockaddr_can addr
By using C99 initializers for struct sockaddr_can addr the not assigned members are automatically set to 0x0, resulting in not passing uninitialized memory to the bind() syscall. Also remove the printing of the socket family, type and proto, this was interesting back in the days, when the numbers were not fixed, yet.pull/444/head
parent
ba5d7de30d
commit
87def9b1fa
|
|
@ -249,9 +249,10 @@ int main(int argc, char **argv)
|
||||||
.sa_handler = sig_handler,
|
.sa_handler = sig_handler,
|
||||||
};
|
};
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr = {
|
||||||
|
.can_family = AF_CAN,
|
||||||
|
};
|
||||||
char *interface = "can0";
|
char *interface = "can0";
|
||||||
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW;
|
|
||||||
int extended = 0;
|
int extended = 0;
|
||||||
int receive = 0;
|
int receive = 0;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
@ -336,16 +337,14 @@ int main(int argc, char **argv)
|
||||||
frame.can_id = filter->can_id;
|
frame.can_id = filter->can_id;
|
||||||
filter->can_mask |= CAN_EFF_FLAG;
|
filter->can_mask |= CAN_EFF_FLAG;
|
||||||
|
|
||||||
printf("interface = %s, family = %d, type = %d, proto = %d\n",
|
printf("interface = %s\n", interface);
|
||||||
interface, family, type, proto);
|
|
||||||
|
|
||||||
s = socket(family, type, proto);
|
s = socket(AF_CAN, SOCK_RAW, CAN_RAW);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
perror("socket()");
|
perror("socket()");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = family;
|
|
||||||
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
|
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(s, SIOCGIFINDEX, &ifr)) {
|
if (ioctl(s, SIOCGIFINDEX, &ifr)) {
|
||||||
perror("ioctl()");
|
perror("ioctl()");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue