From 4d4b879c00430d7c4fc0ef7b9e3eb6186053d921 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Mon, 22 Oct 2012 12:19:25 +0200 Subject: [PATCH] pud: fix socket error Coverity: CID 739662 (#2 of 2): Argument cannot be negative (NEGATIVE_RETURNS) At (9): "fd" is passed to a parameter that cannot be negative. Signed-off-by: Ferry Huberts --- lib/pud/src/netTools.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/pud/src/netTools.c b/lib/pud/src/netTools.c index 686f1166..def580e1 100644 --- a/lib/pud/src/netTools.c +++ b/lib/pud/src/netTools.c @@ -7,6 +7,8 @@ /* System includes */ #include +#include +#include /** Get the hardware address (MAC) of an interface @@ -33,6 +35,10 @@ unsigned char * getHardwareAddress(const char * ifName, int family, assert(ifr != NULL); fd = socket(family, SOCK_DGRAM, 0); + if (fd < 0) { + pudError(true, "%s@%u: socket error: %s", __FILE__, __LINE__, strerror(errno)); + return NULL; + } ifr->ifr_addr.sa_family = family; memset(ifr->ifr_name, 0, sizeof(ifr->ifr_name));