return 0;
}
-int sd_dhcp_client_prefixlen(const struct in_addr *addr) {
- int len = 0;
- uint32_t mask;
-
- assert_return(addr, -EADDRNOTAVAIL);
-
- mask = be32toh(addr->s_addr);
- while (mask) {
- len++;
- mask = mask << 1;
- }
-
- return len;
-}
-
int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr) {
assert_return(client, -EINVAL);
assert_return(addr, -EINVAL);
#include "libudev-private.h"
#include "util.h"
#include "bus-util.h"
+#include "net-util.h"
int link_new(Manager *manager, struct udev_device *device, Link **ret) {
_cleanup_link_free_ Link *link = NULL;
struct in_addr address;
struct in_addr netmask;
struct in_addr gateway;
- int prefixlen;
+ unsigned prefixlen;
int r;
assert(link);
return;
}
- prefixlen = sd_dhcp_client_prefixlen(&netmask);
- if (prefixlen < 0) {
- log_warning_link(link, "DHCP error: no prefixlen");
- link_enter_failed(link);
- return;
- }
+ prefixlen = net_netmask_to_prefixlen(&netmask);
r = sd_dhcp_client_get_router(client, &gateway);
if (r < 0) {
return 1;
}
+unsigned net_netmask_to_prefixlen(const struct in_addr *addr) {
+ unsigned len = 0;
+ uint32_t mask;
+
+ assert(addr);
+
+ mask = be32toh(addr->s_addr);
+ while (mask) {
+ len++;
+ mask = mask << 1;
+ }
+
+ return len;
+}
+
int config_parse_ifname(const char *unit,
const char *filename,
unsigned line,
#pragma once
#include <netinet/ether.h>
+#include <netinet/in.h>
#include <stdbool.h>
bool net_match_config(const struct ether_addr *match_mac,
const char *dev_type,
const char *dev_name);
+unsigned net_netmask_to_prefixlen(const struct in_addr *netmask);
+
int config_parse_hwaddr(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
int sd_dhcp_client_get_address(sd_dhcp_client *client, struct in_addr *addr);
int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr);
-int sd_dhcp_client_prefixlen(const struct in_addr *addr);
int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr);
int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t *addr_size);
int sd_dhcp_client_get_mtu(sd_dhcp_client *client, uint16_t *mtu);