MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ioctl

Method ioctl

source/kernel/knativesocket.cpp:528–725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526#define K_IFNAMSIZ 16
527
528U32 KNativeSocketObject::ioctl(KThread* thread, U32 request) {
529 CPU* cpu = thread->cpu;
530 if (request == 0x541b) {
531#ifdef WIN32
532 u_long value=0;
533 U32 result = ioctlsocket(this->nativeSocket, FIONREAD, &value);
534#else
535 int value=0;
536 U32 result = ::ioctl(this->nativeSocket, FIONREAD, &value);
537#endif
538 LOG_SOCK(" native socket: %x FIONREAD %d", nativeSocket, (int)value);
539 if (result != 0) {
540 std::shared_ptr< KNativeSocketObject> t = std::dynamic_pointer_cast<KNativeSocketObject>(shared_from_this());
541 return handleNativeSocketError(t, true);
542 }
543 this->error = 0;
544 thread->memory->writed(IOCTL_ARG1, value);
545 return 0;
546 } else if (request == K_SIOCGIFCONF) {
547 U32 address = IOCTL_ARG1;
548 if (!address) {
549 return -K_EFAULT;
550 }
551#ifdef WIN32
552 INTERFACE_INFO interfaces[20];
553 unsigned long bytes;
554
555 if (this->nativeSocket == SOCKET_ERROR) {
556 return -1;
557 }
558
559 if (WSAIoctl(this->nativeSocket, SIO_GET_INTERFACE_LIST, 0, 0, &interfaces, sizeof(interfaces), &bytes, 0, 0) == SOCKET_ERROR) {
560 std::shared_ptr< KNativeSocketObject> t = std::dynamic_pointer_cast<KNativeSocketObject>(shared_from_this());
561 return handleNativeSocketError(t, false);
562 }
563
564 U32 count = bytes / sizeof(INTERFACE_INFO);
565 thread->memory->writed(address, count * 40);
566 U32 buf = thread->memory->readd(address + 4);
567 for (U32 i = 0; i < count; i++) {
568 struct sockaddr_in* addr = (struct sockaddr_in*)&(interfaces[i].iiAddress);
569 if (addr->sin_family == AF_INET && (interfaces[i].iiFlags & IFF_LOOPBACK)) {
570 thread->memory->memcpy(buf + 40 * i, "lo", 3);
571 } else {
572 BString s;
573 s += "eth";
574 s += i;
575 thread->memory->memcpy(buf + 40 * i, s.c_str(), s.length() + 1);
576 }
577 thread->memory->memcpy(buf + 40 * i + 16, addr, 16); // 16 sizeof addr
578 }
579 this->error = 0;
580 return 0;
581#else
582 U32 numifs = 64;
583
584#ifdef SIOCGIFNUM
585 ::ioctl(this->nativeSocket, SIOCGIFNUM, (char*)&numifs);

Callers

nothing calls this directly

Calls 14

handleNativeSocketErrorFunction · 0.85
getAdapterAddressesFunction · 0.85
minFunction · 0.85
getAdapterAddressFunction · 0.85
kwarn_fmtFunction · 0.85
memcpyMethod · 0.80
memsetMethod · 0.80
writedMethod · 0.45
readdMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected