tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsWifiAccessPoint.h (1937B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef __nsWifiAccessPoint__
      6 #define __nsWifiAccessPoint__
      7 
      8 #include <algorithm>
      9 #include "nsWifiMonitor.h"
     10 #include "nsIWifiAccessPoint.h"
     11 
     12 #include "nsString.h"
     13 #include "nsCOMArray.h"
     14 #include "mozilla/Sprintf.h"
     15 
     16 class nsWifiAccessPoint final : public nsIWifiAccessPoint {
     17  ~nsWifiAccessPoint() = default;
     18 
     19 public:
     20  NS_DECL_THREADSAFE_ISUPPORTS
     21  NS_DECL_NSIWIFIACCESSPOINT
     22 
     23  nsWifiAccessPoint();
     24 
     25  char mMac[18]{0};
     26  int mSignal;
     27  char mSsid[33]{0};
     28  int mSsidLen;
     29 
     30  void setSignal(int signal) { mSignal = signal; }
     31 
     32  void setMacRaw(const char* aString) {
     33    memcpy(mMac, aString, std::size(mMac));
     34  }
     35 
     36  void setMac(const unsigned char mac_as_int[6]) {
     37    // mac_as_int is big-endian. Write in byte chunks.
     38    // Format is XX-XX-XX-XX-XX-XX.
     39 
     40    const unsigned char holder[6] = {0};
     41    if (!mac_as_int) {
     42      mac_as_int = holder;
     43    }
     44 
     45    static const char* kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
     46 
     47    SprintfLiteral(mMac, kMacFormatString, mac_as_int[0], mac_as_int[1],
     48                   mac_as_int[2], mac_as_int[3], mac_as_int[4], mac_as_int[5]);
     49 
     50    mMac[17] = 0;
     51  }
     52 
     53  void setSSIDRaw(const char* aSSID, size_t len) {
     54    mSsidLen = std::min(len, std::size(mSsid));
     55    memcpy(mSsid, aSSID, mSsidLen);
     56  }
     57 
     58  void setSSID(const char* aSSID, unsigned long len) {
     59    if (aSSID && (len < sizeof(mSsid))) {
     60      strncpy(mSsid, aSSID, len);
     61      mSsid[len] = 0;
     62      mSsidLen = len;
     63    } else {
     64      mSsid[0] = 0;
     65      mSsidLen = 0;
     66    }
     67  }
     68 
     69  // 3-value compare for nsWifiAccessPoint
     70  int Compare(const nsWifiAccessPoint& o) const;
     71 
     72  bool operator==(const nsWifiAccessPoint& o) const;
     73  bool operator!=(const nsWifiAccessPoint& o) const { return !(*this == o); }
     74 };
     75 
     76 #endif