void loconfig() { struct ifreq ifr = {0}; ifr.ifr_addr.sa_len = sizeof(struct sockaddr_in); ifr.ifr_addr.sa_family = AF_INET; ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = htonl(0x7F000001); in_control(NULL, SIOCSIFADDR, &ifr, &loif); }
addifp (struct ifnet *ifp, struct in_addr in_addr) { struct socket s; register struct ifreq ifr; ifr.ifr_addr.sa_family = AF_INET; ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr = in_addr; s.so_state = SS_PRIV; in_control(&s,SIOCSIFADDR,(void*)&ifr,ifp); }
void IPCP::UpdateAddresses() { RemoveRoutes(); if(State() != PPP_OPENED_STATE && !Interface().DoesConnectOnDemand()) return; struct in_aliasreq inreq; struct ifreq ifreqAddress, ifreqDestination; memset(&inreq, 0, sizeof(struct in_aliasreq)); memset(&ifreqAddress, 0, sizeof(struct ifreq)); memset(&ifreqDestination, 0, sizeof(struct ifreq)); memset(&fGateway, 0, sizeof(struct sockaddr_in)); // create local address inreq.ifra_addr.sin_family = AF_INET; if(fLocalRequests.address != INADDR_ANY) inreq.ifra_addr.sin_addr.s_addr = fLocalRequests.address; else if(fLocalConfiguration.address == INADDR_ANY) inreq.ifra_addr.sin_addr.s_addr = 0x010F0F0F; // was: INADDR_BROADCAST else inreq.ifra_addr.sin_addr.s_addr = fLocalConfiguration.address; inreq.ifra_addr.sin_len = sizeof(struct sockaddr_in); memcpy(&ifreqAddress.ifr_addr, &inreq.ifra_addr, sizeof(struct sockaddr_in)); // create destination address fGateway.sin_family = AF_INET; if(fPeerRequests.address != INADDR_ANY) fGateway.sin_addr.s_addr = fPeerRequests.address; else if(fPeerConfiguration.address == INADDR_ANY) fGateway.sin_addr.s_addr = 0x020F0F0F; // was: INADDR_BROADCAST else fGateway.sin_addr.s_addr = fPeerConfiguration.address; fGateway.sin_len = sizeof(struct sockaddr_in); memcpy(&inreq.ifra_dstaddr, &fGateway, sizeof(struct sockaddr_in)); memcpy(&ifreqDestination.ifr_dstaddr, &inreq.ifra_dstaddr, sizeof(struct sockaddr_in)); // create netmask inreq.ifra_mask.sin_family = AF_INET; inreq.ifra_mask.sin_addr.s_addr = fLocalRequests.netmask; inreq.ifra_mask.sin_len = sizeof(struct sockaddr_in); // tell stack to use these values if(in_control(NULL, SIOCAIFADDR, (caddr_t) &inreq, Interface().Ifnet()) != B_OK) ERROR("IPCP: UpdateAddress(): SIOCAIFADDR returned error!\n"); if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress, Interface().Ifnet()) != B_OK) ERROR("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n"); if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination, Interface().Ifnet()) != B_OK) ERROR("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n"); memcpy(&inreq.ifra_addr, &inreq.ifra_mask, sizeof(struct sockaddr_in)); // SIOCISFNETMASK wants the netmask to be in ifra_addr if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq, Interface().Ifnet()) != B_OK) ERROR("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n"); // add default/subnet route if(Side() == PPP_LOCAL_SIDE) { if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask, (struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask, RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK) ERROR("IPCP: UpdateAddress(): could not add default/subnet route!\n"); --fDefaultRoute->rt_refcnt; } }