non
This commit is contained in:
parent
c5108dcccf
commit
33cdb682d6
@ -1,32 +1,40 @@
|
|||||||
CC := gcc -Wall -Wextra -Wpedantic -Werror -Iinclude -g
|
CC := gcc -Wall -Wextra -Wpedantic -Werror -Wshadow=local -Iinclude -Isrc -g -std=c11
|
||||||
|
|
||||||
LIBS :=
|
# pkg-config
|
||||||
|
# LIBS :=
|
||||||
LDFLAGS := $(LDFLAGS) $(shell pkg-config --libs $(LIBS))
|
# LDFLAGS := $(LDFLAGS) $(shell pkg-config --libs $(LIBS))
|
||||||
CFLAGS := $(CFLAGS) $(shell pkg-config --cflags $(LIBS))
|
# CFLAGS := $(CFLAGS) $(shell pkg-config --cflags $(LIBS))
|
||||||
|
|
||||||
CFLAGS := $(CFLAGS) -D_POSIX_C_SOURCE=200809L
|
CFLAGS := $(CFLAGS) -D_POSIX_C_SOURCE=200809L
|
||||||
|
|
||||||
BUILD_DIR ?= build
|
|
||||||
|
|
||||||
OUT := $(notdir $(shell pwd))
|
OUT := $(notdir $(shell pwd))
|
||||||
|
|
||||||
SRC := $(wildcard src/*.c)
|
SRC := $(wildcard src/*.c)
|
||||||
OBJS := $(patsubst src/%.c,$(BUILD_DIR)/%.o,$(SRC))
|
TEST := $(wildcard test/*.c)
|
||||||
DEPS := $(wildcard $(BUILD_DIR)/*.d)
|
OBJS := $(patsubst src/%.c,build/%.o,$(SRC))
|
||||||
|
TEST_OBJS := $(patsubst test/%.c,build/test-%.o,$(TEST))
|
||||||
|
DEPS := $(wildcard build/*.d)
|
||||||
|
|
||||||
|
|
||||||
all: ext-in ext-out test-iftun tunnel64d
|
all: ext-in ext-out test-iftun tunnel64d
|
||||||
|
|
||||||
$(OUT): $(OBJS)
|
# $(OUT): $(OBJS)
|
||||||
|
$(OUT):
|
||||||
$(CC) $(LDFLAGS) -o $@ $^
|
$(CC) $(LDFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
test-ext-in: build/test-ext-in.o build/extremite.o build/iftun.o
|
||||||
|
test-ext-out: build/test-ext-out.o build/extremite.o build/iftun.o
|
||||||
|
test-iftun: build/test-iftun.o build/iftun.o
|
||||||
|
|
||||||
|
tunnel64d: build/tunnel64d.o build/extremite.o build/iftun.o
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
$(BUILD_DIR)/%.o: src/%.c
|
build/test-%.o: test/%.c
|
||||||
|
$(CC) $(CFLAGS) -MP -MD $< -c -o $@
|
||||||
|
build/%.o: src/%.c
|
||||||
$(CC) $(CFLAGS) -MP -MD $< -c -o $@
|
$(CC) $(CFLAGS) -MP -MD $< -c -o $@
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f $(BUILD_DIR)/*.o
|
-rm -f build/*.o
|
||||||
-rm -f $(BUILD_DIR)/*.d
|
-rm -f build/*.d
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include "extremite.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/if.h>
|
#include <linux/if.h>
|
||||||
@ -19,7 +21,7 @@
|
|||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
|
|
||||||
|
|
||||||
void ext_out(int port, int out) {
|
int ext_out(int port) {
|
||||||
int server = socket(AF_INET6, SOCK_STREAM, 0);
|
int server = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
if (server == -1) {
|
if (server == -1) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
@ -40,7 +42,7 @@ void ext_out(int port, int out) {
|
|||||||
inet_ntop(AF_INET6, &(server_addr.sin6_addr), server_addr_pretty, sizeof server_addr_pretty);
|
inet_ntop(AF_INET6, &(server_addr.sin6_addr), server_addr_pretty, sizeof server_addr_pretty);
|
||||||
printf("Écoute sur : %s\n", server_addr_pretty);
|
printf("Écoute sur : %s\n", server_addr_pretty);
|
||||||
|
|
||||||
if (listen(server, SOMAXCONN) == -1) {
|
if (listen(server, 1) == -1) {
|
||||||
perror("listen");
|
perror("listen");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -49,31 +51,35 @@ void ext_out(int port, int out) {
|
|||||||
socklen_t client_addr_len;
|
socklen_t client_addr_len;
|
||||||
puts("Attente d’un client.");
|
puts("Attente d’un client.");
|
||||||
int client = accept(server, (struct sockaddr *) &client_addr, &client_addr_len);
|
int client = accept(server, (struct sockaddr *) &client_addr, &client_addr_len);
|
||||||
|
|
||||||
|
close(server);
|
||||||
|
|
||||||
char client_addr_pretty[INET6_ADDRSTRLEN] = "";
|
char client_addr_pretty[INET6_ADDRSTRLEN] = "";
|
||||||
inet_ntop(AF_INET6, &(client_addr.sin6_addr), client_addr_pretty, sizeof client_addr_pretty);
|
inet_ntop(AF_INET6, &(client_addr.sin6_addr), client_addr_pretty, sizeof client_addr_pretty);
|
||||||
printf("Client connecté : %s\n", client_addr_pretty);
|
printf("Client connecté : %s\n", client_addr_pretty);
|
||||||
|
|
||||||
char buf[BUFSIZE];
|
return client;
|
||||||
ssize_t n;
|
|
||||||
while (1) {
|
|
||||||
n = read(client, buf, sizeof buf);
|
|
||||||
if (n == -1) {
|
|
||||||
perror("read");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
n = write(out, buf, n);
|
|
||||||
if (n == -1) {
|
|
||||||
perror("write");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(client);
|
/* char buf[BUFSIZE]; */
|
||||||
close(server);
|
/* ssize_t n; */
|
||||||
|
/* while (1) { */
|
||||||
|
/* n = read(client, buf, sizeof buf); */
|
||||||
|
/* if (n == -1) { */
|
||||||
|
/* perror("read"); */
|
||||||
|
/* exit(1); */
|
||||||
|
/* } */
|
||||||
|
/* n = write(out, buf, n); */
|
||||||
|
/* if (n == -1) { */
|
||||||
|
/* perror("write"); */
|
||||||
|
/* exit(1); */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* close(client); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ext_in(const char addr[], int port, int in) {
|
int ext_in(const char addr[], int port) {
|
||||||
int s = socket(AF_INET6, SOCK_STREAM, 0);
|
int s = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
if (s == -1) {
|
if (s == -1) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
@ -94,32 +100,37 @@ void ext_in(const char addr[], int port, int in) {
|
|||||||
inet_ntop(AF_INET6, &(sa.sin6_addr), addr_pretty, sizeof addr_pretty);
|
inet_ntop(AF_INET6, &(sa.sin6_addr), addr_pretty, sizeof addr_pretty);
|
||||||
printf("Connecté à : %s\n", addr_pretty);
|
printf("Connecté à : %s\n", addr_pretty);
|
||||||
|
|
||||||
char buf[BUFSIZE];
|
return s;
|
||||||
ssize_t n;
|
|
||||||
while (1) {
|
|
||||||
n = read(in, buf, sizeof buf);
|
|
||||||
if (n == -1) {
|
|
||||||
perror("read");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
n = write(s, buf, n);
|
|
||||||
if (n == -1) {
|
|
||||||
perror("write");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(s);
|
/* char buf[BUFSIZE]; */
|
||||||
|
/* ssize_t n; */
|
||||||
|
/* while (1) { */
|
||||||
|
/* n = read(in, buf, sizeof buf); */
|
||||||
|
/* if (n == -1) { */
|
||||||
|
/* perror("read"); */
|
||||||
|
/* exit(1); */
|
||||||
|
/* } */
|
||||||
|
/* n = write(s, buf, n); */
|
||||||
|
/* if (n == -1) { */
|
||||||
|
/* perror("write"); */
|
||||||
|
/* exit(1); */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* close(s); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ext_bidir(const char addr[], int port, int in, int out) {
|
void ext_bidir(const char addr[], int port, int in, int out) {
|
||||||
|
(void) in;
|
||||||
|
(void) out;
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
ext_in(addr, port, in);
|
ext_in(addr, port);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ext_out(port, out);
|
ext_out(port);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#define EXTREMITE_H
|
#define EXTREMITE_H
|
||||||
|
|
||||||
|
|
||||||
void ext_out(int port, int out);
|
int ext_out(int port);
|
||||||
void ext_in(const char addr[], int port, int in);
|
int ext_in(const char addr[], int port);
|
||||||
void ext_bidir(const char addr[], int port, int in, int out);
|
void ext_bidir(const char addr[], int port, int in, int out);
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@ int main(int argc, char *argv[argc]) {
|
|||||||
fprintf(stderr, "Erreur lors de l’exécution du script de configuration de l’interface.\n");
|
fprintf(stderr, "Erreur lors de l’exécution du script de configuration de l’interface.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ext_in(argv[1], port, tun);
|
|
||||||
|
int ext = ext_in(argv[1], port);
|
||||||
|
copy(tun, ext);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -26,7 +26,9 @@ int main(int argc, char *argv[argc]) {
|
|||||||
fprintf(stderr, "Erreur lors de l’exécution du script de configuration de l’interface.\n");
|
fprintf(stderr, "Erreur lors de l’exécution du script de configuration de l’interface.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ext_out(port, tun);
|
|
||||||
|
int ext = ext_out(port);
|
||||||
|
copy(ext, tun);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user