"Fossies" - the Fresh Open Source Software Archive

Member "monit-5.28.0/src/net/os/dragonfly/Link.inc" (28 Mar 2021, 3616 Bytes) of package /linux/privat/monit-5.28.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "Link.inc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.27.2_vs_5.28.0.

    1 /*
    2  * Copyright (C) Tildeslash Ltd. All rights reserved.
    3  *
    4  * This program is free software: you can redistribute it and/or modify
    5  * it under the terms of the GNU Affero General Public License version 3.
    6  *
    7  * This program is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  * GNU Affero General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Affero General Public License
   13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   14  *
   15  * In addition, as a special exception, the copyright holders give
   16  * permission to link the code of portions of this program with the
   17  * OpenSSL library under certain conditions as described in each
   18  * individual source file, and distribute linked combinations
   19  * including the two.
   20  *
   21  * You must obey the GNU Affero General Public License in all respects
   22  * for all of the code used other than OpenSSL.  
   23  */
   24 
   25 
   26 /**
   27  * Implementation of the Network Statistics for DragonFly.
   28  *
   29  * @author http://www.tildeslash.com/
   30  * @see http://www.mmonit.com/
   31  * @file
   32  */
   33 
   34 
   35 static boolean_t _update(T L, const char *interface) {
   36         for (struct ifaddrs *a = _stats.addrs; a != NULL; a = a->ifa_next) {
   37                 if (a->ifa_addr == NULL)
   38                         continue;
   39                 if (Str_isEqual(interface, a->ifa_name) && a->ifa_addr->sa_family == AF_LINK) {
   40                         int s = socket(AF_INET, SOCK_DGRAM, 0);
   41                         if (s >= 0) {
   42                                 struct ifmediareq ifmr;
   43                                 memset(&ifmr, 0, sizeof(ifmr));
   44                                 strncpy(ifmr.ifm_name, interface, sizeof(ifmr.ifm_name));
   45                                 // try SIOCGIFMEDIA - if not supported, assume the interface is UP (loopback or other virtual interface)
   46                                 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
   47                                         if (ifmr.ifm_status & IFM_AVALID && ifmr.ifm_status & IFM_ACTIVE) {
   48                                                 L->state = 1LL;
   49                                                 L->duplex = ifmr.ifm_active & 0x00100000 ? 1LL : 0LL;
   50                                         } else {
   51                                                 L->state = 0LL;
   52                                                 L->duplex = -1LL;
   53                                         }
   54                                 } else {
   55                                         L->state = 1LL;
   56                                 }
   57                                 close(s);
   58                         } else {
   59                                 L->state = -1LL;
   60                                 L->duplex = -1LL;
   61                         }
   62                         struct if_data *data = (struct if_data *)a->ifa_data;
   63                         L->timestamp.last = L->timestamp.now;
   64                         L->timestamp.now = Time_milli();
   65                         L->speed = data->ifi_baudrate;
   66                         _updateValue(&(L->ibytes), data->ifi_ibytes);
   67                         _updateValue(&(L->ipackets), data->ifi_ipackets);
   68                         _updateValue(&(L->ierrors), data->ifi_ierrors);
   69                         _updateValue(&(L->obytes), data->ifi_obytes);
   70                         _updateValue(&(L->opackets), data->ifi_opackets);
   71                         _updateValue(&(L->oerrors), data->ifi_oerrors);
   72                         return true;
   73                 }
   74         }
   75         return false;
   76 }
   77