X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibnet.so_src%2Fmain.c;h=2adaf1b85103e53879a216384c62f7c21633e0e9;hb=510431249326d5a44fc502ed5cf798b79a442ce8;hp=b39d7548e62b4e40b3850aed65e1a1437733ceba;hpb=08e1f139ca02aa899f698d90146a5bc9926c2f37;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libnet.so_src/main.c b/Usermode/Libraries/libnet.so_src/main.c index b39d7548..2adaf1b8 100644 --- a/Usermode/Libraries/libnet.so_src/main.c +++ b/Usermode/Libraries/libnet.so_src/main.c @@ -11,6 +11,7 @@ #include #include + // === CODE === int SoMain(void) { @@ -28,32 +29,6 @@ int Net_GetAddressSize(int AddressType) } } -int Net_OpenSocket(int AddrType, void *Addr, const char *Filename) -{ - int addrLen = Net_GetAddressSize(AddrType); - int i; - uint8_t *addrBuffer = Addr; - char hexAddr[addrLen*2+1]; - - for( i = 0; i < addrLen; i ++ ) - sprintf(hexAddr+i*2, "%02x", addrBuffer[i]); - - if(Filename) - { - int len = snprintf(NULL, 100, "/Devices/ip/routes/%i:%s/%s", AddrType, hexAddr, Filename); - char path[len+1]; - snprintf(path, 100, "/Devices/ip/routes/%i:%s/%s", AddrType, hexAddr, Filename); - return open(path, OPENFLAG_READ|OPENFLAG_WRITE); - } - else - { - int len = snprintf(NULL, 100, "/Devices/ip/routes/%i:%s", AddrType, hexAddr); - char path[len+1]; - snprintf(path, 100, "/Devices/ip/routes/%i:%s", AddrType, hexAddr); - return open(path, OPENFLAG_READ); - } -} - //TODO: Move out to another file char *Net_GetInterface(int AddressType, void *Address) { @@ -74,7 +49,7 @@ char *Net_GetInterface(int AddressType, void *Address) // Open fd = open("/Devices/ip/routes", 0); if( !fd ) { - fprintf(stderr, "ERROR: It seems that '/Devices/ip/routes' does not exist, are you running Acess2?\n"); + fprintf(stderr, "ERROR: Unable to open '/Devices/ip/routes'\n"); return NULL; } @@ -89,15 +64,18 @@ char *Net_GetInterface(int AddressType, void *Address) // Check answer validity if( routeNum > 0 ) { - int len = sprintf(NULL, "/Devices/ip/routes/%i", routeNum); + int len = sprintf(NULL, "/Devices/ip/routes/#%i", routeNum); char buf[len+1]; char *ret; - sprintf(buf, "/Devices/ip/routes/%i", routeNum); + sprintf(buf, "/Devices/ip/routes/#%i", routeNum); // Open route fd = open(buf, 0); - if( !fd ) return NULL; // Shouldn't happen :/ + if( fd == -1 ) { + fprintf(stderr, "Net_GetInterface - ERROR: Unable to open %s\n", buf); + return NULL; // Shouldn't happen :/ + } // Allocate space for name ret = malloc( ioctl(fd, ioctl(fd, 3, "get_interface"), NULL) + 1 );