#include <stdlib.h>
#include <stdio.h>
+
// === CODE ===
int SoMain(void)
{
// Query the route manager for the route number
{
char buf[sizeof(int)+size];
+ 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
- *(int*)buf = AddressType;
- memcpy(&buf[sizeof(int)], Address, size);
- routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf);
+ *type = AddressType;
+ memcpy(type+1, Address, size);
+ routeNum = _SysIOCtl(fd, _SysIOCtl(fd, 3, "locate_route"), buf);
// Close
- close(fd);
+ _SysClose(fd);
}
// 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 :/
+ fd = _SysOpen(buf, 0);
+ 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 );
+ 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;
}