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

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

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

    hello,
    why i am getting this warning? how can i solve this............

    warning: passing argument 2 of ‘signal’ from incompatible pointer type
    getting warning in redline

    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);
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    From Russia: http://psb.sbras.ru/cgi-bin/www/unix...x-man?signal+3

    SYNOPSIS
    #include <signal.h>

    void (*
    signal(int sig, void (*func)(int)))(int);

    or in FreeBSD's equivalent but easier to read typedef'd version:

    typedef void (*sig_t) (int)

    sig_t
    signal(int sig, sig_t func);
    It's clear that your handler function has the wrong prototype; pass something compatible (a sig_t).
    Last edited by whiteflags; 04-14-2008 at 11:24 PM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    it means that alarmHandler has to have following prototype:

    Code:
    void alarmHandler(int param);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    {
    Better to use ISO C definitions:

    Code:
    int slickPing(int amount, int sock, char* dest)
    {
    And the warning is because it really shouldn't compile because you are passing a pointer to a function that doesn't match what signal wants or expects.
    Vart points out the correct solution there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  2. Replies: 5
    Last Post: 08-12-2007, 05:26 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM