diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index f78374d..1eaefa4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,20 +1,20 @@ { - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "compilerPath": "C:\\gcc\\bin\\gcc.exe", - "cStandard": "c17", - "cppStandard": "gnu++17", - "intelliSenseMode": "windows-gcc-x64" - } - ], - "version": 4 + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..94c599c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Usuario/Documents/GitHub/quickcmd", + "program": "c:/Users/Usuario/Documents/GitHub/quickcmd/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index f7ab0ea..2f9d7b2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,62 @@ { - "files.associations": { - "ws2tcpip.h": "c" - } + "files.associations": { + "ws2tcpip.h": "c" + }, + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false } \ No newline at end of file diff --git a/RUN.cmd b/RUN.cmd index d9f5815..27958f9 100644 --- a/RUN.cmd +++ b/RUN.cmd @@ -1 +1 @@ -gcc main.c cmd_functions.c -o outputs/quickcmd.exe -lws2_32 && "./outputs/quickcmd.exe" \ No newline at end of file +gcc main.c cmd_functions.c -o outputs/quickcmd.exe -liphlpapi -lws2_32 && "./outputs/quickcmd.exe" \ No newline at end of file diff --git a/cmd_functions.c b/cmd_functions.c index 93b49ff..c885855 100644 --- a/cmd_functions.c +++ b/cmd_functions.c @@ -11,16 +11,68 @@ #include #include #include - +#include // For IP address retrieval #pragma comment(lib, "Ws2_32.lib") // Link with Winsock library +#pragma comment(lib, "Iphlpapi.lib") // Link with IP Helper library void printfNewLine(char *str); +void ipaddr(); +int hostname(); +void display_help(); +// Function to retrieve and display the local machine's IP addresses void ipaddr() { - printf("IP ADDRESS: 192.12.345.23\n"); + DWORD dwSize = 0; + DWORD dwRetVal = 0; + IP_ADAPTER_INFO *pAdapterInfo; + IP_ADAPTER_INFO *pAdapter = NULL; + + // Allocate memory for the adapter info structure + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO)); + if (pAdapterInfo == NULL) + { + printf("Error allocating memory needed to call GetAdaptersInfo\n"); + return; + } + + // Make an initial call to GetAdaptersInfo to get the necessary size of the buffer + dwSize = sizeof(IP_ADAPTER_INFO); + if (GetAdaptersInfo(pAdapterInfo, &dwSize) == ERROR_BUFFER_OVERFLOW) + { + free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(dwSize); + if (pAdapterInfo == NULL) + { + printf("Error allocating memory\n"); + return; + } + } + + // Call GetAdaptersInfo to get the adapter information + if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &dwSize)) == NO_ERROR) + { + pAdapter = pAdapterInfo; + while (pAdapter) + { + printf("Adapter Name: %s\n", pAdapter->AdapterName); + printf("IP Address: %s\n", pAdapter->IpAddressList.IpAddress.String); + + // Move to the next adapter in the list + pAdapter = pAdapter->Next; + } + } + else + { + printf("GetAdaptersInfo failed with error: %d\n", dwRetVal); + } + + // Free allocated memory + if (pAdapterInfo) + free(pAdapterInfo); } +// Function to get and display the local machine's hostname int hostname() { WSADATA wsaData; @@ -53,6 +105,7 @@ int hostname() return EXIT_SUCCESS; } +// Function to display help commands void display_help() { printfNewLine("Available commands:"); @@ -62,8 +115,8 @@ void display_help() printfNewLine(" exit - Exit the program"); } -void printfNewLine(char * str) +// Utility function to print strings with a newline +void printfNewLine(char *str) { printf("%s\n", str); } -