我正在尝试在 C 中使用 gethostbyname() 函数进行网络分配。
当我尝试这样做时
struct hostent *host;
char* addr = malloc (10*sizeof(char));
strcpy (addr, "localhost");
host= (struct hostent *) gethostbyname(addr);
我收到以下错误。
glibc detected ./Sender: free(): invalid next size (normal): 0x0000000001584480 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7fcdbaca4b96]
/lib/x86_64-linux-gnu/libc.so.6(fclose+0x155)[0x7fcdbac94815]
/lib/x86_64-linux-gnu/libc.so.6(+0x103b16)[0x7fcdbad29b16]
/lib/x86_64-linux-gnu/libc.so.6(__res_maybe_init+0x125)[0x7fcdbad2b3d5]
/lib/x86_64-linux-gnu/libc.so.6(__nss_hostname_digits_dots+0x3d)[0x7fcdbad2db0d]
/lib/x86_64-linux-gnu/libc.so.6(gethostbyname+0x8b)[0x7fcdbad32b7b]
./Sender[0x401858]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fcdbac4776d]
./Sender[0x400a09]
======= Memory map: ========
00400000-00403000 r-xp 00000000 08:07 3573874 /home/karthik/courses/Sem 6/Networks/Lab/lab4/Sender
00602000-00603000 r--p 00002000 08:07 3573874 /home/karthik/courses/Sem 6/Networks/Lab/lab4/Sender
00603000-00604000 rw-p 00003000 08:07 3573874 /home/karthik/courses/Sem 6/Networks/Lab/lab4/Sender
01584000-015a5000 rw-p 00000000 00:00 0 [heap]
7fcdbaa10000-7fcdbaa25000 r-xp 00000000 08:08 525634 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcdbaa25000-7fcdbac24000 ---p 00015000 08:08 525634 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcdbac24000-7fcdbac25000 r--p 00014000 08:08 525634 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcdbac25000-7fcdbac26000 rw-p 00015000 08:08 525634 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcdbac26000-7fcdbaddb000 r-xp 00000000 08:08 541113 /lib/x86_64-linux-gnu/libc-2.15.so
7fcdbaddb000-7fcdbafda000 ---p 001b5000 08:08 541113 /lib/x86_64-linux-gnu/libc-2.15.so
7fcdbafda000-7fcdbafde000 r--p 001b4000 08:08 541113 /lib/x86_64-linux-gnu/libc-2.15.so
7fcdbafde000-7fcdbafe0000 rw-p 001b8000 08:08 541113 /lib/x86_64-linux-gnu/libc-2.15.so
7fcdbafe0000-7fcdbafe5000 rw-p 00000000 00:00 0
7fcdbafe5000-7fcdbb007000 r-xp 00000000 08:08 545991 /lib/x86_64-linux-gnu/ld-2.15.so
7fcdbb1e4000-7fcdbb1e7000 rw-p 00000000 00:00 0
7fcdbb203000-7fcdbb207000 rw-p 00000000 00:00 0
7fcdbb207000-7fcdbb208000 r--p 00022000 08:08 545991 /lib/x86_64-linux-gnu/ld-2.15.so
7fcdbb208000-7fcdbb20a000 rw-p 00023000 08:08 545991 /lib/x86_64-linux-gnu/ld-2.15.so
7fff5c673000-7fff5c695000 rw-p 00000000 00:00 0 [stack]
7fff5c7ff000-7fff5c800000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)`
我该如何解决这个问题?