mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 09:42:42 +01:00 
			
		
		
		
	added support for the {gwaddr} variable
This commit is contained in:
		
							
								
								
									
										3
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								Makefile
									
									
									
									
									
								
							@@ -16,5 +16,8 @@ install: build
 | 
				
			|||||||
run: build
 | 
					run: build
 | 
				
			||||||
	./build/waybar
 | 
						./build/waybar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					debug-run: build
 | 
				
			||||||
 | 
						./build/waybar --log-level debug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	rm -rf build
 | 
						rm -rf build
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,6 +67,7 @@ class Network : public ALabel {
 | 
				
			|||||||
  bool        carrier_;
 | 
					  bool        carrier_;
 | 
				
			||||||
  std::string ifname_;
 | 
					  std::string ifname_;
 | 
				
			||||||
  std::string ipaddr_;
 | 
					  std::string ipaddr_;
 | 
				
			||||||
 | 
					  std::string gwaddr_;
 | 
				
			||||||
  std::string netmask_;
 | 
					  std::string netmask_;
 | 
				
			||||||
  int         cidr_;
 | 
					  int         cidr_;
 | 
				
			||||||
  int32_t     signal_strength_dbm_;
 | 
					  int32_t     signal_strength_dbm_;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,6 +131,8 @@ Addressed by *network*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
*{ipaddr}*: The first IP of the interface.
 | 
					*{ipaddr}*: The first IP of the interface.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*{gwaddr}*: The default gateway for the interface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*{netmask}*: The subnetmask corresponding to the IP.
 | 
					*{netmask}*: The subnetmask corresponding to the IP.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*{cidr}*: The subnetmask corresponding to the IP in CIDR notation.
 | 
					*{cidr}*: The subnetmask corresponding to the IP in CIDR notation.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -348,6 +348,7 @@ auto waybar::modules::Network::update() -> void {
 | 
				
			|||||||
      fmt::arg("ifname", ifname_),
 | 
					      fmt::arg("ifname", ifname_),
 | 
				
			||||||
      fmt::arg("netmask", netmask_),
 | 
					      fmt::arg("netmask", netmask_),
 | 
				
			||||||
      fmt::arg("ipaddr", ipaddr_),
 | 
					      fmt::arg("ipaddr", ipaddr_),
 | 
				
			||||||
 | 
					      fmt::arg("gwaddr", gwaddr_),
 | 
				
			||||||
      fmt::arg("cidr", cidr_),
 | 
					      fmt::arg("cidr", cidr_),
 | 
				
			||||||
      fmt::arg("frequency", frequency_),
 | 
					      fmt::arg("frequency", frequency_),
 | 
				
			||||||
      fmt::arg("icon", getIcon(signal_strength_, state_)),
 | 
					      fmt::arg("icon", getIcon(signal_strength_, state_)),
 | 
				
			||||||
@@ -376,6 +377,7 @@ auto waybar::modules::Network::update() -> void {
 | 
				
			|||||||
          fmt::arg("ifname", ifname_),
 | 
					          fmt::arg("ifname", ifname_),
 | 
				
			||||||
          fmt::arg("netmask", netmask_),
 | 
					          fmt::arg("netmask", netmask_),
 | 
				
			||||||
          fmt::arg("ipaddr", ipaddr_),
 | 
					          fmt::arg("ipaddr", ipaddr_),
 | 
				
			||||||
 | 
					          fmt::arg("gwaddr", gwaddr_),
 | 
				
			||||||
          fmt::arg("cidr", cidr_),
 | 
					          fmt::arg("cidr", cidr_),
 | 
				
			||||||
          fmt::arg("frequency", frequency_),
 | 
					          fmt::arg("frequency", frequency_),
 | 
				
			||||||
          fmt::arg("icon", getIcon(signal_strength_, state_)),
 | 
					          fmt::arg("icon", getIcon(signal_strength_, state_)),
 | 
				
			||||||
@@ -409,6 +411,7 @@ void waybar::modules::Network::clearIface() {
 | 
				
			|||||||
  ifname_.clear();
 | 
					  ifname_.clear();
 | 
				
			||||||
  essid_.clear();
 | 
					  essid_.clear();
 | 
				
			||||||
  ipaddr_.clear();
 | 
					  ipaddr_.clear();
 | 
				
			||||||
 | 
					  gwaddr_.clear();
 | 
				
			||||||
  netmask_.clear();
 | 
					  netmask_.clear();
 | 
				
			||||||
  carrier_ = false;
 | 
					  carrier_ = false;
 | 
				
			||||||
  cidr_ = 0;
 | 
					  cidr_ = 0;
 | 
				
			||||||
@@ -581,6 +584,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
 | 
				
			|||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    char	temp_gw_addr[INET6_ADDRSTRLEN];
 | 
				
			||||||
  case RTM_DELROUTE:
 | 
					  case RTM_DELROUTE:
 | 
				
			||||||
    is_del_event = true;
 | 
					    is_del_event = true;
 | 
				
			||||||
  case RTM_NEWROUTE: {
 | 
					  case RTM_NEWROUTE: {
 | 
				
			||||||
@@ -595,6 +599,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
 | 
				
			|||||||
    int            temp_idx = -1;
 | 
					    int            temp_idx = -1;
 | 
				
			||||||
    uint32_t       priority = 0;
 | 
					    uint32_t       priority = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Find the message(s) concerting the main routing table, each message
 | 
					    /* Find the message(s) concerting the main routing table, each message
 | 
				
			||||||
     * corresponds to a single routing table entry.
 | 
					     * corresponds to a single routing table entry.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@@ -612,9 +617,10 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
 | 
				
			|||||||
      case RTA_GATEWAY:
 | 
					      case RTA_GATEWAY:
 | 
				
			||||||
        /* The gateway of the route.
 | 
					        /* The gateway of the route.
 | 
				
			||||||
         *
 | 
					         *
 | 
				
			||||||
         * If someone every needs to figure out the gateway address as well,
 | 
					         * If someone ever needs to figure out the gateway address as well,
 | 
				
			||||||
         * it's here as the attribute payload.
 | 
					         * it's here as the attribute payload.
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
 | 
						inet_ntop(net->family_, RTA_DATA(attr), temp_gw_addr, sizeof(temp_gw_addr));
 | 
				
			||||||
        has_gateway = true;
 | 
					        has_gateway = true;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      case RTA_DST: {
 | 
					      case RTA_DST: {
 | 
				
			||||||
@@ -655,6 +661,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
 | 
				
			|||||||
        net->clearIface();
 | 
					        net->clearIface();
 | 
				
			||||||
        net->ifid_ = temp_idx;
 | 
					        net->ifid_ = temp_idx;
 | 
				
			||||||
        net->route_priority = priority;
 | 
					        net->route_priority = priority;
 | 
				
			||||||
 | 
						net->gwaddr_ = temp_gw_addr;
 | 
				
			||||||
 | 
						spdlog::debug("netwok: gateway {}", net->gwaddr_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority);
 | 
					        spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user