From 87def9b1fadb212310cb93402b16d1a5630bf6f5 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Thu, 6 Jul 2023 11:25:23 +0200 Subject: [PATCH] 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. --- cansequence.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cansequence.c b/cansequence.c index e9861eb..06da7a6 100644 --- a/cansequence.c +++ b/cansequence.c @@ -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()");