|
// Copyright 2023 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include <gccore.h>
|
|
#include <network.h>
|
|
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
static vu32* const CONSOLE_TYPE = (u32*)0x8000002C;
|
|
|
|
void *initialise()
|
|
{
|
|
VIDEO_Init();
|
|
|
|
GXRModeObj *rmode = VIDEO_GetPreferredMode(NULL);
|
|
void* framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
|
console_init(
|
|
framebuffer, 20, 20,
|
|
rmode->fbWidth, rmode->xfbHeight,
|
|
rmode->fbWidth * VI_DISPLAY_PIX_SZ
|
|
);
|
|
|
|
VIDEO_Configure(rmode);
|
|
VIDEO_SetNextFramebuffer(framebuffer);
|
|
VIDEO_SetBlack(false);
|
|
VIDEO_Flush();
|
|
VIDEO_WaitVSync();
|
|
if (rmode->viTVMode & VI_NON_INTERLACE)
|
|
VIDEO_WaitVSync();
|
|
|
|
return framebuffer;
|
|
}
|
|
|
|
void net_tcp_overflow(const char* addr, int port)
|
|
{
|
|
#ifdef HW_DOL
|
|
char localip[16] = {0};
|
|
char gateway[16] = {0};
|
|
char netmask[16] = {0};
|
|
|
|
if (if_config(localip, netmask, gateway, TRUE, 20) < 0) {
|
|
printf("GC network init failed!\n");
|
|
return;
|
|
}
|
|
printf("ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
|
|
#elif HW_RVL
|
|
net_init();
|
|
printf("Wii network init succeeded!\n");
|
|
#else
|
|
printf("Unsupported hardware!\n");
|
|
#endif
|
|
|
|
sockaddr_in in;
|
|
sockaddr* in_addr = (sockaddr*)∈
|
|
socklen_t in_len = sizeof(in);
|
|
in.sin_family = AF_INET;
|
|
in.sin_port = htons(port);
|
|
inet_aton(addr, &in.sin_addr);
|
|
|
|
int fd = net_socket(AF_INET, SOCK_STREAM, 0);
|
|
int res = net_connect(fd, in_addr, in_len);
|
|
if (res != 0)
|
|
{
|
|
printf("connect (fd=%d) to %s:%d = %d\n", fd, addr, port, res);
|
|
return;
|
|
}
|
|
|
|
constexpr u32 SIZE = 256;
|
|
constexpr u32 END = 0xFFFFFFFFul / SIZE + 2;
|
|
constexpr u32 UPDATE = 0x1000;
|
|
for (u32 i = 0; i < END; i += 1)
|
|
{
|
|
std::string data(SIZE, 'a' + i % 26);
|
|
net_send(fd, data.c_str(), data.size(), 0);
|
|
if ((i % UPDATE) == 0)
|
|
{
|
|
printf(" - Count: %08x\r", i);
|
|
}
|
|
}
|
|
printf("\n");
|
|
|
|
net_close(fd);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
initialise();
|
|
|
|
const char* addr = "192.168.1.17";
|
|
const int port = 8000;
|
|
|
|
printf("\n\n# Net overflow (CONSOLE_TYPE=%08x)\n\n", (u32)CONSOLE_TYPE);
|
|
printf("Please run Wireshark on the target %s:%d\n", addr, port);
|
|
net_tcp_overflow(addr, port);
|
|
|
|
printf("\nDone!\n");
|
|
while (1);
|
|
|
|
return 0;
|
|
}
|