X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FLibraries%2Flibnet.so_src%2Fmain.c;h=2b3ff76c8bfd95bf46fc092df4a5566b964618dd;hb=545c440973f9676efe7cb01edf9ec47b61023513;hp=403a3394bc6290a0d3a28aeab94b8c0b423103f8;hpb=bfacdd3b71576cf6ceaa83352d3a7d162adb75e1;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libnet.so_src/main.c b/Usermode/Libraries/libnet.so_src/main.c index 403a3394..2b3ff76c 100644 --- a/Usermode/Libraries/libnet.so_src/main.c +++ b/Usermode/Libraries/libnet.so_src/main.c @@ -29,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) { @@ -73,19 +47,19 @@ char *Net_GetInterface(int AddressType, void *Address) uint32_t *type = (void*)buf; // Open - fd = open("/Devices/ip/routes", 0); + fd = _SysOpen("/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; } // Make structure and ask *type = AddressType; memcpy(type+1, Address, size); - routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf); + routeNum = _SysIOCtl(fd, _SysIOCtl(fd, 3, "locate_route"), buf); // Close - close(fd); + _SysClose(fd); } // Check answer validity @@ -97,24 +71,24 @@ char *Net_GetInterface(int AddressType, void *Address) sprintf(buf, "/Devices/ip/routes/#%i", routeNum); // Open route - fd = open(buf, 0); + fd = _SysOpen(buf, 0); if( fd == -1 ) { - fprintf(stderr, "Net_GetInterface - ERROR: Unabel to open %s\n", buf); + 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 ); + ret = malloc( _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), NULL) + 1 ); if( !ret ) { fprintf(stderr, "malloc() failure - Allocating space for interface name\n"); return NULL; } // Get name - ioctl(fd, ioctl(fd, 3, "get_interface"), ret); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), ret); // Close and return - close(fd); + _SysClose(fd); return ret; }