Usermode/AxWin3 - Working on a bitmap/framebuffer window type
[tpg/acess2.git] / Usermode / Libraries / libnet.so_src / main.c
index 938d114..403a339 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+
 // === CODE ===
 int SoMain(void)
 {
@@ -28,6 +29,32 @@ 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)
 {
@@ -43,6 +70,7 @@ char *Net_GetInterface(int AddressType, void *Address)
        // 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);
@@ -52,8 +80,8 @@ char *Net_GetInterface(int AddressType, void *Address)
                }
                
                // Make structure and ask
-               *(int*)buf = AddressType;
-               memcpy(&buf[sizeof(int)], Address, size);
+               *type = AddressType;
+               memcpy(type+1, Address, size);
                routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf);
                
                // Close
@@ -62,15 +90,18 @@ char *Net_GetInterface(int AddressType, void *Address)
        
        // 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 :/
+               if( fd == -1 ) {
+                       fprintf(stderr, "Net_GetInterface - ERROR: Unabel 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 );

UCC git Repository :: git.ucc.asn.au