Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/net/tests/report_send.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / net / tests / report_send.c` 65 lines ยท 2468 bytes Raw Blame History 1 /* report_send.c -- host tool for scripts/ck_spark_report_test.sh: builds the 2 * Spark boot report frames with native/net/aienos_report.c exactly as the 3 * kernel does (net_report_frame), checks each with net_report_parse, and 4 * sends each frame's UDP payload to 127.0.0.1:PORT, last part first and 5 * every part twice, so the listener must reorder and ignore repeats. 6 * report_send PORT INFILE */ 7 #define _POSIX_C_SOURCE 200809L 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 16 #include "../aienos_net.h" 17 #include "../aienos_report.h" 18 19 int main(int argc, char **argv) 20 { 21 static char log[NET_REPORT_MAX + 1]; 22 if (argc != 3) 23 return 2; 24 FILE *f = fopen(argv[2], "rb"); 25 size_t len = f ? fread(log, 1, sizeof log, f) : 0; 26 if (f) 27 fclose(f); 28 unsigned parts = net_report_parts(len); 29 if (!parts) { 30 fprintf(stderr, "report_send: bad input length %zu\n", len); 31 return 1; 32 } 33 int s = socket(AF_INET, SOCK_DGRAM, 0); 34 struct sockaddr_in to; 35 memset(&to, 0, sizeof to); 36 to.sin_family = AF_INET; 37 to.sin_port = htons((uint16_t)atoi(argv[1])); 38 to.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 39 static const uint8_t mac[6] = {0x48, 0x11, 0x22, 0x33, 0x44, 0x55}; 40 for (int rep = 0; rep < 2; rep++) 41 for (unsigned k = 0; k < parts; k++) { 42 unsigned p = parts - 1 - k; 43 uint8_t fr[1600]; 44 size_t n = net_report_frame(NET_REPORT_TAG_SPARK, mac, 0xfedcba9876543210ull, log, len, p, fr, sizeof fr); 45 net_report_part rp; 46 net_eth_frame e; 47 net_ipv4_header ih; 48 net_udp_header uh; 49 const uint8_t *ipp, *up; 50 size_t ipn, un; 51 if (!n || net_report_parse(NET_REPORT_TAG_SPARK, fr, n, &rp) || rp.part != p || 52 net_eth_parse(fr, n, &e) || net_ipv4_parse(e.payload, e.payload_len, &ih, &ipp, &ipn) || 53 net_udp_parse(ipp, ipn, ih.source, ih.destination, &uh, &up, &un)) { 54 fprintf(stderr, "report_send: part %u does not build or parse\n", p); 55 return 1; 56 } 57 if (sendto(s, up, un, 0, (struct sockaddr *)&to, sizeof to) != (ssize_t)un) { 58 perror("sendto"); 59 return 1; 60 } 61 } 62 close(s); 63 printf("sent %u parts twice, %zu bytes\n", parts, len); 64 return 0; 65 }