diff --git a/partage/Makefile b/partage/Makefile index c019893..89b0f79 100644 --- a/partage/Makefile +++ b/partage/Makefile @@ -1,35 +1,22 @@ -CC := gcc -Wall -Wextra -Wpedantic -Werror -Iinclude -g +CC := gcc -Wall -Wextra -Wpedantic -Werror -Iinclude -std=c11 -g +all: build test-iftun + +build: + -mkdir build + +test-iftun: build/test-iftun.o build/iftun.a + $(CC) $(CFLAGS) $^ -o $@ + +build/test-iftun.o: src/test-iftun.c src/iftun.h + $(CC) $(CFLAGS) $< -c -o $@ + build/iftun.a: build/iftun.o - ar rcs $@ $^ - -build/iftun: build/iftun.a - - - -# LIBS := - -# LDFLAGS := $(LDFLAGS) $(shell pkg-config --libs $(LIBS)) -# CFLAGS := $(CFLAGS) $(shell pkg-config --cflags $(LIBS)) - -BUILD_DIR ?= build - -OUT := $(notdir $(shell pwd)) - -SRC := $(wildcard src/*.c) -OBJS := $(patsubst src/%.c,$(BUILD_DIR)/%.o,$(SRC)) -DEPS := $(wildcard $(BUILD_DIR)/*.d) - - -$(BUILD_DIR)/$(OUT): $(OBJS) - $(CC) $(LDFLAGS) -o $@ $^ - - --include $(DEPS) -$(BUILD_DIR)/%.o: src/%.c - $(CC) $(CFLAGS) -MP -MD $< -c -o $@ + ar rcs $@ $< +build/iftun.o: src/iftun.c src/iftun.h + $(CC) $(CFLAGS) $< -c -o $@ clean: -rm -f $(BUILD_DIR)/*.o diff --git a/partage/src/iftun.c b/partage/src/iftun.c index 63105ba..25b3008 100644 --- a/partage/src/iftun.c +++ b/partage/src/iftun.c @@ -1,5 +1,21 @@ #include "iftun.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + int tun_alloc(char *dev) { int fd = open("/dev/net/tun", O_RDWR); @@ -24,3 +40,14 @@ int tun_alloc(char *dev) { strcpy(dev, ifr.ifr_name); return fd; } + + +int copy(int src, int dest) { + char buf[1024]; + int n = 0; + + while (1) { + n = read(src, buf, 1024); + write(dest, buf, n); + } +} diff --git a/partage/src/iftun.h b/partage/src/iftun.h index 7d3732b..a9139b0 100644 --- a/partage/src/iftun.h +++ b/partage/src/iftun.h @@ -3,6 +3,7 @@ int tun_alloc(char *dev); +int copy(int src, int dest); #endif diff --git a/partage/src/test-iftun.c b/partage/src/test-iftun.c new file mode 100644 index 0000000..a2ec7ef --- /dev/null +++ b/partage/src/test-iftun.c @@ -0,0 +1,16 @@ +#include "iftun.h" + +#include + + +int main(int argc, char *argv[argc]) { + if (argc != 2) { + fprintf(stderr, "Utilisation : %s interface\n", argv[0]); + return 1; + } + int tun = tun_alloc(argv[1]); + printf("Configurez l’interface puis appuyez sur une touche.\n"); + getchar(); + copy(tun, 1); + return 0; +} diff --git a/partage/src/tunalloc.c b/partage/src/tunalloc.c index b3a38e9..ba20e2b 100644 --- a/partage/src/tunalloc.c +++ b/partage/src/tunalloc.c @@ -17,17 +17,6 @@ #include -int copy(int src, int dest) { - char buf[1024]; - int n = 0; - - while (1) { - n = read(src, buf, 1024); - write(dest, buf, n); - } -} - - void ext_out() { struct addrinfo hints = { .ai_family = AF_UNSPEC, @@ -84,7 +73,6 @@ int main(int argc, char *argv[argc]){ int tun = tun_alloc(argv[1]); /* printf("Configure %s puis appuie sur un touche…\n", argv[1]); */ /* getchar(); */ - system("./configure-tun.sh"); /* copy(tun, 1); */ /* ext_out(); */ return 0;