V1 implémentée

This commit is contained in:
Gwenael Robert 2022-03-18 09:43:49 +01:00
parent 13766b7c78
commit f24472df74
2 changed files with 36 additions and 10 deletions

View file

@ -21,7 +21,7 @@
*/ */
typedef enum protocol_state typedef enum protocol_state
{ {
IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, ESTABLISHED, CLOSING IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, CONNECTED, CLOSING
} protocol_state; } protocol_state;
/* /*

View file

@ -5,13 +5,16 @@
* Permet de créer un socket entre lapplication et MIC-TCP * Permet de créer un socket entre lapplication et MIC-TCP
* Retourne le descripteur du socket ou bien -1 en cas d'erreur * 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 mic_tcp_socket(start_mode sm)
{ {
int result = -1; int result=-1;
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
result = initialize_components(sm); /* Appel obligatoire */ result = initialize_components(sm); /* Appel obligatoire */
sock.fd=result;
set_loss_rate(0); set_loss_rate(0);
return result; return result;
} }
@ -22,7 +25,13 @@ int mic_tcp_socket(start_mode sm)
int mic_tcp_bind(int socket, mic_tcp_sock_addr addr) int mic_tcp_bind(int socket, mic_tcp_sock_addr addr)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); 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; 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) int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); 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) int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); 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) int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); 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) int mic_tcp_recv (int socket, char* mesg, int max_mesg_size)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); 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) int mic_tcp_close (int socket)
{ {
printf("[MIC-TCP] Appel de la fonction : "); printf(__FUNCTION__); printf("\n"); 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) void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
{ {
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n"); printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
return app_buffer_put(pdu.payload);
} }