ifconfig: check the family is available

* fixes #6489
* fixes 64-bit warnings

Change-Id: I6ddfee8ec418881fddc0561b8b464a7d739dec9e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6454
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jérôme Duval 2023-05-19 14:05:50 +02:00 committed by waddlesplash
parent 4e9653027d
commit fa82fcc532

View File

@ -609,11 +609,11 @@ list_interface(const char* name)
ifreq_stats stats; ifreq_stats stats;
if (interface.GetStats(stats) == B_OK) { if (interface.GetStats(stats) == B_OK) {
printf("\tReceive: %d packets, %d errors, %Ld bytes, %d mcasts, %d " printf("\tReceive: %d packets, %d errors, %" B_PRId64 " bytes, %d mcasts, %d "
"dropped\n", stats.receive.packets, stats.receive.errors, "dropped\n", stats.receive.packets, stats.receive.errors,
stats.receive.bytes, stats.receive.multicast_packets, stats.receive.bytes, stats.receive.multicast_packets,
stats.receive.dropped); stats.receive.dropped);
printf("\tTransmit: %d packets, %d errors, %Ld bytes, %d mcasts, %d " printf("\tTransmit: %d packets, %d errors, %" B_PRId64 " bytes, %d mcasts, %d "
"dropped\n", stats.send.packets, stats.send.errors, "dropped\n", stats.send.packets, stats.send.errors,
stats.send.bytes, stats.send.multicast_packets, stats.send.dropped); stats.send.bytes, stats.send.multicast_packets, stats.send.dropped);
printf("\tCollisions: %d\n", stats.collisions); printf("\tCollisions: %d\n", stats.collisions);
@ -696,6 +696,14 @@ configure_interface(const char* name, char* const* args, int32 argCount)
int family = get_address_family(args[i]); int family = get_address_family(args[i]);
if (family != AF_UNSPEC) if (family != AF_UNSPEC)
i++; i++;
int socket = ::socket(family, SOCK_DGRAM, 0);
if (socket < 0) {
fprintf(stderr, "%s: The requested address family is not available.\n",
kProgramName);
exit(1);
}
close(socket);
// try to parse address // try to parse address