mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-06 09:50:28 +00:00
Removed debugging statements from the NT implementation of ioctl
This commit is contained in:
parent
b3b85c2f96
commit
c60de329a2
2 changed files with 7 additions and 37 deletions
|
@ -33,9 +33,6 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
//#include "libc/nt/windows.h" /* Needed for WideCharToMultiByte */
|
//#include "libc/nt/windows.h" /* Needed for WideCharToMultiByte */
|
||||||
|
|
||||||
#include "libc/stdio/stdio.h"
|
|
||||||
#define PRINTF weaken(printf)
|
|
||||||
|
|
||||||
/* Maximum number of unicast addresses handled for each interface */
|
/* Maximum number of unicast addresses handled for each interface */
|
||||||
#define MAX_UNICAST_ADDR 32
|
#define MAX_UNICAST_ADDR 32
|
||||||
#define MAX_NAME_CLASH ((int)('z'-'a')) /* Allow a..z */
|
#define MAX_NAME_CLASH ((int)('z'-'a')) /* Allow a..z */
|
||||||
|
@ -100,16 +97,13 @@ struct HostAdapterInfoNode *appendHostInfo(
|
||||||
struct sockaddr_in tempAddr;
|
struct sockaddr_in tempAddr;
|
||||||
int attemptNum;
|
int attemptNum;
|
||||||
|
|
||||||
PRINTF("FABDEBUG> \t\t\tappendHostInfo:\n");
|
|
||||||
node = weaken(calloc)(1, sizeof(*node));
|
node = weaken(calloc)(1, sizeof(*node));
|
||||||
if (!node) {
|
if (!node) {
|
||||||
PRINTF("FABDEBUG> \t\t\tMALLOC FAILED\n");
|
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(node->name, baseName, IFNAMSIZ);
|
memcpy(node->name, baseName, IFNAMSIZ);
|
||||||
PRINTF("FABDEBUG> \t\t\tnodeAllocated, name=%s\n", node->name);
|
|
||||||
|
|
||||||
/* Are there more than a single unicast address ? */
|
/* Are there more than a single unicast address ? */
|
||||||
if (count > 0 || ((*ptrUA)->Next != NULL)) {
|
if (count > 0 || ((*ptrUA)->Next != NULL)) {
|
||||||
|
@ -122,11 +116,9 @@ struct HostAdapterInfoNode *appendHostInfo(
|
||||||
node->name[nameLen-2] = ':';
|
node->name[nameLen-2] = ':';
|
||||||
node->name[nameLen-1] = '0'+count;
|
node->name[nameLen-1] = '0'+count;
|
||||||
node->name[nameLen] = '\0';
|
node->name[nameLen] = '\0';
|
||||||
PRINTF("FABDEBUG> \t\t\tComputing multi-unicast name: '%s'\n", node->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is there a name clash with other interfaces? */
|
/* Is there a name clash with other interfaces? */
|
||||||
PRINTF("FABDEBUG> \t\t\tFinding name clashes\n");
|
|
||||||
for (attemptNum=0; attemptNum < MAX_NAME_CLASH; ++attemptNum) {
|
for (attemptNum=0; attemptNum < MAX_NAME_CLASH; ++attemptNum) {
|
||||||
temp = findAdapterByName(node->name);
|
temp = findAdapterByName(node->name);
|
||||||
if (!temp) {
|
if (!temp) {
|
||||||
|
@ -140,7 +132,6 @@ struct HostAdapterInfoNode *appendHostInfo(
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t pos = strlen(node->name);
|
size_t pos = strlen(node->name);
|
||||||
PRINTF("FABDEBUG> \t\t\t** NAME CLASH name=%s, attemptNum=%d\n", temp->name, attemptNum);
|
|
||||||
node->name[pos] = 'a' + attemptNum;
|
node->name[pos] = 'a' + attemptNum;
|
||||||
node->name[pos+1] = '\0';
|
node->name[pos+1] = '\0';
|
||||||
/* Try again */
|
/* Try again */
|
||||||
|
@ -148,12 +139,10 @@ struct HostAdapterInfoNode *appendHostInfo(
|
||||||
}
|
}
|
||||||
if (attemptNum == MAX_NAME_CLASH) {
|
if (attemptNum == MAX_NAME_CLASH) {
|
||||||
/* Cannot resolve the conflict */
|
/* Cannot resolve the conflict */
|
||||||
PRINTF("FABDEBUG> \t\t\tReached max clash attempts...\n");
|
|
||||||
weaken(free)(node);
|
weaken(free)(node);
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PRINTF("FABDEBUG> \t\t\tappendHostInfo: computed name='%s'\n", node->name);
|
|
||||||
|
|
||||||
/* Finally we got a unique short and friendly name */
|
/* Finally we got a unique short and friendly name */
|
||||||
node->unicast = *((*ptrUA)->Address.lpSockaddr);
|
node->unicast = *((*ptrUA)->Address.lpSockaddr);
|
||||||
|
@ -260,7 +249,6 @@ static int createHostInfo(NtIpAdapterAddresses *firstAdapter) {
|
||||||
if (baseName[i] == ' ') baseName[i] = '_';
|
if (baseName[i] == ' ') baseName[i] = '_';
|
||||||
if (!baseName[i]) break;
|
if (!baseName[i]) break;
|
||||||
}
|
}
|
||||||
PRINTF("FABDEBUG> \tcreateHostInfo: processing Win interface with baseName='%s'\n", baseName);
|
|
||||||
for (count = 0, ua = aa->FirstUnicastAddress, ap = aa->FirstPrefix;
|
for (count = 0, ua = aa->FirstUnicastAddress, ap = aa->FirstPrefix;
|
||||||
(ua != NULL) && (count < MAX_UNICAST_ADDR);
|
(ua != NULL) && (count < MAX_UNICAST_ADDR);
|
||||||
++count) {
|
++count) {
|
||||||
|
@ -269,7 +257,6 @@ static int createHostInfo(NtIpAdapterAddresses *firstAdapter) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (!__hostInfo) __hostInfo = node;
|
if (!__hostInfo) __hostInfo = node;
|
||||||
PRINTF("FABDEBUG> \t\tcreateHostInfo: added interface='%s'\n", node->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: do we need to process the remaining adapter prefix?
|
/* Note: do we need to process the remaining adapter prefix?
|
||||||
|
@ -288,7 +275,6 @@ err:
|
||||||
static int readAdapterAddresses(void) {
|
static int readAdapterAddresses(void) {
|
||||||
uint32_t size, rc;
|
uint32_t size, rc;
|
||||||
NtIpAdapterAddresses * aa = NULL;
|
NtIpAdapterAddresses * aa = NULL;
|
||||||
PRINTF("FABDEBUG> _readAdapterAddresses:\n");
|
|
||||||
|
|
||||||
assert(weaken(GetAdaptersAddresses));
|
assert(weaken(GetAdaptersAddresses));
|
||||||
|
|
||||||
|
@ -301,15 +287,12 @@ static int readAdapterAddresses(void) {
|
||||||
NULL, /* Ptr */
|
NULL, /* Ptr */
|
||||||
&size);
|
&size);
|
||||||
if (rc != kNtErrorBufferOverflow) {
|
if (rc != kNtErrorBufferOverflow) {
|
||||||
PRINTF("FABDEBUG> \tGetAdaptersAddresses failed with error %d\n", WSAGetLastError());
|
|
||||||
ebadf();
|
ebadf();
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
PRINTF("FABDEBUG> \tsize required=%lu, allocating...\n", size);
|
|
||||||
|
|
||||||
aa = (NtIpAdapterAddresses *)weaken(malloc)(size);
|
aa = (NtIpAdapterAddresses *)weaken(malloc)(size);
|
||||||
if (!aa) {
|
if (!aa) {
|
||||||
PRINTF("FABDEBUG> \tmalloc failed\n");
|
|
||||||
enomem();
|
enomem();
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -322,26 +305,13 @@ static int readAdapterAddresses(void) {
|
||||||
aa,
|
aa,
|
||||||
&size);
|
&size);
|
||||||
if (rc != kNtErrorSuccess) {
|
if (rc != kNtErrorSuccess) {
|
||||||
PRINTF("FABDEBUG> \tGetAdaptersAddresses failed %d\n", WSAGetLastError());
|
|
||||||
efault();
|
efault();
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (createHostInfo(aa) == -1) {
|
if (createHostInfo(aa) == -1) {
|
||||||
PRINTF("FABDEBUG> \tFailed to createHostInfo\n");
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("FABDEBUG> \tDone reading.\n");
|
|
||||||
{
|
|
||||||
struct HostAdapterInfoNode *foo = __hostInfo;
|
|
||||||
while (foo) {
|
|
||||||
PRINTF("FABDEBUG>>>>>>> %s - %s\n", foo->name,
|
|
||||||
weaken(inet_ntoa)(
|
|
||||||
((struct sockaddr_in *)(&foo->unicast))->sin_addr));
|
|
||||||
foo = foo->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
weaken(free)(aa);
|
weaken(free)(aa);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -371,11 +341,6 @@ textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) {
|
||||||
ptr++, node = node->next) {
|
ptr++, node = node->next) {
|
||||||
memcpy(ptr->ifr_name, node->name, IFNAMSIZ);
|
memcpy(ptr->ifr_name, node->name, IFNAMSIZ);
|
||||||
memcpy(&ptr->ifr_addr, &node->unicast, sizeof(struct sockaddr));
|
memcpy(&ptr->ifr_addr, &node->unicast, sizeof(struct sockaddr));
|
||||||
|
|
||||||
PRINTF("FABDEBUG> Adapter name = '%s'. IP=%s\n", ptr->ifr_name,
|
|
||||||
weaken(inet_ntoa)(((struct sockaddr_in *)(&ptr->ifr_addr))->sin_addr));
|
|
||||||
PRINTF("FABDEBUG> '%s'. BR=%s\n", ptr->ifr_name,
|
|
||||||
weaken(inet_ntoa)(((struct sockaddr_in *)&node->broadcast)->sin_addr));
|
|
||||||
}
|
}
|
||||||
ifc->ifc_len = (char *)ptr - ifc->ifc_buf;
|
ifc->ifc_len = (char *)ptr - ifc->ifc_buf;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
* The ifc_len is an input/output parameter: set it to the total size of
|
* The ifc_len is an input/output parameter: set it to the total size of
|
||||||
* the ifcu_buf (ifcu_req) buffer on input.
|
* the ifcu_buf (ifcu_req) buffer on input.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ioctl_default(int, uint64_t, void *) hidden;
|
int ioctl_default(int, uint64_t, void *) hidden;
|
||||||
int ioctl_siocgifconf_nt(int, struct ifconf *) hidden;
|
int ioctl_siocgifconf_nt(int, struct ifconf *) hidden;
|
||||||
int ioctl_siocgifaddr_nt(int, struct ifreq *) hidden;
|
int ioctl_siocgifaddr_nt(int, struct ifreq *) hidden;
|
||||||
|
@ -159,7 +158,13 @@ int ioctl_siocgifdstaddr(int fd, void *ifr) {
|
||||||
return ioctl_siocgifaddr_sysv(fd, SIOCGIFDSTADDR, (struct ifreq *)ifr);
|
return ioctl_siocgifaddr_sysv(fd, SIOCGIFDSTADDR, (struct ifreq *)ifr);
|
||||||
} else {
|
} else {
|
||||||
return enotsup();
|
return enotsup();
|
||||||
//return ioctl_siocgifbrdaddr_nt(fd, ifc);
|
/* Not supported - TODO: Find out how to retrieve the destination
|
||||||
|
* address of a PPP from the interface list returned by the
|
||||||
|
* GetAdaptersAddresses function
|
||||||
|
*
|
||||||
|
return ioctl_siocgifbrdaddr_nt(fd, ifc);
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue