X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fifconfig_src%2Fmain.c;h=3a45530497d58820574408f09b695d3f3cdbcc4c;hb=92517b68b7582251f69db7e062d5e5a4c773791f;hp=7f8746b3562386f329a41207235d288ec60c46c1;hpb=7514bb8053931759b99f77d3f9ad70446b0625ac;p=tpg%2Facess2.git diff --git a/Usermode/Applications/ifconfig_src/main.c b/Usermode/Applications/ifconfig_src/main.c index 7f8746b3..3a455304 100644 --- a/Usermode/Applications/ifconfig_src/main.c +++ b/Usermode/Applications/ifconfig_src/main.c @@ -3,122 +3,306 @@ */ #include #include +#include #include #include +#include // === CONSTANTS === #define FILENAME_MAX 255 #define IPSTACK_ROOT "/Devices/ip" +// TODO: Move this to a header +#define ntohs(v) (((v&0xFF)<<8)|((v>>8)&0xFF)) + // === PROTOTYPES === -void PrintUsage(char *ProgName); -void DumpInterfaces( int DumpAll ); - int AddInterface( char *Address ); - int DoAutoConfig( char *Device ); +void PrintUsage(const char *ProgName); +void DumpInterfaces(void); +void DumpRoutes(void); +void DumpInterface(const char *Name); +void DumpRoute(const char *Name); + int AddInterface(const char *Device); +void AddRoute(const char *Interface, void *Dest, int MaskBits, void *NextHop); + int DoAutoConfig(const char *Device); + int SetAddress(int IFNum, const char *Address); + int ParseIPAddres(const char *Address, uint8_t *Dest, int *SubnetBits); // === CODE === /** - * \fn int main(int argc, char *argv[]) - * \brief Entrypoint + * \brief Program entrypoint */ int main(int argc, char *argv[]) { + int ret; + + // No args, dump interfaces if(argc == 1) { - DumpInterfaces(0); + DumpInterfaces(); + return 0; + } + + if( strcmp(argv[1], "routes") == 0 ) { + DumpRoutes(); return 0; } + // Add a new interface if( strcmp(argv[1], "add") == 0 ) { + if( argc < 4 ) { + fprintf(stderr, "ERROR: '%s add' requires two arguments, %i passed\n", argv[0], argc-2); + PrintUsage(argv[0]); + return -1; + } + // TODO: Also set the IP address as the usage says it does + ret = AddInterface( argv[2] ); + if(ret < 0) return ret; + ret = SetAddress( ret, argv[3] ); + return ret; + } + + // Delete an interface + if( strcmp(argv[1], "del") == 0 ) { if( argc < 3 ) { - fprintf(stderr, "ERROR: `add` requires an argument\n"); + fprintf(stderr, "ERROR: '%s del' requires an argument\n", argv[0]); PrintUsage(argv[0]); - return 0; + return -1; } - return AddInterface( argv[2] ); + // TODO: } + // Autoconfigure an interface + // NOTE: Debugging hack (see the function for more details) if( strcmp(argv[1], "autoconf") == 0 ) { DoAutoConfig(argv[2]); + return 0; } + // Print usage instructions + PrintUsage(argv[0]); + return 0; } -void PrintUsage(char *ProgName) +/** + * \brief Print usage instructions + */ +void PrintUsage(const char *ProgName) { - fprintf(stderr, "Usage: %s [add ]\n", ProgName); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " %s add /\n", ProgName); + fprintf(stderr, " Add a new interface listening on with the specified\n"); + fprintf(stderr, " address.\n"); + fprintf(stderr, " %s del \n", ProgName); + fprintf(stderr, " %s set