void nsockstream::connect( const char * node, unsigned int port ) throw( sockexception, socktimeoutexception ) { // network address nsockaddr naddr( node, port ); // connect connect( &naddr ); }
static void setoutvar(void) { Type *t; Node *n; Addr a; Iter save; Bits bit; int z; t = structfirst(&save, getoutarg(curfn->type)); while(t != T) { n = nodarg(t, 1); a = zprog.from; naddr(n, &a, 0); bit = mkvar(R, &a); for(z=0; z<BITS; z++) ovar.b[z] |= bit.b[z]; t = structnext(&save); } //if(bany(&ovar)) //print("ovars = %Q\n", ovar); }
std::set<addrwithbroadcast> getlist() { std::set<addrwithbroadcast> result; struct ifconf ifc; std::vector<char> buffer(10*1024); //MAXBUFSIZE struct ifreq *ifr; int skfd; ifc.ifc_len = buffer.size(); ifc.ifc_buf = &buffer[0]; if ((skfd = ::socket(AF_INET, SOCK_DGRAM,0)) < 0) { std::cout << "new socket failed\n"; return result; } if (::ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { std::cout << "SIOCGIFCONF:Failed\n"; ::close(skfd); return result; } #ifndef __APPLE__ ifr = ifc.ifc_req; for (int i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) { #else for (int n = 0; n < ifc.ifc_len; ) { ifr = (struct ifreq*)(((char*)ifc.ifc_req) + n); n += sizeof(ifr->ifr_name); n += (ifr->ifr_addr.sa_len > sizeof(struct sockaddr) ? ifr->ifr_addr.sa_len : sizeof(struct sockaddr)); #endif if (ifr->ifr_addr.sa_family != AF_INET) continue; sockaddr_in * pAddress; if (::ioctl(skfd, SIOCGIFFLAGS, ifr) != 0) { std::cout << "SIOCGIFFLAGS:Failed\n"; continue; } short flags = ifr->ifr_flags; boost::asio::ip::address_v4::bytes_type ifaddr; pAddress = (sockaddr_in *) &ifr->ifr_addr; memcpy(&ifaddr[0], &pAddress->sin_addr, 4); if (::ioctl(skfd, SIOCGIFNETMASK, ifr) != 0) { std::cout << "SIOCGIFNETMASK:Failed\n"; continue; } boost::asio::ip::address_v4::bytes_type nmaddr; pAddress = (sockaddr_in *) &ifr->ifr_addr; memcpy(&nmaddr[0], &pAddress->sin_addr, 4); if (flags&IFF_UP && !(flags&IFF_LOOPBACK)) { boost::asio::ip::address_v4::bytes_type bcaddr; for (int i = 0; i < 4; ++i) bcaddr[i] = ifaddr[i] | ~nmaddr[i]; boost::asio::ip::address_v4 naddr(ifaddr); boost::asio::ip::address_v4 baddr(bcaddr); result.insert(addrwithbroadcast(naddr, baddr)); } } ::close(skfd); return result; } };