--- embedtools/src/get1steth.c 2010/01/01 17:24:04 1.1.2.6 +++ embedtools/src/get1steth.c 2010/01/01 17:58:16 1.1.2.7 @@ -76,9 +76,9 @@ int main(int argc, char **argv) openlog("get1steth", LOG_CONS | LOG_PERROR, LOG_CONSOLE | LOG_USER); - s = socket(PF_INET, SOCK_STREAM, 0); + s = socket(AF_LOCAL, SOCK_DGRAM, 0); if (-1 == s) { - syslog(LOG_ERR, "Error:: socket(INET) #%d - %s\n", errno, strerror(errno)); + syslog(LOG_ERR, "Error:: socket(LOCAL) #%d - %s\n", errno, strerror(errno)); closelog(); return 1; } @@ -86,6 +86,13 @@ int main(int argc, char **argv) strlcpy(szIface, *argv, MAX_STR); VERB(1) syslog(LOG_NOTICE, "Info:: Get CUSTOM first interface %s\n", szIface); } else { + s = socket(PF_INET, SOCK_DGRAM, 0); + if (-1 == s) { + syslog(LOG_ERR, "Error:: socket(INET) #%d - %s\n", errno, strerror(errno)); + closelog(); + return 1; + } + getifaddrs(&ifa); for (ifp = ifa; ifp; ifp = ifp->ifa_next) { if (PF_LINK == ifp->ifa_addr->sa_family && @@ -110,11 +117,12 @@ int main(int argc, char **argv) } } freeifaddrs(ifa); + + close(s); } if (!*szIface) { syslog(LOG_NOTICE, "Info:: Ethernet interface not found!!!\n"); - close(s); closelog(); return 1; } @@ -122,7 +130,6 @@ int main(int argc, char **argv) if (GetOnly) { printf("%s\n", szIface); - close(s); closelog(); return 0; } @@ -130,7 +137,6 @@ int main(int argc, char **argv) s = kldLoad(); if (s == -1) { syslog(LOG_ERR, "Error:: kldload(if_vlan) Can`t operate with vlans ...\n"); - close(s); return 1; } else VERB(1) syslog(LOG_NOTICE, "VLAN module ... %s\n", s ? "Loaded" : "Already loaded"); @@ -143,6 +149,12 @@ int main(int argc, char **argv) strlcpy(ifr.ifr_name, MGMT_IFACE, IFNAMSIZ); ifr.ifr_data = (void *) &vlr; + s = socket(PF_INET, SOCK_DGRAM, 0); + if (-1 == s) { + syslog(LOG_ERR, "Error:: socket(INET) #%d - %s\n", errno, strerror(errno)); + closelog(); + return 2; + } if (ioctl(s, SIOCIFCREATE2, &ifr) == -1 && errno != EEXIST) { syslog(LOG_ERR, "Error:: Create interface=%s ioctl(SIOCIFCREATE2) #%d - %s\n", MGMT_IFACE, errno, strerror(errno));