From f24472df74bd3c88f323b3b524ad9ce2bf7c8b0a Mon Sep 17 00:00:00 2001 From: g_robert Date: Fri, 18 Mar 2022 09:43:49 +0100 Subject: [PATCH] =?UTF-8?q?V1=20impl=C3=A9ment=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/mictcp.h | 2 +- src/mictcp.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/mictcp.h b/include/mictcp.h index 36a4d38..4a87e4d 100644 --- a/include/mictcp.h +++ b/include/mictcp.h @@ -21,7 +21,7 @@ */ typedef enum protocol_state { - IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, ESTABLISHED, CLOSING + IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, CONNECTED, CLOSING } protocol_state; /* diff --git a/src/mictcp.c b/src/mictcp.c index b94107c..8afcb7c 100644 --- a/src/mictcp.c +++ b/src/mictcp.c @@ -5,13 +5,16 @@ * Permet de créer un socket entre l’application et MIC-TCP * Retourne le descripteur du socket ou bien -1 en cas d'erreur */ + mic_tcp_sock sock; + mic_tcp_pdu pdu; + int mic_tcp_socket(start_mode sm) { - int result = -1; + int result=-1; printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); result = initialize_components(sm); /* Appel obligatoire */ + sock.fd=result; set_loss_rate(0); - return result; } @@ -21,8 +24,14 @@ int mic_tcp_socket(start_mode sm) */ int mic_tcp_bind(int socket, mic_tcp_sock_addr addr) { - printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); - return -1; + printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); + if(sock.fd == socket){ + sock.addr=addr; + sock.state= IDLE; + return 0; + }else { + return -1; + } } /* @@ -32,7 +41,8 @@ int mic_tcp_bind(int socket, mic_tcp_sock_addr addr) int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr) { printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); - return -1; + sock.state=CONNECTED; + return 0; } /* @@ -42,7 +52,8 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr) int mic_tcp_connect(int socket, mic_tcp_sock_addr addr) { printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); - return -1; + sock.state=CONNECTED; + return 0; } /* @@ -52,7 +63,16 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr) int mic_tcp_send (int mic_sock, char* mesg, int mesg_size) { printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); - return -1; + + pdu.header.syn = 0; + pdu.header.ack = 0; + pdu.header.fin = 0; + + pdu.payload.data = mesg; + pdu.payload.size=mesg_size; + + + return IP_send(pdu,sock.addr); } /* @@ -64,7 +84,9 @@ int mic_tcp_send (int mic_sock, char* mesg, int mesg_size) int mic_tcp_recv (int socket, char* mesg, int max_mesg_size) { printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); - return -1; + pdu.payload.data=mesg; + pdu.payload.size=max_mesg_size; + return app_buffer_get(pdu.payload); } /* @@ -75,7 +97,8 @@ int mic_tcp_recv (int socket, char* mesg, int max_mesg_size) int mic_tcp_close (int socket) { printf("[MIC-TCP] Appel de la fonction : "); printf(__FUNCTION__); printf("\n"); - return -1; + sock.state=CLOSED; + return 0; } /* @@ -87,4 +110,7 @@ int mic_tcp_close (int socket) void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr) { printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); + return app_buffer_put(pdu.payload); + + }