- fd = open(IPSTACK_ROOT"/routes", 0);
- num = ioctl(fd, ioctl(fd, 3, "add_route"), (char*)Interface);
- close(fd);
-
- // Open route
- sprintf(tmp, IPSTACK_ROOT"/routes/%i", num);
- fd = open(tmp, 0);
+ int addrsize = Net_GetAddressSize(AddressType);
+ int len = snprintf(NULL, 0, "/Devices/ip/routes/%i::%i:%i", AddressType, MaskBits, Metric) + addrsize*2;
+ char path[len+1];
+ {
+ int i, ofs;
+ ofs = sprintf(path, "/Devices/ip/routes/%i:", AddressType);
+ for( i = 0; i < addrsize; i ++ )
+ sprintf(path+ofs+i*2, "%02x", ((uint8_t*)Dest)[i]);
+ ofs += addrsize*2;
+ sprintf(path+ofs, ":%i:%i", MaskBits, Metric);
+ }
+
+ fd = open(path, 0);
+ if( fd != -1 ) {
+ close(fd);
+ fprintf(stderr, "Unable to create route '%s', already exists\n", path);
+ return ;
+ }
+ fd = open(path, OPENFLAG_CREATE, 0);
+ if( fd == -1 ) {
+ fprintf(stderr, "Unable to create '%s'\n", path);
+ return ;
+ }