2 * Acess2 Networking Toolkit
3 * By John Hodge (thePowersGang)
6 * - Library main (and misc functions)
20 int Net_GetAddressSize(int AddressType)
24 case 4: return 4; // IPv4
25 case 6: return 16; // IPv6
31 //TODO: Move out to another file
32 char *Net_GetInterface(int AddressType, void *Address)
36 size = Net_GetAddressSize(AddressType);
39 fprintf(stderr, "BUG: AddressType = %i unknown\n", AddressType);
43 // Query the route manager for the route number
45 char buf[sizeof(int)+size];
48 fd = open("/Devices/ip/routes", 0);
50 fprintf(stderr, "ERROR: It seems that '/Devices/ip/routes' does not exist, are you running Acess2?\n");
54 // Make structure and ask
55 *(int*)buf = AddressType;
56 memcpy(&buf[sizeof(int)], Address, size);
57 routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf);
63 // Check answer validity
65 int len = sprintf(NULL, "/Devices/ip/routes/%i", routeNum);
69 sprintf(buf, "/Devices/ip/routes/%i", routeNum);
73 if( !fd ) return NULL; // Shouldn't happen :/
75 // Allocate space for name
76 ret = malloc( ioctl(fd, ioctl(fd, 3, "get_interface"), NULL) + 1 );
78 fprintf(stderr, "malloc() failure - Allocating space for interface name\n");
83 ioctl(fd, ioctl(fd, 3, "get_interface"), ret);