Saturday, October 16, 2010

inet_ntoa() segmentation fault issue

inet_ntoa is a UNIX system call used in socket programming to obtain an IPv4 string form of an IP address from its in_addr form.

I have encountered an issue where its use results in the following warning:

warning: assignment makes pointer from integer without a cast

Attempting to run a program with this warning on inet_ntoa will result in a segmentation fault.

The cause of the problem is not incorrect C, but a missing header file. Shachar Shemesh wrote that the solution to this obscure problem is simply to include the arpa/inet.h header file:

#include <arpa/inet.h>

4 comments:

  1. Thank you SOOOO much for this, was pulling my hair out :)

    ReplyDelete
  2. Me too, I'd never have found the solution to this under osx without this post!

    Colum

    ReplyDelete
  3. You are awesome!!!.....spend a lot of time on the issue....header file inclusion worked!!

    Can you please explain why it works?

    Thanks,
    Prasad

    ReplyDelete
  4. I'm afraid I don't know how to answer that. Do post here if you find out.

    ReplyDelete