This commit is contained in:
Alexis Berger 2024-03-27 17:27:41 +01:00
parent ca99010627
commit a1db787834

View file

@ -5,12 +5,24 @@
* Permet de créer un socket entre lapplication et MIC-TCP
* Retourne le descripteur du socket ou bien -1 en cas d'erreur
*/
mic_tcp_sock sock = {0};
mic_tcp_sock_addr address;
int mic_tcp_socket(start_mode sm)
{
int result = -1;
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
result = initialize_components(sm); /* Appel obligatoire */
set_loss_rate(0);
sock.local_addr.port = 9000;
sock.local_addr.ip_addr.addr = "localhost";
sock.local_addr.ip_addr.addr_size = 9;
return result;
}
@ -22,7 +34,7 @@ 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;
return 0;
}
/*
@ -32,7 +44,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.remote_addr = *addr;
return 0;
}
/*
@ -42,7 +55,9 @@ 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;
address = addr;
sock.remote_addr = addr;
return 0;
}
/*
@ -52,6 +67,15 @@ 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");
mic_tcp_pdu pdu = {0};
pdu.payload.data = mesg;
pdu.payload.size = mesg_size;
pdu.header.source_port = sock.local_addr.port;
pdu.header.dest_port = address.port;
return IP_send(pdu,address.ip_addr);
return -1;
}
@ -62,9 +86,11 @@ int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
* NB : cette fonction fait appel à la fonction app_buffer_get()
*/
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;
{ printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
mic_tcp_payload p;
p.data = mesg;
p.size = max_mesg_size;
return app_buffer_get(p);
}
/*
@ -87,4 +113,5 @@ int mic_tcp_close (int socket)
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_ip_addr local_addr, mic_tcp_ip_addr remote_addr)
{
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
app_buffer_put(pdu.payload);
}