feat(v1): usage message
This commit is contained in:
parent
2e156fef2f
commit
40f45b9e3b
1 changed files with 34 additions and 38 deletions
72
tsock_v1.c
72
tsock_v1.c
|
@ -19,23 +19,12 @@
|
|||
#include <errno.h>
|
||||
#define BASE_SIZE 10
|
||||
|
||||
void construire_message(char *message, char motif, int lg) {
|
||||
int i;
|
||||
for (i=0;i<lg;i++) message[i] = motif;
|
||||
}
|
||||
|
||||
void afficher_message(char *message, int lg) {
|
||||
int i;
|
||||
printf("message reçu : ");
|
||||
for (i=0;i<lg;i++){
|
||||
printf("%c", message[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
void construire_message(char *message, char motif, int lg);
|
||||
void afficher_message(char *message, int lg);
|
||||
void print_usage();
|
||||
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
@ -47,7 +36,7 @@ int main (int argc, char **argv)
|
|||
switch (c) {
|
||||
case 'p':
|
||||
if (source == 1) {
|
||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
source = 0;
|
||||
|
@ -55,7 +44,7 @@ int main (int argc, char **argv)
|
|||
|
||||
case 's':
|
||||
if (source == 0) {
|
||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
||||
print_usage();
|
||||
exit(1) ;
|
||||
}
|
||||
source = 1;
|
||||
|
@ -70,8 +59,8 @@ int main (int argc, char **argv)
|
|||
break;
|
||||
|
||||
default:
|
||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
||||
break;
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +73,7 @@ int main (int argc, char **argv)
|
|||
char* message = malloc(BASE_SIZE * sizeof(char));
|
||||
|
||||
if (source == -1) {
|
||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
||||
print_usage();
|
||||
exit(1) ;
|
||||
}
|
||||
|
||||
|
@ -93,9 +82,7 @@ int main (int argc, char **argv)
|
|||
|
||||
//Recuperation du nom logique
|
||||
nom_machine_distante=argv[argc-2];
|
||||
}
|
||||
|
||||
else
|
||||
} else
|
||||
printf("on est dans le puits\n");
|
||||
|
||||
if (nb_message != -1) {
|
||||
|
@ -109,7 +96,6 @@ int main (int argc, char **argv)
|
|||
printf("nb de tampons à envoyer = 10 par défaut\n");
|
||||
} else
|
||||
printf("nb de tampons à envoyer = infini\n");
|
||||
|
||||
}
|
||||
|
||||
if (udp==1){
|
||||
|
@ -117,9 +103,6 @@ int main (int argc, char **argv)
|
|||
int sock= socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
if (source==1) {
|
||||
|
||||
|
||||
|
||||
// Creation de l'adresse du socket distant
|
||||
struct hostent *hp ;
|
||||
struct sockaddr_in adr_dest;
|
||||
|
@ -150,14 +133,8 @@ int main (int argc, char **argv)
|
|||
|
||||
sendto(sock,message,longueur_message,0,(struct sockaddr*)&adr_dest,longueur_adr_dest);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
|
||||
} else { // UDP & Puit
|
||||
// Creation de l'adresse du socket distant
|
||||
struct sockaddr_in adr_locale;
|
||||
int longueur_adr_locale = sizeof(adr_locale);
|
||||
|
@ -183,12 +160,31 @@ int main (int argc, char **argv)
|
|||
// Afficher notre seule et unique triste message
|
||||
afficher_message(message, longueur_message);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void construire_message(char *message, char motif, int lg) {
|
||||
int i;
|
||||
for (i=0;i<lg;i++) message[i] = motif;
|
||||
}
|
||||
|
||||
void afficher_message(char *message, int lg) {
|
||||
int i;
|
||||
printf("message reçu : ");
|
||||
for (i=0;i<lg;i++){
|
||||
printf("%c", message[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_usage() {
|
||||
printf("usage: tsock_v1 <-u> [-ps] [host] <port>\n");
|
||||
printf("parameters: host With -s, address of the host to connect to. Required with -s.\n");
|
||||
printf(" port Port to connect or bind to. Required.\n");
|
||||
printf("options: -p Runs a TCP/UDP sink. Incompatible with -s.\n");
|
||||
printf(" -s Runs a TCP/UDP faucet. Incompatible with -p.\n");
|
||||
printf(" -u Use UDP instead of TCP. Required.\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue