In the first version you pass the null pointer to inet_aton
. Then inet_aton
attempts to write to that address and that leads to the segfault.
inet_aton(ptr,hipaddr);//hipaddr is NULL
You need to pass a pointer to an in_addr
struct when you call inet_aton
. Which is what you do in the second version.
struct in_addr hipaddr;
inet_aton(ptr, &hipaddr);&hipaddr is a pointer to struct in_addr