// Universal Plug and Play // UPnP is used in this demo to programmatically manipulate // port forwarding entries on the user's router. #include #include #include using namespace std; // Check for errors and deal with them void CheckError() { if(mnGetErrorFlag() == true) { system("CLS"); cout << "An unexpected error has occurred. This indicates that Universal Plug and Play is disabled or is not functioning properly on your computer or network.\n"; cout << "\nDetails of this error are as follows: \n"; cout << "Full error message: " << mnGetErrorFull() << "\n\n"; cout << "Operation: " << mnGetErrorOperation() << '\n'; cout << "Command: " << mnGetErrorCommand() << '\n'; cout << "Code: " << mnGetErrorCode() << '\n'; cout << "Line: " << mnGetErrorLine() << '\n'; cout << "File: " << mnGetErrorFile() << '\n'; cout << "\n"; system("PAUSE"); exit(0); } } // Update NAT non blocking void DoUpdate(bool ReloadInfo, char * Title) { if(ReloadInfo == true) { // Start update NAT action without blocking cout << "Updating NAT...\n"; long long int Action = mnUpdateNAT(false); CheckError(); // Wait for update to finish int iResult; do { iResult = mnPollUPNP(Action); Sleep(1); } while(iResult == 2); // Loop until action is completed CheckError(); } // Display information loaded by mnUpdateNAT system("CLS"); cout << "Port map information " << Title << '\n'; for(unsigned int n = 0;n