2 * Acess2 Networking Toolkit
3 * By John Hodge (thePowersGang)
6 * - Library main (and misc functions)
21 int Net_GetAddressSize(int AddressType)
25 case 4: return 4; // IPv4
26 case 6: return 16; // IPv6
32 //TODO: Move out to another file
33 char *Net_GetInterface(int AddressType, void *Address)
37 size = Net_GetAddressSize(AddressType);
40 fprintf(stderr, "BUG: AddressType = %i unknown\n", AddressType);
44 // Query the route manager for the route number
46 char buf[sizeof(int)+size];
47 uint32_t *type = (void*)buf;
50 fd = _SysOpen("/Devices/ip/routes", 0);
52 fprintf(stderr, "ERROR: Unable to open '/Devices/ip/routes'\n");
56 // Make structure and ask
58 memcpy(type+1, Address, size);
59 routeNum = _SysIOCtl(fd, _SysIOCtl(fd, 3, "locate_route"), buf);
65 // Check answer validity
67 int len = sprintf(NULL, "/Devices/ip/routes/#%i", routeNum);
71 sprintf(buf, "/Devices/ip/routes/#%i", routeNum);
74 fd = _SysOpen(buf, 0);
76 fprintf(stderr, "Net_GetInterface - ERROR: Unable to open %s\n", buf);
77 return NULL; // Shouldn't happen :/
80 // Allocate space for name
81 ret = malloc( _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), NULL) + 1 );
83 fprintf(stderr, "malloc() failure - Allocating space for interface name\n");
88 _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), ret);