This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: inet_aton 0x0 in integer in structure
- From: Mirko Banchi <mk dot banchi at gmail dot com>
- To: alleswirdbesser at posteo dot de
- Cc: libc-help at sourceware dot org
- Date: Thu, 11 May 2017 20:46:16 +0200
- Subject: Re: inet_aton 0x0 in integer in structure
- Authentication-results: sourceware.org; auth=none
- References: <4118714c1220c06d434f608997a8bb3c@posteo.de>
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;
> }
>
>