Thread: warning problem: passing argument 2 of ‘signal’ from incompatible pointer type

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    20

    Post warning problem: passing argument 2 of ‘signal’ from incompatible pointer type

    hello,
    I am trying for watch syn packet on my network. After compile my program getting this problem
    warning: passing argument 2 of ‘signal’ from incompatible pointer type
    Actually i used header file #include <linux.h> then getting this warning here

    Code:
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    {
    
    	int alarmHandler();
    	unsigned nameResolve(char *);
    	
    	register int retcode,j=0;
    	struct icmphdr *icmp;
    	struct sockaddr_in sin;
    	unsigned char sendICMPpak[MAXPAK]={0};
    	unsigned short pakID=getpid()&0xffff;
    
    	struct ippkt{
       		struct iphdr ip;
       		struct icmphdr icmp;
       		char buffer[MAXPAK];
    	}pkt;
    
    	bzero((char *)&sin,sizeof(sin));
    	sin.sin_family=AF_INET;
    	sin.sin_addr.s_addr=nameResolve(dest);
    
    		/* ICMP Packet assembly  */
    	/* We let the kernel create our IP header as it is legit */
    
    	icmp=(struct icmphdr *)sendICMPpak;
    	icmp->type=ICMP_ECHO;			/* Requesting an Echo */
    	icmp->code=0;				/* 0 for ICMP ECHO/ECHO_REPLY */
    	icmp->un.echo.id=pakID;			/* To identify upon return */	
    	icmp->un.echo.sequence=0;		/* Not used for us */
    	icmp->checksum=in_cksum((unsigned short *)icmp,64);
    
    	fprintf(stderr,"sending ICMP_ECHO packets: ");
    	for(;j<amount;j++){
    		usleep(ICMPSLEEP);		/* For good measure */
    		retcode=sendto(sock,sendICMPpak,64,0,(struct sockaddr *)&sin,sizeof(sin));
    		if(retcode<0||retcode!=64)
    			if(retcode<0){
    				perror("ICMP sendto err");
    				exit(1);
    			}
    			else fprintf(stderr,"Only wrote %d bytes",retcode);
    		else fprintf(stderr,".");
    	}
    	HANDLERCODE=1;
    	signal(SIGALRM,alarmHandler);	/* catch the ALARM and handle it */
    	fprintf(stderr,"\nSetting alarm timeout for 10 seconds...\n");
    	alarm(10);	/* ALARM is set b/c read() will block forever if no */
    	while(1){	/* packets arrive...   (which is what we want....)  */
    		read(sock,(struct ippkt *)&pkt,MAXPAK-1);
      		if(pkt.icmp.type==ICMP_ECHOREPLY&&icmp->un.echo.id==pakID){
    			if(!HANDLERCODE)return(0);
    			return(1);
    		}
      	}	
    }
    
    
    /* 
     *	SIGALRM signal handler.  Souper simple.
     */ 
    int alarmHandler(){
    
    	HANDLERCODE=0;		/* shame on me for using global vars */
    	alarm(0);
    	signal(SIGALRM,SIG_DFL);
    	return(0);
    }
    but i thought may be header file should be #include <linux/signal.h> then getting this problem
    Code:
    In file included from /usr/include/asm/signal.h:7,
                     from /usr/include/linux/signal.h:4,
                     from neptune.c:67:
    /usr/include/asm-i386/signal.h:13: error: conflicting types for ‘sigset_t’
    /usr/include/sys/select.h:38: error: previous declaration of ‘sigset_t’ was here
    I checked all the path signal.h. all in the right place.
    please help me for solve this problem.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    According to man signal, the second parameter of signal should be a pointer-to-function-returning-void-taking-int, while you have pointer-to-function-returning-int-taking-void, which is not the same thing.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Is it _REALLY_ a requirement for your code to compile on non-ANSI compilers? I would recommend using modern ANSI function argument definition:
    Not this:
    Code:
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    but this:
    Code:
    int slickPing(int amount, int sock,char *dest)
    It won't change much of your code, but it makes it neater and easier to read (and you'll never have the problem that you added an extra argument that you forgot to put in the type declaration section between ) and {, which means that it's the default type of int and you get strange compile errors).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM