inet_ntoa and segmentation fault

inet_ntoa and segmentation fault

Shachar Shemesh shachar at shemesh.biz
Wed Jul 15 16:29:27 IDT 2009


Today was the second time that I ran across this problem. Each time I 
run across it, I search Google, come back empty handed, and then have a 
second look, find the solution, and altogether waste too much time on a 
problem I have solved before. As a measure to prevent this, I am posting 
both problem and solution to this mailing list, that has a high Google 
juice, so that the next time, I will find my own solution.

In other words, I am shamelessly using the list to archive my problems 
and solutions.

The problem:
The following code segfaults:
    printf("%s\n", inet_ntoa(addr) );

The cause: Failing to include the relevant header file.

The solution: Add:
#include <arpa/inet.h>

Sorry for the noise.
Shachar

-- 
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20090715/8ab04ecc/attachment.html>


More information about the Linux-il mailing list