Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP_ADDRESS FUNCTION #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
63 changes: 60 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion RUN.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gcc main.c cmd_functions.c -o outputs/quickcmd.exe -lws2_32 && "./outputs/quickcmd.exe"
gcc main.c cmd_functions.c -o outputs/quickcmd.exe -liphlpapi -lws2_32 && "./outputs/quickcmd.exe"
61 changes: 57 additions & 4 deletions cmd_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,68 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

#include <iphlpapi.h> // 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;
Expand Down Expand Up @@ -53,6 +105,7 @@ int hostname()
return EXIT_SUCCESS;
}

// Function to display help commands
void display_help()
{
printfNewLine("Available commands:");
Expand All @@ -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);
}

Loading