-static void set_ifreq_to_ifname(struct ifreq *ifreq)
-{
- memset(ifreq, 0, sizeof(struct ifreq));
- strncpy_IFNAMSIZ(ifreq->ifr_name, G.iface);
-}
-
-static const char *strstatus(int status)
-{
- if (status == IFSTATUS_ERR)
- return "error";
- return "down\0up" + (status * 5);
-}
-
-static void up_iface(void)
-{
- struct ifreq ifrequest;
-
- if (!G.iface_exists)
- return;
-
- set_ifreq_to_ifname(&ifrequest);
- if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "getting interface flags") < 0) {
- G.iface_exists = 0;
- return;
- }
-
- if (!(ifrequest.ifr_flags & IFF_UP)) {
- ifrequest.ifr_flags |= IFF_UP;
- /* Let user know we mess up with interface */
- bb_error_msg("upping interface");
- if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0)
- xfunc_die();
- }
-
-#if 0 /* why do we mess with IP addr? It's not our business */
- if (network_ioctl(SIOCGIFADDR, &ifrequest, "can't get interface address") < 0) {
- } else if (ifrequest.ifr_addr.sa_family != AF_INET) {
- bb_perror_msg("the interface is not IP-based");
- } else {
- ((struct sockaddr_in*)(&ifrequest.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
- network_ioctl(SIOCSIFADDR, &ifrequest, "can't set interface address");
- }
- network_ioctl(SIOCGIFFLAGS, &ifrequest, "can't get interface flags");
-#endif
-}
-
-static void maybe_up_new_iface(void)
-{
- if (!(option_mask32 & FLAG_NO_AUTO))
- up_iface();
-
-#if 0 /* bloat */
- struct ifreq ifrequest;
- struct ethtool_drvinfo driver_info;
-
- set_ifreq_to_ifname(&ifrequest);
- driver_info.cmd = ETHTOOL_GDRVINFO;
- ifrequest.ifr_data = &driver_info;
- if (network_ioctl(SIOCETHTOOL, &ifrequest, NULL) == 0) {
- char buf[sizeof("/xx:xx:xx:xx:xx:xx")];
-
- /* Get MAC */
- buf[0] = '\0';
- set_ifreq_to_ifname(&ifrequest);
- if (network_ioctl(SIOCGIFHWADDR, &ifrequest, NULL) == 0) {
- sprintf(buf, "/%02X:%02X:%02X:%02X:%02X:%02X",
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[0]),
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[1]),
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[2]),
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[3]),
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[4]),
- (uint8_t)(ifrequest.ifr_hwaddr.sa_data[5]));
- }
-
- bb_error_msg("using interface %s%s with driver<%s> (version: %s)",
- G.iface, buf, driver_info.driver, driver_info.version);
- }
-#endif
-
- G.cached_detect_link_func = NULL;
-}