X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fifconfig_src%2Fmain.c;h=5f50dac39b0cfa92452cf775f6854c5542fdd497;hb=321d008781422b7d7137e9acc1ba0e84dec79ff1;hp=eb8fa19d148186b3b9043c0fdde763be219c773e;hpb=b3fa9a08edcbc459bd8e9df73186e292470ebfc3;p=tpg%2Facess2.git diff --git a/Usermode/Applications/ifconfig_src/main.c b/Usermode/Applications/ifconfig_src/main.c index eb8fa19d..5f50dac3 100644 --- a/Usermode/Applications/ifconfig_src/main.c +++ b/Usermode/Applications/ifconfig_src/main.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include @@ -10,114 +11,188 @@ #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 DumpInterface(const char *Name); + int AddInterface(const char *Device); + 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; } + // 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