inet_aton 0x0 in integer in structure
Mirko Banchi
mk.banchi@gmail.com
Thu May 11 18:46:00 GMT 2017
You need to declare a struct in_addr, not a struct in_addr*.
struct in_addr ipaddr;
...
valide = inet_aton (name, &ipaddr);
M.
> Il giorno 11 mag 2017, alle ore 20:38, alleswirdbesser@posteo.de ha scritto:
>
> I used inet_aton, received 1, expected an integer in the structure. Why is it 0x0?
>
> (gdb) break 12
> Breakpoint 1 at 0x10494: file main.c, line 12.
> (gdb) r
> Starting program: /home/pi/minimal Examples/a.out
>
> Breakpoint 1, main () at main.c:12
> 12 printf ("valide: %d. \nIP-Adresse: %d", valide, (*ipaddr).s_addr );
> (gdb) print valide
> $1 = 1
> (gdb) print (*ipaddr).s_addr
> Cannot access memory at address 0x0
> (gdb)
>
> #include <stdio.h>
> #include <netinet/in.h>
> #include <arpa/inet.h>
> #include <sys/socket.h>
>
> int main ()
> {
> const char *name="201.23.23.44";
> struct in_addr *ipaddr;
> int valide;
> valide = inet_aton (name, ipaddr);
> printf ("valide: %d. \nIP-Adresse: %d", valide, (*ipaddr).s_addr );
> return 0;
> }
>
>
More information about the Libc-help
mailing list