version 1.1.2.5, 2009/12/28 14:22:25
|
version 1.2, 2011/06/08 12:45:41
|
Line 1
|
Line 1
|
|
/************************************************************************* |
|
* (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com> |
|
* by Michael Pounov <misho@aitbg.com> |
|
* |
|
* $Author$ |
|
* $Id$ |
|
* |
|
*************************************************************************/ |
#include "global.h" |
#include "global.h" |
#include "get1steth.h" |
#include "get1steth.h" |
|
|
Line 17 static void Usage()
|
Line 25 static void Usage()
|
"\n", compiled, compiledby, compilehost); |
"\n", compiled, compiledby, compilehost); |
} |
} |
|
|
|
#ifdef HAVE_KLDNEXT |
static int kldLoad() |
static int kldLoad() |
{ |
{ |
struct module_stat mstat; |
struct module_stat mstat; |
Line 43 static int kldLoad()
|
Line 52 static int kldLoad()
|
|
|
return 1; |
return 1; |
} |
} |
|
#endif |
|
|
// ------------------------------- |
// ------------------------------- |
|
|
Line 55 int main(int argc, char **argv)
|
Line 65 int main(int argc, char **argv)
|
struct ifreq ifr; |
struct ifreq ifr; |
struct vlanreq vlr; |
struct vlanreq vlr; |
struct ifaliasreq ifra; |
struct ifaliasreq ifra; |
|
struct ifmediareq ifmr; |
int s; |
int s; |
|
|
while ((ch = getopt(argc, argv, "hvg")) != -1) |
while ((ch = getopt(argc, argv, "hvg")) != -1) |
Line 73 int main(int argc, char **argv)
|
Line 84 int main(int argc, char **argv)
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
openlog("get1steth", LOG_CONS | LOG_PERROR, LOG_CONSOLE | LOG_USER); | openlog("get1steth", LOG_CONS | LOG_PERROR, LOG_USER); |
|
|
if (argc) { |
if (argc) { |
strlcpy(szIface, *argv, MAX_STR); |
strlcpy(szIface, *argv, MAX_STR); |
VERB(1) syslog(LOG_NOTICE, "Info:: Get CUSTOM first interface %s\n", szIface); |
VERB(1) syslog(LOG_NOTICE, "Info:: Get CUSTOM first interface %s\n", szIface); |
} else { |
} 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); |
getifaddrs(&ifa); |
for (ifp = ifa; ifp; ifp = ifp->ifa_next) { |
for (ifp = ifa; ifp; ifp = ifp->ifa_next) { |
if (PF_LINK == ifp->ifa_addr->sa_family && |
if (PF_LINK == ifp->ifa_addr->sa_family && |
IFT_ETHER == ((struct sockaddr_dl*) ifp->ifa_addr)->sdl_type) { |
IFT_ETHER == ((struct sockaddr_dl*) ifp->ifa_addr)->sdl_type) { |
strlcpy(szIface, ifp->ifa_name, MAX_STR); | memset(&ifmr, 0, sizeof ifmr); |
sdl = (struct sockaddr_dl*) ifp->ifa_addr; | strlcpy(ifmr.ifm_name, ifp->ifa_name, IFNAMSIZ); |
VERB(2) syslog(LOG_NOTICE, "Info:: Get first interface=%s MAC=%s\n", szIface, | if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) { |
ether_ntoa((struct ether_addr*) LLADDR(sdl))); | syslog(LOG_ERR, "Error:: media interface=%s ioctl(SIOCGIFMEDIA) #%d - %s\n", |
break; | ifmr.ifm_name, errno, strerror(errno)); |
| close(s); |
| closelog(); |
| return 1; |
| } |
| |
| if (IFM_ETHER == IFM_TYPE(ifmr.ifm_current)) { |
| strlcpy(szIface, ifp->ifa_name, MAX_STR); |
| sdl = (struct sockaddr_dl*) ifp->ifa_addr; |
| VERB(2) syslog(LOG_NOTICE, "Info:: Get first interface=%s MAC=%s\n", szIface, |
| ether_ntoa((struct ether_addr*) LLADDR(sdl))); |
| break; |
| } |
} |
} |
} |
} |
freeifaddrs(ifa); |
freeifaddrs(ifa); |
|
|
|
close(s); |
} |
} |
|
if (!*szIface) { |
|
syslog(LOG_NOTICE, "Info:: Ethernet interface not found!!!\n"); |
|
|
|
closelog(); |
|
return 1; |
|
} |
|
|
if (GetOnly) { |
if (GetOnly) { |
printf("%s\n", szIface); |
printf("%s\n", szIface); |
|
|
Line 99 int main(int argc, char **argv)
|
Line 138 int main(int argc, char **argv)
|
return 0; |
return 0; |
} |
} |
|
|
|
#ifdef HAVE_KLDNEXT |
s = kldLoad(); |
s = kldLoad(); |
if (s == -1) { |
if (s == -1) { |
printf("Error:: kldload(if_vlan) Can`t operate with vlans ...\n"); | syslog(LOG_ERR, "Error:: kldload(if_vlan) Can`t operate with vlans ...\n"); |
return 1; |
return 1; |
} else |
} else |
VERB(1) printf("VLAN module ... %s\n", s ? "Loaded" : "Already loaded"); | VERB(3) syslog(LOG_NOTICE, "VLAN module ... %s\n", s ? "Loaded" : "Already loaded"); |
| #endif |
|
|
// create vlan |
// create vlan |
memset(&ifr, 0, sizeof ifr); |
memset(&ifr, 0, sizeof ifr); |
Line 114 int main(int argc, char **argv)
|
Line 155 int main(int argc, char **argv)
|
strlcpy(ifr.ifr_name, MGMT_IFACE, IFNAMSIZ); |
strlcpy(ifr.ifr_name, MGMT_IFACE, IFNAMSIZ); |
ifr.ifr_data = (void *) &vlr; |
ifr.ifr_data = (void *) &vlr; |
|
|
s = socket(PF_INET, SOCK_STREAM, 0); | s = socket(PF_INET, SOCK_DGRAM, 0); |
if (-1 == s) { |
if (-1 == s) { |
syslog(LOG_ERR, "Error:: socket(LOCAL) #%d - %s\n", errno, strerror(errno)); | syslog(LOG_ERR, "Error:: socket(INET) #%d - %s\n", errno, strerror(errno)); |
| closelog(); |
return 2; |
return 2; |
} |
} |
|
#ifdef SIOCIFCREATE2 |
if (ioctl(s, SIOCIFCREATE2, &ifr) == -1 && errno != EEXIST) { |
if (ioctl(s, SIOCIFCREATE2, &ifr) == -1 && errno != EEXIST) { |
|
#else |
|
if (ioctl(s, SIOCIFCREATE, &ifr) == -1 && errno != EEXIST) { |
|
#endif |
syslog(LOG_ERR, "Error:: Create interface=%s ioctl(SIOCIFCREATE2) #%d - %s\n", |
syslog(LOG_ERR, "Error:: Create interface=%s ioctl(SIOCIFCREATE2) #%d - %s\n", |
MGMT_IFACE, errno, strerror(errno)); |
MGMT_IFACE, errno, strerror(errno)); |
close(s); |
close(s); |
Line 128 int main(int argc, char **argv)
|
Line 174 int main(int argc, char **argv)
|
VERB(2) syslog(LOG_NOTICE, "Info:: Created interface=%s\n", MGMT_IFACE); |
VERB(2) syslog(LOG_NOTICE, "Info:: Created interface=%s\n", MGMT_IFACE); |
// rename iface |
// rename iface |
ifr.ifr_data = MGMT_NAME; |
ifr.ifr_data = MGMT_NAME; |
|
#ifdef SIOCSIFNAME |
if (errno != EEXIST && ioctl(s, SIOCSIFNAME, &ifr) == -1) { |
if (errno != EEXIST && ioctl(s, SIOCSIFNAME, &ifr) == -1) { |
|
#else |
|
if (errno != EEXIST && ioctl(s, SIOCGIFDESCR, &ifr) == -1) { |
|
#endif |
syslog(LOG_ERR, "Error:: Managment interface=%s ioctl(SIOCSIFNAME) #%d - %s\n", |
syslog(LOG_ERR, "Error:: Managment interface=%s ioctl(SIOCSIFNAME) #%d - %s\n", |
MGMT_NAME, errno, strerror(errno)); |
MGMT_NAME, errno, strerror(errno)); |
close(s); |
close(s); |