|
|
@@ -902,6 +902,96 @@ int sys_get_net(NetworkInfo_t *para, int ipVersion)
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
+const char *sys_get_ifname(int nic)
|
|
|
+{
|
|
|
+ const char *ifname[NIC_MAX]={"eth0","eth1","usb0","wlan0"};
|
|
|
+ return ifname[nic];
|
|
|
+}
|
|
|
+int sys_nic_connected(int nic, int timeout)
|
|
|
+{
|
|
|
+ int fd,r=-1,ret;
|
|
|
+ char ipaddr[64];
|
|
|
+ sa_family_t family;
|
|
|
+ struct ifaddrs *ifap, *ifa;
|
|
|
+ const char *dstIP4="8.8.8.8";
|
|
|
+ const char *dstIP6="2001:4860:4860::8888";
|
|
|
+ const char *ifname=sys_get_ifname(nic);
|
|
|
+
|
|
|
+ if (getifaddrs(&ifap) == -1) {
|
|
|
+ LOGE("___getifaddrs error\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
+ if (fd<0) {
|
|
|
+ freeifaddrs(ifap);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
|
|
+ if (ifa->ifa_addr != NULL && strcmp(ifa->ifa_name, ifname)==0) {
|
|
|
+
|
|
|
+ family = ifa->ifa_addr->sa_family;
|
|
|
+ if(family==AF_INET) {
|
|
|
+ struct sockaddr_in *sin=(struct sockaddr_in *)ifa->ifa_addr;
|
|
|
+
|
|
|
+ inet_ntop(family, ifa->ifa_addr, ipaddr, INET6_ADDRSTRLEN);
|
|
|
+ if(bind(fd, (struct sockaddr *)sin, sizeof(*sin))==0) {
|
|
|
+ struct timeval tv={timeout/1000,(timeout%1000)*1000};
|
|
|
+ struct sockaddr_in remote={0};
|
|
|
+
|
|
|
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
|
|
+
|
|
|
+ remote.sin_family = AF_INET;
|
|
|
+ remote.sin_port = htons(53);
|
|
|
+ inet_pton(AF_INET, dstIP4, &remote.sin_addr);
|
|
|
+ ret = connect(fd, (struct sockaddr *)&remote, sizeof(remote));
|
|
|
+ close(fd);
|
|
|
+ if(ret==0) {
|
|
|
+ r = 0; break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ struct sockaddr_in6 *sin=(struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
+ inet_ntop(family, ifa->ifa_addr, ipaddr, INET6_ADDRSTRLEN);
|
|
|
+ if(bind(fd, (struct sockaddr *)sin, sizeof(*sin))==0) {
|
|
|
+ struct timeval tv={timeout/1000,(timeout%1000)*1000};
|
|
|
+ struct sockaddr_in6 remote={0};
|
|
|
+
|
|
|
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
|
|
+
|
|
|
+ remote.sin6_family = AF_INET6;
|
|
|
+ remote.sin6_port = htons(53);
|
|
|
+ inet_pton(AF_INET6, dstIP6, &remote.sin6_addr);
|
|
|
+ ret = connect(fd, (struct sockaddr *)&remote, sizeof(remote));
|
|
|
+ close(fd);
|
|
|
+ if(ret==0) {
|
|
|
+ r = 0; break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ freeifaddrs(ifap);
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+int sys_bind_nic(int nic, int fd)
|
|
|
+{
|
|
|
+ struct ifreq ifr;
|
|
|
+ const char *ifname=sys_get_ifname(nic);
|
|
|
+
|
|
|
+ memset(&ifr, 0, sizeof(ifr));
|
|
|
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
|
+
|
|
|
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,(void *)&ifr, sizeof(ifr)) < 0) {
|
|
|
+ LOGE("___setsockopt(SO_BINDTODEVICE) failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
int sys_is_running(char *prog)
|
|
|
{
|
|
|
@@ -926,6 +1016,7 @@ int sys_is_running(char *prog)
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
int sys_get_disk_ava_MB(char *path)
|
|
|
{
|
|
|
int r;
|