diff --git a/programs/net/En.rc b/programs/net/En.rc index f3d8f4f..aff6d1d 100644 --- a/programs/net/En.rc +++ b/programs/net/En.rc @@ -37,4 +37,7 @@ STRINGTABLE STRING_STOP_SVC_SUCCESS, "The %s service was stopped successfully.\n" STRING_STOP_SVC_FAIL, "The %s service failed to stop.\n" STRING_HELP_USAGE, "The syntax of this command is:\n\nNET HELP command\n -or-\nNET command /HELP\n\n Commands available are:\n NET HELP NET START NET STOP\n" + STRING_NO_ENTRIES, "There are no entries in the list.\n" + STRING_USE_HEADER, "\nStatus Local Remote\n---------------------------------------------------------------\n" + STRING_USE_ENTRY, "%s %S %S Open resources: %lu\n" } diff --git a/programs/net/Makefile.in b/programs/net/Makefile.in index 5364f4e..05dc537 100644 --- a/programs/net/Makefile.in +++ b/programs/net/Makefile.in @@ -4,7 +4,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = net.exe APPMODE = -mconsole -IMPORTS = user32 advapi32 kernel32 +IMPORTS = user32 advapi32 kernel32 netapi32 C_SRCS = net.c diff --git a/programs/net/net.c b/programs/net/net.c index 4bc3652..460c9ea 100644 --- a/programs/net/net.c +++ b/programs/net/net.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "resources.h" #define NET_START 0001 @@ -36,6 +37,45 @@ int output_string(int msg, ...) return 0; } +static BOOL net_use(int argc, char *argv[]) +{ + USE_INFO_2 *buffer, *connection; + DWORD read, total, resume_handle, rc, i; + const char *status_description[] = { "OK", "Paused", "Disconnected", "An error occurred", + "A network error occurred", "Connection is being made", + "Reconnecting" }; + resume_handle = 0; + buffer = NULL; + + if(argc<3) + { + do { + rc = NetUseEnum(NULL, 2, (BYTE **) &buffer, 2048, &read, &total, &resume_handle); + if (rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS) + { + break; + } + + if(total == 0) + { + output_string(STRING_NO_ENTRIES); + break; + } + + output_string(STRING_USE_HEADER); + for (i = 0, connection = buffer; i < read; ++i, ++connection) + output_string(STRING_USE_ENTRY, status_description[connection->ui2_status], connection->ui2_local, + connection->ui2_remote, connection->ui2_refcount); + + if (buffer != NULL) NetApiBufferFree(buffer); + } while (rc == ERROR_MORE_DATA); + + return TRUE; + } + + return FALSE; +} + static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle) { LPENUM_SERVICE_STATUS dependencies = NULL; @@ -159,5 +199,10 @@ int main(int argc, char *argv[]) return 0; } + if(!strcasecmp(argv[1], "use")) + { + if(!net_use(argc, argv)) return 1; + } + return 0; } diff --git a/programs/net/resources.h b/programs/net/resources.h index 4c1c167..c5199fd 100644 --- a/programs/net/resources.h +++ b/programs/net/resources.h @@ -30,3 +30,6 @@ #define STRING_STOP_SVC_SUCCESS 112 #define STRING_STOP_SVC_FAIL 113 #define STRING_HELP_USAGE 114 +#define STRING_NO_ENTRIES 115 +#define STRING_USE_HEADER 116 +#define STRING_USE_ENTRY 117