void ServerConnection::acceptNewConnection(){ int netHandle = GetNewAcceptNetWork(); if(netHandle != -1){ Connection *newConnection = new Connection(netHandle); int tmp; IPDATA ip; switch(status){ case WAIT_CONNECTION_MODE: tmp = getFirstBrankIndex_(); if(tmp == -1){ newConnection->send("ERROR 01: TOO MANY CLIENTS"); delete newConnection; CloseNetWork(netHandle); return; } clients_[tmp] = newConnection; GetNetWorkIP(netHandle, &ips_[tmp]); connected_[tmp] = true; break; case REJECT_CONNECTION_MODE: GetNetWorkIP(netHandle, &ip); for(int i = 0; i < getClientNum(); ++i){ if(!connected_[i] && isSameIP(ip, ips_[i])){ clients_[i] = newConnection; connected_[i] = true; } } newConnection->send("ERROR 02: CONNECTION IS REJECTED"); delete newConnection; CloseNetWork(netHandle); break; } } }
int isDestinedToMe(arp_hdr arpHeader) { char localIpAddress[INET_ADDRSTRLEN]; populateLocalIpAddress(localIpAddress); if (isSameIP(localIpAddress,getIpAddStr_ARPIPFMT(arpHeader.target_ip))) { return TRUE; } return FALSE; }