From 113d9761f7c7162227e6f14d91037680a682b6a7 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 25 Jan 2014 17:16:01 +0000 Subject: [PATCH] Better failure handling in linuxradiodrv --- cpu/native/net/linuxradio-drv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 9718b4d42..9275c1379 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -67,6 +67,9 @@ static int init(void) { sockbuf = malloc(MAX_PACKET_SIZE); + if (sockbuf == 0) { + return 1; + } return 0; } @@ -163,8 +166,13 @@ on(void) return 0; } else { struct ifreq ifr; - strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); // TODO: make interface configurable - ioctl(sockfd, SIOCGIFINDEX, &ifr); + // TODO: interface should not be hard-coded + strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); + int err = ioctl(sockfd, SIOCGIFINDEX, &ifr); + if (err == -1) { + perror ("linuxradio ioctl()"); + return 0; + } struct sockaddr_ll sll; sll.sll_family = AF_PACKET;