Usermode/dhcpclient - A little cleanup
authorJohn Hodge <[email protected]>
Wed, 10 Jul 2013 14:57:16 +0000 (22:57 +0800)
committerJohn Hodge <[email protected]>
Wed, 10 Jul 2013 14:57:16 +0000 (22:57 +0800)
Usermode/Applications/dhcpclient_src/main.c

index 4d44a5d..ff326b0 100644 (file)
@@ -9,6 +9,13 @@
 #include <net.h>
 #include <acess/sys.h>
 
+enum {
+       UDP_IOCTL_GETSETLPORT = 4,
+       UDP_IOCTL_GETSETRPORT,
+       UDP_IOCTL_GETSETRMASK,
+       UDP_IOCTL_SETRADDR,
+};
+
 #define FILENAME_MAX   255
 // --- Translation functions ---
 static inline uint32_t htonl(uint32_t v)
@@ -88,7 +95,7 @@ void  SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router);
 // === CODE ===
 int main(int argc, char *argv[])
 {
-       tInterface      *ifaces = NULL, *i;
+       tInterface      *ifaces = NULL;
 
        if( argc > 2 ) {
                fprintf(stderr, "Usage: %s <interface>\n", argv[0]);
@@ -104,7 +111,7 @@ int main(int argc, char *argv[])
                Scan_Dir( &ifaces, "/Devices/ip/adapters" );
        }
 
-       for( i = ifaces; i; i = i->Next )
+       for( tInterface *i = ifaces; i; i = i->Next )
        {
                if( Start_Interface(i) < 0 ) {
                        return -1;
@@ -119,12 +126,11 @@ int main(int argc, char *argv[])
        {
                 int    maxfd;
                fd_set  fds;
-               tInterface      *p;
                int64_t timeout = 1000;
        
                maxfd = 0;
                FD_ZERO(&fds);
-               for( i = ifaces; i; i = i->Next )
+               for( tInterface *i = ifaces; i; i = i->Next )
                {
                        FD_SET(i->SocketFD, &fds);
                        if(maxfd < i->SocketFD) maxfd = i->SocketFD;
@@ -139,7 +145,7 @@ int main(int argc, char *argv[])
                _SysDebug("select() returned");
 
                // Check for changes (with magic to allow inline deletion)
-               for( p = (void*)&ifaces, i = ifaces; i; p=i,i = i->Next )
+               for( tInterface *p = (void*)&ifaces, *i = ifaces; i; p=i,i = i->Next )
                {
                        if( FD_ISSET(i->SocketFD, &fds) )
                        {
@@ -255,11 +261,11 @@ int Start_Interface(tInterface *Iface)
                fprintf(stderr, "ERROR: Unable to open '%s'\n", path); 
                return -1;
        }
-       tmp = 68; _SysIOCtl(fd, 4, &tmp);       // Local port
-       tmp = 67; _SysIOCtl(fd, 5, &tmp);       // Remote port
-       tmp = 0;  _SysIOCtl(fd, 7, &tmp);       // Remote addr mask bits - we don't care where the reply comes from
+       tmp = 68; _SysIOCtl(fd, UDP_IOCTL_GETSETLPORT, &tmp);   // Local port
+       tmp = 67; _SysIOCtl(fd, UDP_IOCTL_GETSETRPORT, &tmp);   // Remote port
+       tmp = 0;  _SysIOCtl(fd, UDP_IOCTL_GETSETRMASK, &tmp);   // Remote addr mask bits - don't care source
        addr[0] = addr[1] = addr[2] = addr[3] = 255;    // 255.255.255.255
-       _SysIOCtl(fd, 8, addr); // Remote address
+       _SysIOCtl(fd, UDP_IOCTL_SETRADDR, addr);        // Remote address
        
        return 0;
 }

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