Cleanup: remove trailing whitespace in all files of the project
This commit is contained in:
parent
e28e634800
commit
95be64764a
9 changed files with 133 additions and 133 deletions
6
Makefile
6
Makefile
|
@ -10,7 +10,7 @@ LD := gcc
|
|||
|
||||
TAR_FILENAME := $(DATE)-mictcp-$(TAG).tar.gz
|
||||
|
||||
MODULES := api apps
|
||||
MODULES := api apps
|
||||
SRC_DIR := $(addprefix src/,$(MODULES)) src
|
||||
BUILD_DIR := $(addprefix build/,$(MODULES)) build
|
||||
|
||||
|
@ -19,7 +19,7 @@ OBJ := $(patsubst src/%.c,build/%.o,$(SRC))
|
|||
OBJ_CLI := $(patsubst build/apps/gateway.o,,$(patsubst build/apps/server.o,,$(OBJ)))
|
||||
OBJ_SERV := $(patsubst build/apps/gateway.o,,$(patsubst build/apps/client.o,,$(OBJ)))
|
||||
OBJ_GWAY := $(patsubst build/apps/server.o,,$(patsubst build/apps/client.o,,$(OBJ)))
|
||||
INCLUDES := include
|
||||
INCLUDES := include
|
||||
|
||||
vpath %.c $(SRC_DIR)
|
||||
|
||||
|
@ -51,7 +51,7 @@ clean:
|
|||
|
||||
distclean:
|
||||
@rm -rf $(BUILD_DIR)
|
||||
@-rm -f *.tar.gz || true
|
||||
@-rm -f *.tar.gz || true
|
||||
|
||||
|
||||
$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
|
||||
|
|
|
@ -10,28 +10,28 @@
|
|||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <netdb.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
/*
|
||||
* Etats du protocole (les noms des états sont donnés à titre indicatif
|
||||
/*
|
||||
* Etats du protocole (les noms des états sont donnés à titre indicatif
|
||||
* et peuvent être modifiés)
|
||||
*/
|
||||
typedef enum protocol_state
|
||||
{
|
||||
IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, ESTABLISHED, CLOSING
|
||||
IDLE, CLOSED, SYN_SENT, SYN_RECEIVED, ESTABLISHED, CLOSING
|
||||
} protocol_state;
|
||||
|
||||
/*
|
||||
* Mode de démarrage du protocole
|
||||
* Mode de démarrage du protocole
|
||||
* NB : nécessaire à l’usage de la fonction initialize_components()
|
||||
*/
|
||||
typedef enum start_mode { CLIENT, SERVER } start_mode;
|
||||
|
||||
/*
|
||||
* Structure d’une adresse de socket
|
||||
* Structure d’une adresse de socket
|
||||
*/
|
||||
typedef struct mic_tcp_sock_addr
|
||||
{
|
||||
|
@ -42,10 +42,10 @@ typedef struct mic_tcp_sock_addr
|
|||
|
||||
/*
|
||||
* Structure d'un socket
|
||||
*/
|
||||
*/
|
||||
typedef struct mic_tcp_sock
|
||||
{
|
||||
int fd; /* descripteur du socket */
|
||||
int fd; /* descripteur du socket */
|
||||
protocol_state state; /* état du protocole */
|
||||
mic_tcp_sock_addr addr; /* adresse du socket */
|
||||
} mic_tcp_sock;
|
||||
|
@ -74,7 +74,7 @@ typedef struct mic_tcp_header
|
|||
} mic_tcp_header;
|
||||
|
||||
/*
|
||||
* Structure d'un PDU MIC-TCP
|
||||
* Structure d'un PDU MIC-TCP
|
||||
*/
|
||||
typedef struct mic_tcp_pdu
|
||||
{
|
||||
|
@ -83,7 +83,7 @@ typedef struct mic_tcp_pdu
|
|||
} mic_tcp_pdu;
|
||||
|
||||
/*
|
||||
* Structure des données utiles d’un PDU IP
|
||||
* Structure des données utiles d’un PDU IP
|
||||
*/
|
||||
typedef struct ip_payload
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ typedef struct ip_payload
|
|||
typedef struct app_buffer
|
||||
{
|
||||
mic_tcp_payload packet;
|
||||
struct app_buffer* next;
|
||||
struct app_buffer* next;
|
||||
unsigned short id;
|
||||
} app_buffer;
|
||||
|
||||
|
@ -103,7 +103,7 @@ typedef struct app_buffer
|
|||
/****************************
|
||||
* Fonctions de l'interface *
|
||||
****************************/
|
||||
int mic_tcp_socket(start_mode sm);
|
||||
int mic_tcp_socket(start_mode sm);
|
||||
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_connect(int socket, mic_tcp_sock_addr addr);
|
||||
|
|
|
@ -36,12 +36,12 @@ int initialize_components(start_mode mode)
|
|||
struct hostent * hp;
|
||||
struct sockaddr_in local_addr;
|
||||
|
||||
if(initialized != -1) return initialized;
|
||||
if(initialized != -1) return initialized;
|
||||
if((sys_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) return -1;
|
||||
else initialized = 1;
|
||||
|
||||
|
||||
if((mode == SERVER) & (initialized != -1))
|
||||
{
|
||||
{
|
||||
TAILQ_INIT(&app_buffer_head);
|
||||
pthread_cond_init(&buffer_empty_cond, 0);
|
||||
memset((char *) &local_addr, 0, sizeof(local_addr));
|
||||
|
@ -49,7 +49,7 @@ int initialize_components(start_mode mode)
|
|||
local_addr.sin_port = htons(API_CS_Port);
|
||||
local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
bnd = bind(sys_socket, (struct sockaddr *) &local_addr, sizeof(local_addr));
|
||||
|
||||
|
||||
if (bnd == -1)
|
||||
{
|
||||
initialized = -1;
|
||||
|
@ -62,9 +62,9 @@ int initialize_components(start_mode mode)
|
|||
hp = gethostbyname("localhost");
|
||||
memcpy (&(remote_addr.sin_addr.s_addr), hp->h_addr, hp->h_length);
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ int initialize_components(start_mode mode)
|
|||
remote_addr.sin_port = htons(API_CS_Port);
|
||||
hp = gethostbyname("localhost");
|
||||
memcpy (&(remote_addr.sin_addr.s_addr), hp->h_addr, hp->h_length);
|
||||
|
||||
|
||||
memset((char *) &local_addr, 0, sizeof(local_addr));
|
||||
local_addr.sin_family = AF_INET;
|
||||
local_addr.sin_port = htons(API_SC_Port);
|
||||
|
@ -83,15 +83,15 @@ int initialize_components(start_mode mode)
|
|||
bnd = bind(sys_socket, (struct sockaddr *) &local_addr, sizeof(local_addr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((initialized == 1) && (mode == SERVER))
|
||||
{
|
||||
pthread_create (&listen_th, NULL, listening, "1");
|
||||
}
|
||||
|
||||
|
||||
return initialized;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
|
||||
|
@ -103,12 +103,12 @@ int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
|
|||
result = -1;
|
||||
|
||||
} else {
|
||||
mic_tcp_payload tmp = get_full_stream(pk);
|
||||
mic_tcp_payload tmp = get_full_stream(pk);
|
||||
int sent_size = mic_tcp_core_send(tmp);
|
||||
|
||||
|
||||
free (tmp.data);
|
||||
|
||||
result = sent_size;
|
||||
|
||||
result = sent_size;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -126,12 +126,12 @@ int IP_recv(ip_payload* pk,mic_tcp_sock_addr* addr, unsigned long timeout)
|
|||
if(initialized == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Compute the number of entire seconds */
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_sec = timeout / 1000;
|
||||
/* Convert the remainder to microseconds */
|
||||
tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
|
||||
|
||||
tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
|
||||
|
||||
if ((setsockopt(sys_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) >= 0) {
|
||||
result = recvfrom(sys_socket, pk->data, pk->size, 0, (struct sockaddr *)&tmp_addr, &tmp_addr_size);
|
||||
pk->size = result;
|
||||
|
@ -146,10 +146,10 @@ mic_tcp_payload get_full_stream(mic_tcp_pdu pk)
|
|||
mic_tcp_payload tmp;
|
||||
tmp.size = API_HD_Size + pk.payload.size;
|
||||
tmp.data = malloc (tmp.size);
|
||||
|
||||
|
||||
memcpy (tmp.data, &pk.header, API_HD_Size);
|
||||
memcpy (tmp.data + API_HD_Size, pk.payload.data, pk.payload.size);
|
||||
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ mic_tcp_payload get_mic_tcp_data(ip_payload buff)
|
|||
memcpy(tmp.data, buff.data+API_HD_Size, tmp.size);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
mic_tcp_header get_mic_tcp_header(ip_payload packet)
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ int mic_tcp_core_send(mic_tcp_payload buff)
|
|||
printf("[MICTCP-CORE] Perte du paquet\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
int app_buffer_get(mic_tcp_payload app_buff)
|
||||
|
@ -218,23 +218,23 @@ int app_buffer_get(mic_tcp_payload app_buff)
|
|||
|
||||
/* The entry we want is the first one in the buffer */
|
||||
entry = app_buffer_head.tqh_first;
|
||||
|
||||
|
||||
/* How much data are we going to deliver to the application ? */
|
||||
result = min_size(entry->bf.size, app_buff.size);
|
||||
|
||||
/* We copy the actual data in the application allocated buffer */
|
||||
memcpy(app_buff.data, entry->bf.data, result);
|
||||
|
||||
/* We remove the entry from the buffer */
|
||||
/* We remove the entry from the buffer */
|
||||
TAILQ_REMOVE(&app_buffer_head, entry, entries);
|
||||
|
||||
/* Release the mutex */
|
||||
|
||||
/* Release the mutex */
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
|
||||
/* Clean up memory */
|
||||
free(entry->bf.data);
|
||||
free(entry);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -248,11 +248,11 @@ void app_buffer_put(mic_tcp_payload bf)
|
|||
pthread_mutex_lock(&lock);
|
||||
|
||||
/* Insert the packet in the buffer, at the end of it */
|
||||
TAILQ_INSERT_TAIL(&app_buffer_head, entry, entries);
|
||||
|
||||
TAILQ_INSERT_TAIL(&app_buffer_head, entry, entries);
|
||||
|
||||
/* Release the mutex */
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
|
||||
/* We can now signal to any potential thread waiting that the buffer is
|
||||
no longer empty */
|
||||
pthread_cond_broadcast(&buffer_empty_cond);
|
||||
|
@ -261,25 +261,25 @@ void app_buffer_put(mic_tcp_payload bf)
|
|||
|
||||
|
||||
void* listening(void* arg)
|
||||
{
|
||||
{
|
||||
mic_tcp_pdu pdu_tmp;
|
||||
int recv_size;
|
||||
int recv_size;
|
||||
mic_tcp_sock_addr remote;
|
||||
ip_payload tmp_buff;
|
||||
|
||||
|
||||
pthread_mutex_init(&lock, NULL);
|
||||
|
||||
printf("[MICTCP-CORE] Demarrage du thread de reception reseau...\n");
|
||||
|
||||
|
||||
tmp_buff.size = 1500;
|
||||
tmp_buff.data = malloc(1500);
|
||||
|
||||
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
{
|
||||
tmp_buff.size = 1500;
|
||||
recv_size = IP_recv(&tmp_buff, &remote, 0);
|
||||
|
||||
recv_size = IP_recv(&tmp_buff, &remote, 0);
|
||||
|
||||
if(recv_size > 0)
|
||||
{
|
||||
pdu_tmp.header = get_mic_tcp_header (tmp_buff);
|
||||
|
@ -289,7 +289,7 @@ void* listening(void* arg)
|
|||
/* This should never happen */
|
||||
printf("Error in recv\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
int sockfd = 0;
|
||||
char chaine[MAX_SIZE];
|
||||
char chaine[MAX_SIZE];
|
||||
mic_tcp_sock_addr addr;
|
||||
addr.ip_addr = "127.0.0.1";
|
||||
addr.port = 1234;
|
||||
|
@ -16,23 +16,23 @@ int main()
|
|||
if ((sockfd = mic_tcp_socket(CLIENT)) == -1)
|
||||
{
|
||||
printf("[TSOCK] Erreur a la creation du socket MICTCP!\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[TSOCK] Creation du socket MICTCP: OK\n");
|
||||
}
|
||||
|
||||
|
||||
if (mic_tcp_connect(sockfd, addr) == -1)
|
||||
{
|
||||
printf("[TSOCK] Erreur a la connexion du socket MICTCP!\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[TSOCK] Connexion du socket MICTCP: OK\n");
|
||||
}
|
||||
|
||||
|
||||
memset(chaine, 0, MAX_SIZE);
|
||||
|
||||
printf("[TSOCK] Entrez vos message a envoyer, CTRL+D pour quitter\n");
|
||||
|
@ -40,9 +40,9 @@ int main()
|
|||
int sent_size = mic_tcp_send(sockfd, chaine, strlen(chaine)+1);
|
||||
printf("[TSOCK] Appel de mic_send avec un message de taille : %d\n", strlen(chaine)+1);
|
||||
printf("[TSOCK] Appel de mic_send valeur de retour : %d\n", sent_size);
|
||||
}
|
||||
}
|
||||
|
||||
mic_tcp_close(sockfd);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
@ -29,7 +29,7 @@ void udp_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, in
|
|||
|
||||
/* A buffer used to store received segments before they are forwarded */
|
||||
char buffer[MAX_UDP_SEGMENT_SIZE];
|
||||
|
||||
|
||||
/* Initialize a packet count variable used when loss emulation is active */
|
||||
int count = 0;
|
||||
ssize_t n = -1;
|
||||
|
@ -39,7 +39,7 @@ void udp_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, in
|
|||
struct sockaddr_in cliaddr;
|
||||
socklen_t len = sizeof(cliaddr);
|
||||
|
||||
/* We construct the socket to be used by this function */
|
||||
/* We construct the socket to be used by this function */
|
||||
listen_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (bind(listen_sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
|
||||
|
@ -57,7 +57,7 @@ void udp_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, in
|
|||
|
||||
n = recvfrom(listen_sockfd, buffer, MAX_UDP_SEGMENT_SIZE, 0, (struct sockaddr *) &cliaddr, &len);
|
||||
if (n < 0) {
|
||||
perror(0);
|
||||
perror(0);
|
||||
}
|
||||
|
||||
if(loss == 1) {
|
||||
|
@ -73,14 +73,14 @@ void udp_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, in
|
|||
n = sendto(listen_sockfd, buffer, n, 0, (struct sockaddr *) &transmit_to, len);
|
||||
if (n < 0) {
|
||||
perror(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We never execute this but anyway, for sanity */
|
||||
close(listen_sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
struct timespec tsSubtract (struct timespec time1, struct timespec time2) {
|
||||
struct timespec tsSubtract (struct timespec time1, struct timespec time2) {
|
||||
struct timespec result ;
|
||||
|
||||
/* Subtract the second time from the first. */
|
||||
|
@ -149,7 +149,7 @@ void file_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, i
|
|||
n = fread(buffer, 1, sizeof(n), fd);
|
||||
n = fread(buffer, 1, *((int *)buffer), fd);
|
||||
if (n < 0) {
|
||||
perror(0);
|
||||
perror(0);
|
||||
}
|
||||
|
||||
if(loss == 1) {
|
||||
|
@ -165,11 +165,11 @@ void file_to_tcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to, i
|
|||
n = sendto(listen_sockfd, buffer, n, 0, (struct sockaddr *) &transmit_to, len);
|
||||
if (n < 0) {
|
||||
perror(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(listen_sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that reads a file and delivers to MICTCP.
|
||||
|
@ -196,7 +196,7 @@ void file_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to
|
|||
int firstValue = 0;
|
||||
int active = 1;
|
||||
|
||||
|
||||
|
||||
/* MICTCP stuff */
|
||||
int mic_tcp_sockfd;
|
||||
start_mode start_mode_mic_tcp = CLIENT;
|
||||
|
@ -206,7 +206,7 @@ void file_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to
|
|||
|
||||
/* We construct the UDP and MICTCP sockets to be used by this function */
|
||||
listen_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
|
||||
if((mic_tcp_sockfd = mic_tcp_socket(start_mode_mic_tcp)) == -1) {
|
||||
printf("ERROR creating the MICTCP socket\n");
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ void file_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to
|
|||
if(mic_tcp_connect(mic_tcp_sockfd, mic_tcp_dest_addr) == -1) {
|
||||
printf("ERROR connecting the MICTCP socket\n");
|
||||
}
|
||||
|
||||
|
||||
/* Main activity loop, we exit this at the end of the file */
|
||||
while(active) {
|
||||
memset(buffer, 0, MAX_UDP_SEGMENT_SIZE);
|
||||
|
@ -247,18 +247,18 @@ void file_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to
|
|||
}
|
||||
|
||||
/* We forward the packet to its final destination */
|
||||
n = mic_tcp_send(mic_tcp_sockfd, buffer, n);
|
||||
n = mic_tcp_send(mic_tcp_sockfd, buffer, n);
|
||||
if (n <= 0) {
|
||||
printf("ERROR on MICTCP send\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We execute this when the file has finished being replayed */
|
||||
close(listen_sockfd);
|
||||
|
||||
|
||||
/* Same for MICTCP */
|
||||
mic_tcp_close(mic_tcp_sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -278,10 +278,10 @@ void udp_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
struct sockaddr_in cliaddr;
|
||||
struct sockaddr_in serv_addr = listen_on;
|
||||
socklen_t len = sizeof(cliaddr);
|
||||
|
||||
|
||||
/* Initialize a packet count variable used when loss emulation is active */
|
||||
ssize_t n = -1;
|
||||
|
||||
|
||||
/* MICTCP stuff */
|
||||
int mic_tcp_sockfd;
|
||||
start_mode start_mode_mic_tcp = CLIENT;
|
||||
|
@ -291,7 +291,7 @@ void udp_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
|
||||
/* We construct the UDP and MICTCP sockets to be used by this function */
|
||||
listen_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
|
||||
if((mic_tcp_sockfd = mic_tcp_socket(start_mode_mic_tcp)) == -1) {
|
||||
printf("ERROR creating the MICTCP socket\n");
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ void udp_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
if(mic_tcp_connect(mic_tcp_sockfd, mic_tcp_dest_addr) == -1) {
|
||||
printf("ERROR connecting the MICTCP socket\n");
|
||||
}
|
||||
|
||||
|
||||
if (bind(listen_sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
|
||||
printf("ERROR on binding the UDP socket: ");
|
||||
perror(0);
|
||||
|
@ -315,22 +315,22 @@ void udp_to_mictcp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
|
||||
n = recvfrom(listen_sockfd, buffer, MAX_UDP_SEGMENT_SIZE, 0, (struct sockaddr *) &cliaddr, &len);
|
||||
if (n < 0) {
|
||||
perror(0);
|
||||
perror(0);
|
||||
}
|
||||
|
||||
/* We forward the packet to its final destination */
|
||||
n = mic_tcp_send(mic_tcp_sockfd, buffer, n);
|
||||
n = mic_tcp_send(mic_tcp_sockfd, buffer, n);
|
||||
if (n <= 0) {
|
||||
printf("ERROR on MICTCP send\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We never execute this but anyway, for sanity */
|
||||
close(listen_sockfd);
|
||||
|
||||
|
||||
/* Same for MICTCP */
|
||||
mic_tcp_close(mic_tcp_sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that listens on MICTCP and delivers to UDP.
|
||||
|
@ -352,7 +352,7 @@ void mictcp_to_udp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
/* Addresses for the work to be performed */
|
||||
struct sockaddr_in cliaddr;
|
||||
socklen_t len = sizeof(cliaddr);
|
||||
|
||||
|
||||
/* MICTCP stuff */
|
||||
int mic_tcp_sockfd;
|
||||
start_mode start_mode_mic_tcp = SERVER;
|
||||
|
@ -362,7 +362,7 @@ void mictcp_to_udp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
|
||||
/* We construct the UDP and MICTCP sockets to be used by this function */
|
||||
sending_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
|
||||
if((mic_tcp_sockfd = mic_tcp_socket(start_mode_mic_tcp)) == -1) {
|
||||
printf("ERROR creating the MICTCP socket\n");
|
||||
}
|
||||
|
@ -381,12 +381,12 @@ void mictcp_to_udp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
/* Main activity loop, we never exit this, user terminates with SIGKILL */
|
||||
while(1) {
|
||||
int k;
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
{
|
||||
memset(Buff[k], 0, MAX_UDP_SEGMENT_SIZE);
|
||||
}
|
||||
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
{
|
||||
n = mic_tcp_recv(mic_tcp_sockfd, Buff[k], MAX_UDP_SEGMENT_SIZE);
|
||||
if (n <= 0) {
|
||||
|
@ -395,23 +395,23 @@ void mictcp_to_udp(struct sockaddr_in listen_on, struct sockaddr_in transmit_to)
|
|||
}
|
||||
|
||||
/* We forward the packet to its final destination */
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
for(k=0; k<CUMULATED_BUFF_NB; k++)
|
||||
{
|
||||
n = sendto(sending_sockfd, Buff[k], n, 0, (struct sockaddr *) &transmit_to, len);
|
||||
if (n <= 0) {
|
||||
perror(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*sleep(1); */
|
||||
}
|
||||
|
||||
/* We never execute this but anyway, for sanity */
|
||||
close(sending_sockfd);
|
||||
|
||||
|
||||
/* Same for MICTCP */
|
||||
mic_tcp_close(mic_tcp_sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void usage(void) {
|
||||
|
@ -455,18 +455,18 @@ int main(int argc, char ** argv) {
|
|||
transport = 0;
|
||||
} else {
|
||||
printf("Unrecognized transport : %s\n", optarg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if(puits == -1) {
|
||||
puits = 0;
|
||||
puits = 0;
|
||||
} else {
|
||||
puits = -2;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if(puits == -1) {
|
||||
puits = 1;
|
||||
puits = 1;
|
||||
} else {
|
||||
puits = -2;
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ int main(int argc, char ** argv) {
|
|||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
||||
if((puits == 1 && argc != 1) || ((puits == 0) && argc != 2)) {
|
||||
usage();
|
||||
return -1;
|
||||
|
|
|
@ -8,16 +8,16 @@ int main()
|
|||
int sockfd;
|
||||
mic_tcp_sock_addr addr;
|
||||
mic_tcp_sock_addr remote_addr;
|
||||
char chaine[MAX_SIZE];
|
||||
char chaine[MAX_SIZE];
|
||||
|
||||
addr.ip_addr = "127.0.0.1";
|
||||
addr.port = 1234;
|
||||
|
||||
|
||||
|
||||
if ((sockfd = mic_tcp_socket(SERVER)) == -1)
|
||||
{
|
||||
printf("[TSOCK] Erreur a la creation du socket MICTCP!\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ int main()
|
|||
if (mic_tcp_bind(sockfd, addr) == -1)
|
||||
{
|
||||
printf("[TSOCK] Erreur lors du bind du socket MICTCP!\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -37,13 +37,13 @@ int main()
|
|||
if (mic_tcp_accept(sockfd, &remote_addr) == -1)
|
||||
{
|
||||
printf("[TSOCK] Erreur lors de l'accept sur le socket MICTCP!\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[TSOCK] Accept sur le socket MICTCP: OK\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
memset(chaine, 0, MAX_SIZE);
|
||||
|
||||
|
@ -55,6 +55,6 @@ int main()
|
|||
rcv_size = mic_tcp_recv(sockfd, chaine, MAX_SIZE);
|
||||
printf("[TSOCK] Reception d'un message de taille : %d\n", rcv_size);
|
||||
printf("[TSOCK] Message Recu : %s", chaine);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
24
src/mictcp.c
24
src/mictcp.c
|
@ -5,7 +5,7 @@
|
|||
* Permet de créer un socket entre l’application et MIC-TCP
|
||||
* Retourne le descripteur du socket ou bien -1 en cas d'erreur
|
||||
*/
|
||||
int mic_tcp_socket(start_mode sm)
|
||||
int mic_tcp_socket(start_mode sm)
|
||||
{
|
||||
int result = -1;
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
|
@ -16,7 +16,7 @@ int mic_tcp_socket(start_mode sm)
|
|||
}
|
||||
|
||||
/*
|
||||
* Permet d’attribuer une adresse à un socket.
|
||||
* Permet d’attribuer une adresse à un socket.
|
||||
* Retourne 0 si succès, et -1 en cas d’échec
|
||||
*/
|
||||
int mic_tcp_bind(int socket, mic_tcp_sock_addr addr)
|
||||
|
@ -40,7 +40,7 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr)
|
|||
* Retourne 0 si la connexion est établie, et -1 en cas d’échec
|
||||
*/
|
||||
int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
||||
{
|
||||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -52,24 +52,24 @@ 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;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Permet à l’application réceptrice de réclamer la récupération d’une donnée
|
||||
* Permet à l’application réceptrice de réclamer la récupération d’une donnée
|
||||
* stockée dans les buffers de réception du socket
|
||||
* Retourne le nombre d’octets lu ou bien -1 en cas d’erreur
|
||||
* NB : cette fonction fait appel à la fonction app_buffer_get()
|
||||
* 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;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Permet de réclamer la destruction d’un socket.
|
||||
* Engendre la fermeture de la connexion suivant le modèle de TCP.
|
||||
* Permet de réclamer la destruction d’un socket.
|
||||
* Engendre la fermeture de la connexion suivant le modèle de TCP.
|
||||
* Retourne 0 si tout se passe bien et -1 en cas d'erreur
|
||||
*/
|
||||
int mic_tcp_close (int socket)
|
||||
|
@ -80,9 +80,9 @@ int mic_tcp_close (int socket)
|
|||
|
||||
/*
|
||||
* Traitement d’un PDU MIC-TCP reçu (mise à jour des numéros de séquence
|
||||
* et d'acquittement, etc.) puis insère les données utiles du PDU dans
|
||||
* le buffer de réception du socket. Cette fonction utilise la fonction
|
||||
* app_buffer_put().
|
||||
* et d'acquittement, etc.) puis insère les données utiles du PDU dans
|
||||
* le buffer de réception du socket. Cette fonction utilise la fonction
|
||||
* app_buffer_put().
|
||||
*/
|
||||
void process_received_PDU(mic_tcp_pdu pdu)
|
||||
{
|
||||
|
|
|
@ -6,13 +6,13 @@ protocol="tcp"
|
|||
|
||||
usage() { echo "Usage: $0 [-p|-s]" 1>&2; exit 1; }
|
||||
|
||||
while getopts "pst:" o; do
|
||||
while getopts "pst:" o; do
|
||||
case "${o}" in
|
||||
p)
|
||||
puits=true
|
||||
puits=true
|
||||
;;
|
||||
s)
|
||||
sourc=true
|
||||
sourc=true
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
@ -27,7 +27,7 @@ fi
|
|||
|
||||
if [ "$puits" = true ]; then
|
||||
cd build
|
||||
./server
|
||||
./server
|
||||
cd ..
|
||||
fi
|
||||
|
||||
|
|
10
tsock_video
10
tsock_video
|
@ -6,20 +6,20 @@ protocol="tcp"
|
|||
|
||||
usage() { echo "Usage: $0 [[-p|-s] [-t (tcp|mictcp)]" 1>&2; exit 1; }
|
||||
|
||||
while getopts "pst:" o; do
|
||||
while getopts "pst:" o; do
|
||||
case "${o}" in
|
||||
t)
|
||||
protocol=${OPTARG}
|
||||
if [ "$protocol" != "tcp" ] && [ "$protocol" != "mictcp" ]; then
|
||||
if [ "$protocol" != "tcp" ] && [ "$protocol" != "mictcp" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
p)
|
||||
puits=true
|
||||
puits=true
|
||||
;;
|
||||
s)
|
||||
sourc=true
|
||||
sourc=true
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
@ -53,7 +53,7 @@ if [ "$sourc" = true ]; then
|
|||
fi
|
||||
|
||||
echo "Appuyez sur ENTREE pour arreter"
|
||||
read line
|
||||
read line
|
||||
|
||||
echo "Arret"
|
||||
killall -9 cvlc > /dev/null 2>&1
|
||||
|
|
Loading…
Reference in a new issue