diff options
author | Ren Kararou <[email protected]> | 2024-12-26 01:50:22 -0600 |
---|---|---|
committer | Ren Kararou <[email protected]> | 2024-12-26 01:50:22 -0600 |
commit | 746cd14f273a96c0348f4e64f9b347ce49a93f45 (patch) | |
tree | 813aee86d27bd8ec0b4416ea6cd5f22603666a89 | |
parent | 6b0cf95d75935308e142232fe646d56d0f9d418c (diff) | |
download | nbtpd-746cd14f273a96c0348f4e64f9b347ce49a93f45.tar.gz nbtpd-746cd14f273a96c0348f4e64f9b347ce49a93f45.tar.bz2 nbtpd-746cd14f273a96c0348f4e64f9b347ce49a93f45.zip |
add ci; update packet structs; add makefile
-rw-r--r-- | .builds/arch.yml | 14 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | inc/packet.h | 12 | ||||
-rw-r--r-- | makefile | 19 | ||||
-rw-r--r-- | src/main.c | 18 | ||||
-rw-r--r-- | src/netascii.c | 2 | ||||
-rw-r--r-- | src/packet.c | 24 |
7 files changed, 82 insertions, 8 deletions
diff --git a/.builds/arch.yml b/.builds/arch.yml new file mode 100644 index 0000000..1e44b51 --- /dev/null +++ b/.builds/arch.yml @@ -0,0 +1,14 @@ +image: archlinux +packages: + - base-devel + - clang +sources: + - https://git.sr.ht/~spicywolf/nbtpd +triggers: + - action: email + condition: always + to: ~spicywolf/[email protected] +tasks: + - build: | + cd nbtpd + make diff --git a/.gitignore b/.gitignore index 50e3436..c98082d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ bin/ *.o *.so nbtpd +a.out diff --git a/inc/packet.h b/inc/packet.h index d5f341c..a236f74 100644 --- a/inc/packet.h +++ b/inc/packet.h @@ -23,29 +23,29 @@ typedef enum { } nbt_tftp_ecode; typedef struct { - nbt_tftp_opcode opcode; + uint16_t opcode; char* filename; char* mode; } nbt_tftp_packet_rq; typedef struct { - nbt_tftp_opcode opcode; + uint16_t opcode; uint16_t block_num; char* data; } nbt_tftp_packet_data; typedef struct { - nbt_tftp_opcode opcode; + uint16_t opcode; uint16_t block_num; } nbt_tftp_packet_ack; typedef struct { - nbt_tftp_opcode opcode; - nbt_tftp_ecode err; + uint16_t opcode; + uint16_t err; char* emsg; } nbt_tftp_packet_error; - +char* nbt_tftp_error_to_message(nbt_tftp_ecode error); #endif diff --git a/makefile b/makefile index e69de29..f5a993a 100644 --- a/makefile +++ b/makefile @@ -0,0 +1,19 @@ +CC:=clang +CFLAGS:=-O3 -funroll-loops +LDFLAGS:=-flto + +INCLUDES=-Iinc/ + +OBJECTS=bin/obj/main.o bin/obj/packet.o bin/obj/netascii.o + +bin/nbtpd: $(OBJECTS) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/nbtpd $^ + +bin/obj/%.o: src/%.c + @if [ ! -d "./bin/obj" ]; then mkdir -p ./bin/obj; fi + $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $^ + +.PHONY: clean +clean: + rm -rf ./bin + diff --git a/src/main.c b/src/main.c index 15d3008..159b0b5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,20 @@ +#include <stdint.h> +#include <stdio.h> +#include <sys/socket.h> +#include <pthread.h> -int main() { +#include "packet.h" +#include "netascii.h" + +int main(int argc, char** argv) { + //TODO: use getopt() to parse args + int s = socket(AF_INET, SOCK_DGRAM, 0); + if (s <= 0) { + fprintf(stderr, "error: socket cannot be created.\n"); + return -1; + } + //TODO: threading! + //TODO: daemonize! + fprintf(stderr, "error: routine completed successfully.\n"); return 0; } diff --git a/src/netascii.c b/src/netascii.c index 606d257..2180093 100644 --- a/src/netascii.c +++ b/src/netascii.c @@ -1,6 +1,6 @@ #include <stdint.h> -#include "inc/netascii.h" +#include "netascii.h" uint8_t is_netascii_char(char c) { static const uint64_t LUT[4] = diff --git a/src/packet.c b/src/packet.c new file mode 100644 index 0000000..8f7a7e6 --- /dev/null +++ b/src/packet.c @@ -0,0 +1,24 @@ +#include "packet.h" + +char* nbt_tftp_error_to_message(nbt_tftp_ecode error) { + switch (error) { + case 0: + return "ERROR"; + case 1: + return "File not Found"; + case 2: + return "Access violation"; + case 3: + return "Disk full or allocation exceeded"; + case 4: + return "Illegal TFTP operation"; + case 5: + return "Unknown Transfer ID"; + case 6: + return "File already exists"; + case 7: + return "No such user"; + } + return "UNKNOWN ERROR"; +} + |