|
|
@@ -8,6 +8,7 @@
|
|
|
#include "thread.h"
|
|
|
#include "cfg.h"
|
|
|
#include "lock.h"
|
|
|
+#include "sys.h"
|
|
|
#include "sqlite_handle.h"
|
|
|
#include "smtp.h"
|
|
|
|
|
|
@@ -35,6 +36,8 @@ typedef struct {
|
|
|
|
|
|
int ipflag;
|
|
|
char host_ip[64];
|
|
|
+ char local_ip[64];
|
|
|
+
|
|
|
int port_start;
|
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
@@ -267,9 +270,10 @@ static char *get_string(netsnmp_variable_list *var)
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
-static int get_ipaddr(int family, char *iface, char *addr)
|
|
|
+static int get_ipaddr(int family, char *iface, char *host, char *local)
|
|
|
{
|
|
|
int r=-1;
|
|
|
+ char temp[100];
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
|
|
if (getifaddrs(&ifap) == -1) {
|
|
|
@@ -283,14 +287,15 @@ static int get_ipaddr(int family, char *iface, char *addr)
|
|
|
sa = (struct sockaddr_in *) ifa->ifa_addr;
|
|
|
msk = (struct sockaddr_in *) ifa->ifa_netmask;
|
|
|
|
|
|
- if(addr) {
|
|
|
- char *p = (char*)inet_ntop(family, &sa->sin_addr, addr, INET6_ADDRSTRLEN);
|
|
|
- if(p) {
|
|
|
- //printf("___ipv4: %s\n", p);
|
|
|
- if(strcmp(addr, "127.0.0.1") && strcmp(addr, "172.17.0.1")) {
|
|
|
- p = strrchr(p, '.'); p[1] = '1'; p[2] = 0;
|
|
|
- r = 0; break;
|
|
|
- }
|
|
|
+ char *p = (char*)inet_ntop(family, &sa->sin_addr, temp, INET6_ADDRSTRLEN);
|
|
|
+ if(p) {
|
|
|
+ //printf("___ipv4: %s\n", p);
|
|
|
+
|
|
|
+ if(strcmp(p, "127.0.0.1") && strcmp(p, "172.17.0.1")) {
|
|
|
+ strcpy(host, p); strcpy(local, p);
|
|
|
+
|
|
|
+ p = strrchr(host, '.'); p[1] = '1'; p[2] = 0;
|
|
|
+ r = 0; break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -299,14 +304,15 @@ static int get_ipaddr(int family, char *iface, char *addr)
|
|
|
sa = (struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
msk = (struct sockaddr_in6 *)ifa->ifa_netmask;
|
|
|
|
|
|
- if(addr) {
|
|
|
- char *p = (char*)inet_ntop(family, &sa->sin6_addr, addr, INET6_ADDRSTRLEN);
|
|
|
- if(p) {
|
|
|
- //printf("___ipv6: %s\n", p);
|
|
|
- if(strcmp(addr, "::1")) {
|
|
|
- p = strrchr(p, ':'); p[1] = '1'; p[2] = 0;
|
|
|
- r = 0; break;
|
|
|
- }
|
|
|
+ char *p = (char*)inet_ntop(family, &sa->sin6_addr, temp, INET6_ADDRSTRLEN);
|
|
|
+ if(p) {
|
|
|
+ //printf("___ipv6: %s\n", p);
|
|
|
+
|
|
|
+ if(strcmp(p, "::1")) {
|
|
|
+ strcpy(host, p); strcpy(local, p);
|
|
|
+
|
|
|
+ p = strrchr(host, ':'); p[1] = '1'; p[2] = 0;
|
|
|
+ r = 0; break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -515,23 +521,30 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
strcpy(h->host_ip, SW_HOST_IP);
|
|
|
//get_hostnet(hnet, h->host_ip);
|
|
|
//sprintf(temp, "ip addr add dev eth0 %s/24; ip route add %s/24 via %s", SW_PDU_IP, hnet, h->host_ip);
|
|
|
- set_ip(SW_PDU_IP); set_gw(h->host_ip);
|
|
|
+ //set_ip(SW_PDU_IP); set_gw(h->host_ip);
|
|
|
h->ipflag = 1;
|
|
|
#else
|
|
|
- r = get_ipaddr(AF_INET, "eth0", h->host_ip);
|
|
|
+ r = get_ipaddr(AF_INET, "eth0", h->host_ip, h->local_ip);
|
|
|
if(r) {
|
|
|
LOGE("____get ip4 failed\n");
|
|
|
|
|
|
- r = get_ipaddr(AF_INET6, "eth0", h->host_ip);
|
|
|
+ r = get_ipaddr(AF_INET6, "eth0", h->host_ip, h->local_ip);
|
|
|
if(r) {
|
|
|
LOGE("____get ip6 failed\n");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if((p=strrchr(h->local_ip, '.')) || (p=strrchr(h->local_ip, ':'))) {
|
|
|
+ if(strstr(p, "132")==0) {
|
|
|
+ p[1] = 0; strcat(p, "132");
|
|
|
+ set_ip(h->local_ip); set_gw(h->host_ip);
|
|
|
+ }
|
|
|
+ }
|
|
|
h->ipflag = 1;
|
|
|
#endif
|
|
|
}
|
|
|
- //LOGD("___local ip: %s\n", h->host_ip);
|
|
|
+ LOGD("___netswitch ip: %s\n", h->host_ip);
|
|
|
|
|
|
if(h->port_start==-1) {
|
|
|
h->port_start = get_port_start(h->host_ip);
|
|
|
@@ -540,8 +553,6 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //system("/root/run/app/snmp/bin/snmpbulkget -v 2c -c public 192.168.234.1 1.3.6.1.2.1.17.4.3.1");
|
|
|
-
|
|
|
#if 1
|
|
|
char *dot1dTpFdbEntryOid="1.3.6.1.2.1.17.4.3.1";
|
|
|
var = snmp_getbulk(SNMP_VERSION_2c, "public", h->host_ip, dot1dTpFdbEntryOid);
|