status_t BNetworkInterface::AddAddress(const BNetworkAddress& local) { BNetworkInterfaceAddress address; address.SetAddress(local.SockAddr()); return do_ifaliasreq(Name(), B_SOCKET_ADD_ALIAS, address); }
status_t BNetworkInterface::RemoveAddress(const BNetworkAddress& address) { ifreq request; memcpy(&request.ifr_addr, &address.SockAddr(), address.Length()); return do_request(address.Family(), request, Name(), B_SOCKET_REMOVE_ALIAS); }
status_t BNetworkInterface::AddDefaultRoute(const BNetworkAddress& gateway) { route_entry route; memset(&route, 0, sizeof(route_entry)); route.flags = RTF_STATIC | RTF_DEFAULT | RTF_GATEWAY; route.gateway = const_cast<sockaddr*>(&gateway.SockAddr()); return AddRoute(route); }
int32 BNetworkInterface::FindAddress(const BNetworkAddress& address) { int socket = ::socket(address.Family(), SOCK_DGRAM, 0); if (socket < 0) return -1; FileDescriptorCloser closer(socket); ifaliasreq request; memset(&request, 0, sizeof(ifaliasreq)); strlcpy(request.ifra_name, Name(), IF_NAMESIZE); request.ifra_index = -1; memcpy(&request.ifra_addr, &address.SockAddr(), address.Length()); if (ioctl(socket, B_SOCKET_GET_ALIAS, &request, sizeof(struct ifaliasreq)) < 0) { return -1; } return request.ifra_index; }