Thread: compiler warning with sprintf and inet_ntop

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    compiler warning with sprintf and inet_ntop

    hello, i have a bunch of string formatting using sprintf and inet_ntop such as:

    Code:
    sprintf(tmp, "Message received from: <ip>:%s <port>:%d", 
    			inet_ntop(client->addr.sin_addr), 
    			ntohs(client->addr.sin_port));
    (tmp is an adequately sized string where the string gets stored), when doing this i get a compiler warning:

    warning: format '%s' expects type 'char *', but argument 3 has type 'int'

    i can get rid of this warning by casting inet_ntop() to a char*:

    Code:
    sprintf(tmp, "Message received from: <ip>:%s <port>:%d", 
    			(char*)inet_ntop(client->addr.sin_addr), 
    			ntohs(client->addr.sin_port));
    but this seems weird to me as all the documentation i see that inet_ntop() returns a string. i'm trying to understand why the compiler throws this warning can any one help?
    regards,
    qualia
    Last edited by qualia; 08-19-2010 at 03:33 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    const char *inet_ntop(int af, const void *src,char *dst, socklen_t size);
    Do you forget to include header file?

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    hi yes,
    that was it, another silly mistake,
    thanks

Popular pages Recent additions subscribe to a feed