This commit is contained in:
源文雨 2022-11-23 15:20:21 +08:00
parent a813727662
commit 6298cfc645
2 changed files with 5 additions and 5 deletions

8
c302.c
View File

@ -22,8 +22,8 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
srand(time(NULL)); srand(time(NULL));
unsigned int i = rand() % (sizeof(urls)/sizeof(char*)); uint32_t i = rand() % (sizeof(urls)/sizeof(char*));
const struct iovec iov[3] = {{HTTP302HEAD, sizeof(HTTP302HEAD)}, {(void *)urls[i], urlsl[i]}, {"\r\n\r\n", 4}}; uint32_t len = sizeof(HTTP302HEAD) - 1 + urlsl[i];
writev(1, (const struct iovec *)&iov, 3); const struct iovec iov[3] = {{(void *)&len, sizeof(uint32_t)}, {HTTP302HEAD, sizeof(HTTP302HEAD)-1}, {(void *)urls[i], urlsl[i]}};
return 0; return writev(1, (const struct iovec *)&iov, 3) != len+sizeof(uint32_t);
} }

2
c302.h
View File

@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#define SERVER_STRING "Server: C302 by Fumiama/1.0\r\n" #define SERVER_STRING "Server: C302 by Fumiama/1.0\r\n"
#define HTTP302 "HTTP/1.0 302 Moved Temporarily\r\n" #define HTTP302 "HTTP/1.1 302 Found\r\n"
#define LOCATION "Location: " #define LOCATION "Location: "
#define HTTP302HEAD HTTP302 SERVER_STRING LOCATION #define HTTP302HEAD HTTP302 SERVER_STRING LOCATION