From 4b5ad8fb983c1e6a1da86e58746eb22080233f85 Mon Sep 17 00:00:00 2001 From: Russell Bryant <russell@russellbryant.com> Date: Sat, 4 Nov 2006 21:44:48 +0000 Subject: [PATCH] Do some minor cleanup to the section of code that sets the EID by getting the mac address for an ethernet interface git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47204 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- pbx/pbx_dundi.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index e947e56f60..798beca16d 100644 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -392,26 +392,26 @@ static void dundi_reject(struct dundi_hdr *h, struct sockaddr_in *sin) static void reset_global_eid(void) { #if defined(SIOCGIFHWADDR) - int x,s; + int s, x = 0; char eid_str[20]; struct ifreq ifr; s = socket(AF_INET, SOCK_STREAM, 0); - if (s > 0) { - x = 0; - for(x=0;x<10;x++) { - memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x); - if (!ioctl(s, SIOCGIFHWADDR, &ifr)) { - memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(global_eid)); - if (option_debug) - ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifr.ifr_name); - close(s); - return; - } - } - close(s); + if (s < 0) + return; + for (x = 0; x < 10; x++) { + memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x); + if (ioctl(s, SIOCGIFHWADDR, &ifr)) + continue; + memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(global_eid)); + if (option_debug) { + ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", + dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifr.ifr_name); + } + break; } + close(s); #else #if defined(ifa_broadaddr) && !defined(SOLARIS) char eid_str[20]; -- GitLab