friendlier error messages for vpn-users in get-gateway

This commit is contained in:
Eric 2013-08-31 16:16:49 -04:00
parent 5ff9684bf9
commit fc6ef16b8f

View File

@ -131,11 +131,23 @@ int get_hw_addr(struct in_addr *gw_ip, char *iface, unsigned char *hw_mac)
while (RTA_OK(rt_attr, rt_len)) { while (RTA_OK(rt_attr, rt_len)) {
switch (rt_attr->rta_type) { switch (rt_attr->rta_type) {
case NDA_LLADDR: case NDA_LLADDR:
assert(RTA_PAYLOAD(rt_attr) == IFHWADDRLEN); if (RTA_PAYLOAD(rt_attr) != IFHWADDRLEN) {
// could be using a VPN
log_fatal("get_gateway", "Unexpected hardware address length (%d).\n\n" \
" If you are using a VPN, supply the --vpn flag (and provide an interface via -i)",
RTA_PAYLOAD(rt_attr));
exit(1);
}
memcpy(mac, RTA_DATA(rt_attr), IFHWADDRLEN); memcpy(mac, RTA_DATA(rt_attr), IFHWADDRLEN);
break; break;
case NDA_DST: case NDA_DST:
assert(RTA_PAYLOAD(rt_attr) == sizeof(dst_ip)); if (RTA_PAYLOAD(rt_attr) != sizeof(dst_ip)) {
// could be using a VPN
log_fatal("get_gateway", "Unexpected IP address length (%d).\n" \
" If you are using a VPN, supply the --vpn flag (and provide an interface via -i)",
RTA_PAYLOAD(rt_attr));
exit(1);
}
memcpy(&dst_ip, RTA_DATA(rt_attr), sizeof(dst_ip)); memcpy(&dst_ip, RTA_DATA(rt_attr), sizeof(dst_ip));
if (memcmp(&dst_ip, gw_ip, sizeof(dst_ip)) == 0) { if (memcmp(&dst_ip, gw_ip, sizeof(dst_ip)) == 0) {
correct_ip = 1; correct_ip = 1;