X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fdhcpclient_src%2Fmain.c;h=858a61d100f01bd79f9ee0b5ca2ea54124361550;hb=e5deb25fdad3bf008df40679082abdc999d5d1d9;hp=73e85d8ef5c731b41f6df35fc7258a3e0cf365d8;hpb=b0da731b2d89b9dd58de2c98eaf6218a41a21920;p=tpg%2Facess2.git diff --git a/Usermode/Applications/dhcpclient_src/main.c b/Usermode/Applications/dhcpclient_src/main.c index 73e85d8e..858a61d1 100644 --- a/Usermode/Applications/dhcpclient_src/main.c +++ b/Usermode/Applications/dhcpclient_src/main.c @@ -90,7 +90,6 @@ int main(int argc, char *argv[]) { tInterface *ifaces = NULL, *i; - // TODO: Scan /Devices and search for network adapters if( argc > 2 ) { fprintf(stderr, "Usage: %s \n", argv[0]); return -1; @@ -131,9 +130,9 @@ int main(int argc, char *argv[]) if(maxfd < i->SocketFD) maxfd = i->SocketFD; } - if( select(maxfd+1, &fds, NULL, NULL, &timeout) < 0 ) + if( _SysSelect(maxfd+1, &fds, NULL, NULL, &timeout, 0) < 0 ) { - // TODO: Check error result + perror("_SysSelect returned error"); return -1; } @@ -207,11 +206,14 @@ int Start_Interface(tInterface *Iface) sprintf(path, "/Devices/ip/adapters/%s", Iface->Adapter); fd = _SysOpen(path, 0); if(fd == -1) { + perror("Opening adapter"); _SysDebug("Unable to open adapter %s", path); return -1; } - _SysIOCtl(fd, 4, Iface->HWAddr); - // TODO: Check if ioctl() failed + if( _SysIOCtl(fd, 4, Iface->HWAddr) ) { + perror("Getting MAC address"); + return -1; + } _SysClose(fd); } @@ -221,7 +223,15 @@ int Start_Interface(tInterface *Iface) fprintf(stderr, "ERROR: Unable to open '/Devices/ip'\n"); return -1; } - Iface->Num = _SysIOCtl(fd, 4, (void*)Iface->Adapter); // Create interface + struct { + const char *Device; + const char *Name; + int Type; + } ifinfo; + ifinfo.Device = Iface->Adapter; + ifinfo.Name = ""; + ifinfo.Type = 4; + Iface->Num = _SysIOCtl(fd, 4, &ifinfo); // Create interface if( Iface->Num == -1 ) { fprintf(stderr, "ERROR: Unable to create new interface\n"); return -1; @@ -235,7 +245,6 @@ int Start_Interface(tInterface *Iface) fprintf(stderr, "ERROR: Unable to open '%s'\n", path); return -1; } - tmp = 4; _SysIOCtl(fd, 4, &tmp); // Set to IPv4 _SysIOCtl(fd, 6, addr); // Set address to 0.0.0.0 tmp = 0; _SysIOCtl(fd, 7, &tmp); // Set subnet mask to 0 @@ -248,7 +257,7 @@ int Start_Interface(tInterface *Iface) } 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 = 0; _SysIOCtl(fd, 7, &tmp); // Remote addr mask bits - we don't care where the reply comes from addr[0] = addr[1] = addr[2] = addr[3] = 255; // 255.255.255.255 _SysIOCtl(fd, 8, addr); // Remote address