This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inet_aton 0x0 in integer in structure


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;
> }
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]