static int st_set_router(void) { char *tmp; struct in_addr addr; tmp = strtok(NULL, " "); if (tmp == NULL) { printf("! No router address given\n"); return (-1); } if ((addr.s_addr = inet_addr(tmp)) == (uint32_t)-1) { printf("! Malformed router address\n"); return (-1); } ipv4_setdefaultrouter(&addr); if (ipv4_route(IPV4_ADD_ROUTE, RT_DEFAULT, NULL, &addr) < 0) { printf("! Cannot add default route\n"); } else { printf("@ Default router %s set\n", inet_ntoa(addr)); } return (0); }
/* * Actually setup our network interface with the values derived from the * PROM, DHCP or interactively from the user. */ static void setup_interface() { char str[MAXHOSTNAMELEN]; /* will accomodate an IP too */ size_t len; struct in_addr in_addr; len = sizeof (str); if (bootinfo_get(BI_HOST_IP, str, &len, NULL) == BI_E_SUCCESS && (in_addr.s_addr = inet_addr(str)) != (in_addr_t)-1) { in_addr.s_addr = htonl(in_addr.s_addr); ipv4_setipaddr(&in_addr); } len = sizeof (str); if (bootinfo_get(BI_SUBNET_MASK, str, &len, NULL) == BI_E_SUCCESS && (in_addr.s_addr = inet_addr(str)) != (in_addr_t)-1) { in_addr.s_addr = htonl(in_addr.s_addr); ipv4_setnetmask(&in_addr); } len = sizeof (str); if (bootinfo_get(BI_ROUTER_IP, str, &len, NULL) == BI_E_SUCCESS && (in_addr.s_addr = inet_addr(str)) != (in_addr_t)-1) { in_addr.s_addr = htonl(in_addr.s_addr); ipv4_setdefaultrouter(&in_addr); (void) ipv4_route(IPV4_ADD_ROUTE, RT_DEFAULT, NULL, &in_addr); } len = sizeof (str); if (bootinfo_get(BI_HOSTNAME, str, &len, NULL) == BI_E_SUCCESS) { (void) sethostname(str, len); } }