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
Marc Kleine-Budde 2023-07-06 11:25:23 +02:00 committed by Oliver Hartkopp
parent ba5d7de30d
commit 87def9b1fa
1 changed files with 5 additions and 6 deletions

View File

@ -249,9 +249,10 @@ int main(int argc, char **argv)
.sa_handler = sig_handler,
};
struct ifreq ifr;
struct sockaddr_can addr;
struct sockaddr_can addr = {
.can_family = AF_CAN,
};
char *interface = "can0";
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW;
int extended = 0;
int receive = 0;
int opt;
@ -336,16 +337,14 @@ int main(int argc, char **argv)
frame.can_id = filter->can_id;
filter->can_mask |= CAN_EFF_FLAG;
printf("interface = %s, family = %d, type = %d, proto = %d\n",
interface, family, type, proto);
printf("interface = %s\n", interface);
s = socket(family, type, proto);
s = socket(AF_CAN, SOCK_RAW, CAN_RAW);
if (s < 0) {
perror("socket()");
exit(EXIT_FAILURE);
}
addr.can_family = family;
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFINDEX, &ifr)) {
perror("ioctl()");