Completato esercizio di gestioen database client-server. Archivio.txt e comandi aggiungi nome voto,verifica nome.
This commit is contained in:
7
11.client-server-exam-database (COMPLETE)/archivio.txt
Executable file
7
11.client-server-exam-database (COMPLETE)/archivio.txt
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
MARIO 30 127.0.0.1:37968
|
||||||
|
FONZO 15 127.0.0.1:37968
|
||||||
|
CARLO 14 127.0.0.1:37981
|
||||||
|
MARIO 1950 127.0.0.1:38094
|
||||||
|
ARTUR 150 127.0.0.1:38099
|
||||||
|
KOMBAT 150 127.0.0.1:38099
|
||||||
|
|
||||||
7
11.client-server-exam-database (COMPLETE)/archivio.txt~
Executable file
7
11.client-server-exam-database (COMPLETE)/archivio.txt~
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
MARIO 30 127.0.0.1:37968
|
||||||
|
FONZO 15 127.0.0.1:37968
|
||||||
|
CARLO 14 127.0.0.1:37981
|
||||||
|
MARIO 1950 127.0.0.1:38094
|
||||||
|
ARTUR 150 127.0.0.1:38099
|
||||||
|
KOMBAT 150 127.0.0.1:38099
|
||||||
|
ione fornita da 127.0.0.1:38099 150 127.0.0.1:38099
|
||||||
BIN
11.client-server-exam-database (COMPLETE)/client
Executable file
BIN
11.client-server-exam-database (COMPLETE)/client
Executable file
Binary file not shown.
136
11.client-server-exam-database (COMPLETE)/daytimecli.c
Normal file
136
11.client-server-exam-database (COMPLETE)/daytimecli.c
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
#include "../basic.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void sigpipeaction (int signal){
|
||||||
|
|
||||||
|
|
||||||
|
//fprintf(stderr, "Sigpipe catturato\n");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct message {
|
||||||
|
char data [50];
|
||||||
|
char nome [50];
|
||||||
|
char voto [50];
|
||||||
|
}t_message;
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct sigaction sigpipestructure;
|
||||||
|
sigpipestructure.sa_handler = sigpipeaction;
|
||||||
|
sigpipestructure.sa_flags = 0;
|
||||||
|
|
||||||
|
sigaction (SIGPIPE, &sigpipestructure, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
if (argc != 3){
|
||||||
|
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
||||||
|
printf("inet_pton error for %s\n", argv[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
||||||
|
printf("connect error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ridden;
|
||||||
|
int written;
|
||||||
|
t_message m;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// welcome from server - first message
|
||||||
|
for (ridden = read (sockfd,&m,sizeof(m)); ridden <= 0;ridden = read (sockfd,&m,sizeof(m))){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
fprintf(stdout,"Server: %s\n",m.data);// answer from server
|
||||||
|
|
||||||
|
char line [1000];
|
||||||
|
char line_data [50];
|
||||||
|
char line_nome [50];
|
||||||
|
char line_voto [50];
|
||||||
|
for(; ;){
|
||||||
|
fprintf(stdout, "Inserisci comando: ");
|
||||||
|
fscanf (stdin,"%999[^\n]%*c",line);
|
||||||
|
sscanf (line, "%s", line_data);
|
||||||
|
if (strcmp("AGGIUNGI",line_data) == 0 || strcmp("VERIFICA",line_data) == 0){
|
||||||
|
|
||||||
|
if (strcmp("AGGIUNGI",line_data) == 0 ){
|
||||||
|
sprintf(m.data,"AGGIUNGI");
|
||||||
|
sprintf(line_nome,"def");
|
||||||
|
sprintf(line_voto,"def");
|
||||||
|
|
||||||
|
sscanf (line, "%*s %s %s", line_nome,line_voto);
|
||||||
|
if (strcmp(line_nome,"def") == 0 || strcmp(line_voto,"def") == 0){
|
||||||
|
fprintf(stdout,"Comando invalido\n");
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
sprintf(m.nome,"%s",line_nome);
|
||||||
|
sprintf(m.voto,"%s",line_voto);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sprintf(m.data,"VERIFICA");
|
||||||
|
sprintf(line_nome,"def");
|
||||||
|
sscanf (line, "%*s %s ", line_nome);
|
||||||
|
if (strcmp(line_nome,"def") == 0 ){
|
||||||
|
fprintf(stdout,"Comando invalido\n");
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
sprintf(m.nome,"%s",line_nome);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (written = write (sockfd, &m, sizeof (m) ); written == -1; written = write (sockfd, &m, sizeof (m)) ){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
for (ridden = read (sockfd,&m,sizeof(m)); ridden <= 0;ridden = read (sockfd,&m,sizeof(m))){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
fprintf(stdout,"Server: %s\n",m.data);// answer from server
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sprintf(m.data,"Bye");
|
||||||
|
|
||||||
|
for (written = write (sockfd, &m, sizeof (m) ); written == -1; written = write (sockfd, &m, sizeof (m)) ){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ridden = read (sockfd,&m,sizeof(m)); ridden <= 0;ridden = read (sockfd,&m,sizeof(m))){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout,"Server: %s\n",m.data);// answer from server
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
BIN
11.client-server-exam-database (COMPLETE)/daytimecli.o
Normal file
BIN
11.client-server-exam-database (COMPLETE)/daytimecli.o
Normal file
Binary file not shown.
@@ -17,6 +17,13 @@ void sigchldaction (int signal){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigpipeaction (int signal){
|
||||||
|
|
||||||
|
//fprintf(stderr, "Sigpipe catturato\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct message {
|
typedef struct message {
|
||||||
@@ -27,13 +34,22 @@ typedef struct message {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////// SIGNALS
|
||||||
|
///////SIGCHLD
|
||||||
struct sigaction sigchldstructure;
|
struct sigaction sigchldstructure;
|
||||||
sigchldstructure.sa_handler = sigchldaction;
|
sigchldstructure.sa_handler = sigchldaction;
|
||||||
sigchldstructure.sa_flags = 0;
|
sigchldstructure.sa_flags = 0;
|
||||||
|
|
||||||
sigaction (SIGCHLD, &sigchldstructure, NULL);
|
sigaction (SIGCHLD, &sigchldstructure, NULL);
|
||||||
|
|
||||||
|
///////SIGPIPE
|
||||||
|
struct sigaction sigpipestructure;
|
||||||
|
sigpipestructure.sa_handler = sigpipeaction;
|
||||||
|
sigpipestructure.sa_flags = 0;
|
||||||
|
|
||||||
|
sigaction (SIGPIPE, &sigpipestructure, NULL);
|
||||||
|
//////////////////////////////////////////////////////////// END SIGNALS
|
||||||
|
|
||||||
|
|
||||||
int listenfd, connfd, n;
|
int listenfd, connfd, n;
|
||||||
struct sockaddr_in servaddr;
|
struct sockaddr_in servaddr;
|
||||||
@@ -87,12 +103,13 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
close(listenfd);
|
close(listenfd);
|
||||||
|
|
||||||
t_message m; // buffer message structure
|
t_message m; // buffer message structure
|
||||||
int ridden, wrote;
|
int ridden, written;
|
||||||
|
|
||||||
sprintf ( m.data, "Benvenuto" );
|
sprintf ( m.data, "Benvenuto" );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo benvenuto sul socket
|
//write with error check
|
||||||
// check wrote
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN); // get client address
|
inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN); // get client address
|
||||||
@@ -101,8 +118,10 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
|
|
||||||
|
|
||||||
for ( ; ; ) {// the server child reserve other requests from same client
|
for ( ; ; ) {// the server child reserve other requests from same client
|
||||||
ridden = read (connfd,&m,sizeof(m));
|
|
||||||
// check read. it's blocking
|
for (ridden = read (connfd,&m,sizeof(m)); ridden <= 0;ridden = read (connfd,&m,sizeof(m))){
|
||||||
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@@ -111,12 +130,14 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
if (fd < 0){
|
if (fd < 0){
|
||||||
fd = open ("archivio.txt", O_CREAT | O_RDWR | O_APPEND ,00700);
|
fd = open ("archivio.txt", O_CREAT | O_RDWR | O_APPEND ,00700);
|
||||||
}
|
}
|
||||||
if (fd < 0){
|
if (fd < 0){
|
||||||
sprintf ( m.data, "Non posso modificare il database" );
|
sprintf ( m.data, "Non posso modificare il database" );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
} else {
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// local writes. no checks
|
||||||
write (fd,(m.nome), strlen ((m.nome)));
|
write (fd,(m.nome), strlen ((m.nome)));
|
||||||
write (fd," ", 1);
|
write (fd," ", 1);
|
||||||
write (fd,(m.voto), strlen ((m.voto)) );
|
write (fd,(m.voto), strlen ((m.voto)) );
|
||||||
@@ -131,9 +152,11 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
|
|
||||||
|
|
||||||
sprintf ( m.data, "AGGIUNTO" );
|
sprintf ( m.data, "AGGIUNTO" );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (strcmp (m.data, "VERIFICA" ) == 0 ){
|
if (strcmp (m.data, "VERIFICA" ) == 0 ){
|
||||||
@@ -141,8 +164,9 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
fd = open ("archivio.txt",O_RDONLY);
|
fd = open ("archivio.txt",O_RDONLY);
|
||||||
if (fd < 0){
|
if (fd < 0){
|
||||||
sprintf ( m.data, "Non posso leggere il database" );
|
sprintf ( m.data, "Non posso leggere il database" );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
char line [1000];
|
char line [1000];
|
||||||
@@ -154,7 +178,7 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
found = 0;
|
found = 0;
|
||||||
FILE * fdfile = fdopen(fd,"r");
|
FILE * fdfile = fdopen(fd,"r");
|
||||||
returned = fscanf (fdfile,"%999[^\n]%*c",line);
|
returned = fscanf (fdfile,"%999[^\n]%*c",line);
|
||||||
for( ; returned > 0 ; fscanf (fdfile,"%999[^\n]%*c",line) ){
|
for( ; returned > 0 ; returned = fscanf (fdfile,"%999[^\n]%*c",line) ){
|
||||||
|
|
||||||
sscanf (line, "%s %s %s", line_nome, line_voto, line_ip_port);
|
sscanf (line, "%s %s %s", line_nome, line_voto, line_ip_port);
|
||||||
|
|
||||||
@@ -162,8 +186,9 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
found = 1;
|
found = 1;
|
||||||
|
|
||||||
sprintf ( m.data, "%s ha sostenuto l'esame con voto %s. Informazione fornita da %s ", line_nome, line_voto, line_ip_port );
|
sprintf ( m.data, "%s ha sostenuto l'esame con voto %s. Informazione fornita da %s ", line_nome, line_voto, line_ip_port );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -171,17 +196,20 @@ sigaction (SIGCHLD, &sigchldstructure, NULL);
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found == 0){
|
if (found == 0){
|
||||||
sprintf ( m.data, "%s non ha sostenuto l'esame", &(m.nome) );
|
sprintf ( m.data, "%s non ha sostenuto l'esame", m.nome );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
sprintf ( m.data, "Bye" );
|
sprintf ( m.data, "Bye" );
|
||||||
wrote = write (connfd, &m, sizeof (m) ); // scrivo sul socket
|
for (written = write (connfd, &m, sizeof (m) ); written == -1; written = write (connfd, &m, sizeof (m)) ){
|
||||||
// check wrote
|
if (errno == EINTR){continue;} else {exit(0);}
|
||||||
|
}
|
||||||
|
|
||||||
break; // end requests from client
|
break; // end requests from client
|
||||||
|
|
||||||
BIN
11.client-server-exam-database (COMPLETE)/daytimesrv.o
Normal file
BIN
11.client-server-exam-database (COMPLETE)/daytimesrv.o
Normal file
Binary file not shown.
16
11.client-server-exam-database (COMPLETE)/readme
Normal file
16
11.client-server-exam-database (COMPLETE)/readme
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
SONO STATI CALCOALTI ERRORI SU READ,WRITE,CONNECT,SIGNALS
|
||||||
|
IL SERVER E' RICORSIVO E LE READ/WRITE SONO BLOCCANTI (SENZA SELECT)
|
||||||
|
PROTOCOLLO USATO TCP
|
||||||
|
|
||||||
|
il server gestisce un file archivio.txt
|
||||||
|
|
||||||
|
il client puo inviare:
|
||||||
|
BYE - per chiudere la connessione
|
||||||
|
AGGIUNGI <NOME> <VOTO> - per far aggiungere un nome al server
|
||||||
|
VERIFICA <NOME> - per verificare se un nome è presente nel database del server
|
||||||
|
|
||||||
|
il server risponde:
|
||||||
|
BYE - A BYE
|
||||||
|
AGGIUNTO - AL COMANDO AGGIUNGI DEL CLIENT
|
||||||
|
EVENTUALI INFORMAZIONI SUI DATI - AL COMADNO VERIFICA
|
||||||
14
11.client-server-exam-database (COMPLETE)/readme~
Normal file
14
11.client-server-exam-database (COMPLETE)/readme~
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
SONO STATI CALCOALTI ERRORI SU READ,WRITE,CONNECT,SIGNALS
|
||||||
|
|
||||||
|
il server gestisce un file archivio.txt
|
||||||
|
|
||||||
|
il client puo inviare:
|
||||||
|
BYE - per chiudere la connessione
|
||||||
|
AGGIUNGI <NOME> <VOTO> - per far aggiungere un nome al server
|
||||||
|
VERIFICA <NOME> - per verificare se un nome è presente nel database del server
|
||||||
|
|
||||||
|
il server risponde:
|
||||||
|
BYE - A BYE
|
||||||
|
AGGIUNTO - AL COMANDO AGGIUNGI DEL CLIENT
|
||||||
|
EVENTUALI INFORMAZIONI SUI DATI - AL COMADNO VERIFICA
|
||||||
BIN
11.client-server-exam-database (COMPLETE)/server
Executable file
BIN
11.client-server-exam-database (COMPLETE)/server
Executable file
Binary file not shown.
Binary file not shown.
@@ -1,106 +0,0 @@
|
|||||||
#include "../basic.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void sigpipeaction (int signal){
|
|
||||||
|
|
||||||
int status, pid;
|
|
||||||
|
|
||||||
fprintf(stderr, "Sigpipe catturato\n");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct sigaction sigpipestructure;
|
|
||||||
sigpipestructure.sa_handler = sigpipeaction;
|
|
||||||
sigpipestructure.sa_flags = 0;
|
|
||||||
|
|
||||||
sigaction (SIGPIPE, &sigpipestructure, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
siginterrupt (SIGPIPE,1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int sockfd;
|
|
||||||
struct sockaddr_in servaddr;
|
|
||||||
|
|
||||||
if (argc != 3){
|
|
||||||
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
|
||||||
printf("socket error\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
bzero(&servaddr, sizeof(servaddr));
|
|
||||||
servaddr.sin_family = AF_INET;
|
|
||||||
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
|
||||||
|
|
||||||
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
|
||||||
printf("inet_pton error for %s\n", argv[1]);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
|
||||||
printf("connect error\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_in r_server_local_addr;
|
|
||||||
unsigned int r_server_local_addr_len = sizeof(r_server_local_addr);
|
|
||||||
|
|
||||||
char * socket_buffer = (char *) malloc (r_server_local_addr_len) ;
|
|
||||||
int ridden;
|
|
||||||
int written;
|
|
||||||
|
|
||||||
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for ( i = 0; i < 5; i ++){
|
|
||||||
|
|
||||||
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
|
||||||
if (ridden < 0){
|
|
||||||
fprintf(stdout,"Errore durante la lettura\n");
|
|
||||||
exit(-1);
|
|
||||||
} else {
|
|
||||||
fprintf(stdout,"Ho letto %d bytes\n",ridden);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( i = 0; i < 1; i ++){
|
|
||||||
|
|
||||||
written = write (sockfd, socket_buffer,r_server_local_addr_len /2 );
|
|
||||||
if (written < 0){
|
|
||||||
fprintf(stdout,"Errore durante la scrittura\n");
|
|
||||||
exit(-1);
|
|
||||||
} else {
|
|
||||||
fprintf(stdout,"Ho scritto %d bytes\n",written);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len);
|
|
||||||
|
|
||||||
|
|
||||||
char buff[INET_ADDRSTRLEN];
|
|
||||||
short port;
|
|
||||||
|
|
||||||
inet_ntop(AF_INET, &(r_server_local_addr.sin_addr), buff, INET_ADDRSTRLEN);// get ip
|
|
||||||
port = ntohs(r_server_local_addr.sin_port);// get port
|
|
||||||
|
|
||||||
fprintf (stdout,"%s%c%hu\n",buff,':',port);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
fun-corso-reti.o
Normal file
BIN
fun-corso-reti.o
Normal file
Binary file not shown.
BIN
test/test2
Executable file
BIN
test/test2
Executable file
Binary file not shown.
24
test/test2.c
Normal file
24
test/test2.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main (int index, char** in_data){
|
||||||
|
|
||||||
|
char a [100];
|
||||||
|
char b;
|
||||||
|
char c [100];
|
||||||
|
char d [100];
|
||||||
|
sprintf(d,"eeee");
|
||||||
|
sprintf(a,"alfred ");
|
||||||
|
sscanf (a,"%s%s",c,d);
|
||||||
|
fprintf(stdout,"%s\n",c);
|
||||||
|
fprintf(stdout,"%s\n",d);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
24
test/test2.c~
Normal file
24
test/test2.c~
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main (int index, char** in_data){
|
||||||
|
|
||||||
|
char a [100];
|
||||||
|
char b;
|
||||||
|
char c [100];
|
||||||
|
char d [100];
|
||||||
|
sprint(d,"eeee");
|
||||||
|
sprintf(a,"alfred ");
|
||||||
|
sscanf (a,"%s%s",c,d);
|
||||||
|
fprintf(stdout,"%s\n",c);
|
||||||
|
fprintf(stdout,"%s\n",d);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user