Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:24:41+00:00 2026-06-06T16:24:41+00:00

This is my program: int main(int argc, char *argv[]){ if(argc != 2){ printf(Uso: ./server

  • 0

This is my program:

 int main(int argc, char *argv[]){
    if(argc != 2){
        printf("Uso: ./server <numero porta>\n");
        exit(1);
    }
    int sockd, newsockd, LunghezzaClient;
    int NumPorta = atoi(argv[1]);
    struct sockaddr_in serv_addr, cli_addr; /* indirizzo del server e del client */
    int rc, fd;
    off_t offset = 0;
    struct stat stat_buf;
    char filename[1024] = {};
    size_t fsize;

    if((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
        perror("Errore creazione socket\n");
        exit(EXIT_FAILURE);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr)); /* bzero scrive dei null bytes dove specificato per la lunghezza specificata */
    serv_addr.sin_family = AF_INET; /* la famiglia dei protocolli */
    serv_addr.sin_port = htons(NumPorta); /* porta htons converte nell'ordine dei byte di rete */
    serv_addr.sin_addr.s_addr = INADDR_ANY; /* dato che è un server bisogna associargli l'indirizzo della macchina su cui sta girando */

    if(bind(sockd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0){
        perror("Errore di bind\n");
        onexit(NULL, sockd, NULL, 1);
    }

    if(listen(sockd, 5) < 0){
            perror("Errore nella funzione listen");
            onexit(NULL, sockd, NULL, 1);
    }
    LunghezzaClient = sizeof(cli_addr);
    signal (SIGINT, ( void *)sig_handler); 
    while(1){
        if((newsockd = accept(sockd, (struct sockaddr *) &cli_addr, (socklen_t *) &LunghezzaClient)) < 0){
            perror("Errore nella connessione\n");
            onexit(newsockd, sockd, NULL, 2);
        }

        /* get the file name from the client */
        if((rc = recv(newsockd, filename, sizeof(filename), 0)) < 0){
            perror("Errore nella ricezione del nome del file");
            onexit(newsockd, sockd, NULL, 2);
        }

        /* Terminiamo il nome del file con NULL e se ultimo carattere è \n o \r lo cambiamo con \0*/
        filename[rc] = '\0';
        if (filename[strlen(filename)-1] == '\n')
            filename[strlen(filename)-1] = '\0';
        if (filename[strlen(filename)-1] == '\r')
            filename[strlen(filename)-1] = '\0';

        /* inet_ntoa converte un hostname in un ip decimale puntato */
        fprintf(stderr, "Ricevuta richiesta di inviare il file '%s' dall' indirizzo %s\n", filename, inet_ntoa(cli_addr.sin_addr));

        /* open the file to be sent */
        fd = open(filename, O_RDONLY);
        if (fd < 0) {
            fprintf(stderr, "Impossibile aprire '%s': %s\n", filename, strerror(errno));
            onexit(newsockd, sockd, NULL, 2);
        }

        /* get the size of the file to be sent */
        if(fstat(fd, &stat_buf) < 0){
            perror("Errore fstat");
            onexit(newsockd, sockd, fd, 3);
        }
        fsize = stat_buf.st_size;
        if(send(newsockd, &fsize, sizeof(fsize), 0) < 0){
            perror("Errore durante l'invio della grandezza del file\n");
            onexit(newsockd, sockd, fd, 3);
        }
        /* copy file using sendfile */
        offset = 0;
        rc = sendfile(newsockd, fd, &offset, stat_buf.st_size);
        if (rc == -1) {
            fprintf(stderr, "Errore durante l'invio di: '%s'\n", strerror(errno));
            onexit(newsockd, sockd, fd, 3);
        }
        if (rc != fsize) {
            fprintf(stderr, "Trasferimento incompleto: %d di %d bytes\n", rc, (int)stat_buf.st_size);
            onexit(newsockd, sockd, fd, 3);
        }

        onexit(newsockd, NULL, fd, 4);
    }
    close(sockd);
    exit(EXIT_SUCCESS);
}

But when i try to compile it with gcc -Wall -O3 -o program myprogram.c i got a lot of warnings due too some mistakes into onexit function. Here’s the warnings i got:

server-iterativo.c: In function ‘main’:
server-iterativo.c:51:3: warning: passing argument 1 of ‘onexit’ makes integer from pointer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘int’ but argument is of type ‘void *’
server-iterativo.c:56:7: warning: passing argument 1 of ‘onexit’ makes integer from pointer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘int’ but argument is of type ‘void *’
server-iterativo.c:92:7: warning: passing argument 3 of ‘onexit’ makes pointer from integer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘struct FILE *’ but argument is of type ‘int’
server-iterativo.c:97:7: warning: passing argument 3 of ‘onexit’ makes pointer from integer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘struct FILE *’ but argument is of type ‘int’
server-iterativo.c:104:9: warning: passing argument 3 of ‘onexit’ makes pointer from integer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘struct FILE *’ but argument is of type ‘int’
server-iterativo.c:108:9: warning: passing argument 3 of ‘onexit’ makes pointer from integer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘struct FILE *’ but argument is of type ‘int’
server-iterativo.c:111:3: warning: passing argument 2 of ‘onexit’ makes integer from pointer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘int’ but argument is of type ‘void *’
server-iterativo.c:111:3: warning: passing argument 3 of ‘onexit’ makes pointer from integer without a cast [enabled by default]
server-iterativo.c:23:6: note: expected ‘struct FILE *’ but argument is of type ‘int’
server-iterativo.c: In function ‘onexit’:
server-iterativo.c:131:3: warning: passing argument 1 of ‘close’ makes integer from pointer without a cast [enabled by default]
/usr/include/unistd.h:354:12: note: expected ‘int’ but argument is of type ‘struct FILE *’
server-iterativo.c:136:3: warning: passing argument 1 of ‘close’ makes integer from pointer without a cast [enabled by default]
/usr/include/unistd.h:354:12: note: expected ‘int’ but argument is of type ‘struct FILE *’

I cannot understand why i got this errors 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:24:42+00:00Added an answer on June 6, 2026 at 4:24 pm

    The warning message looks clear enough:

    In the code that you removed, in main, you call your function onexit that expects its parameter 1 to be an int with a pointer. You should feed an int!


    Once again. You defined your own function onexit as follows:

    void onexit(int c, int s, FILE *fp, int flag);
    

    You choose that it wants as parameter 1 an int. Then, when you call it as follows:

    onexit(NULL, sockd, NULL, 1);
    

    You give it NULL as parameter 1, which is a pointer, not an int.

    Hence, the compiler warns you that it had to make an integer from a pointer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my program: #include <stdio.h> int main(int argc, char **argv) { printf(hello world\n);
I have this program in C: int main(int argc, char *argv[]) { int i=300;
#include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { printf(MySQL client version: %s\n,
I have the following program: int main(int argc, char *argv[]) { int a, b;
This is the main code of my server program in C: int main(int argc,
#include <cstdio> #include <QtCore/QProcess> int main (int argc, char** argv) { // if we
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main (int argc, const char * argv[])
I've always wondered how I could get away with this: int main(int argc, char
I have a simple C-program ./my_program #include <stdio.h> int main (int argc , char
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.