LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   segmentation fault inet_ntop() (https://www.linuxquestions.org/questions/linux-newbie-8/segmentation-fault-inet_ntop-931535/)

aspiring_stellar 02-27-2012 08:09 AM

segmentation fault inet_ntop()
 
Hi all,
I am getting segmentation fault in
inet_ntop(AF_INET6, &src, source, 40);

variables are declared as:
char *source;
struct in6_addr src;

Using g++ compiler to compile c++ source.
Any help?

lisle2011 02-28-2012 09:10 PM

Segfault
 
A piece of code is trying to use the same chunk of memory as another piece if code. You need to debug it. Configure GCC with --enable-checking . Compile it with -g -O0 so that you can use gdb. There are lots of pieces of advice on this particular subject as almost no-one who learns C or C++ doesn't get segfaults. You should track it down and if you compile it so gdb can do it's work you will have a 'Eureka' moment. But just a moment. The snippet of code, although well intentioned is not helpful. Good luck because you will overcome this hurdle.



If I helped at all give me a pat on the back (add to my reputation)

aspiring_stellar 02-29-2012 02:43 AM

I have already tried gdb and got the exact location of seg fault using this only. gdb traceback shows seg fault in the line inet_ntop(AF_INET6, &src, source, 40);

Strangely, the same code works fine with gcc but not with g++. I need to get it working in c++.

lisle2011 02-29-2012 10:49 AM

Segfault in internet address function
 
Here is a page with examples and explanation, perhaps you see what is wrong with your code. More code would have been better.

the objective is turn the machine readable address into human readable.


All times are GMT -5. The time now is 01:43 PM.