I have a question: I try to use the systemcall gethostname( char *name, size_t size ) but I get some results I don't understand:
char *hostname;
gethostname( hostname, size ); //results in a segmentation error
gethostname( &hostname, size ); //works fine.
Why should I use the & sign here? gethostname asks for a pointer, but hostname is already a pointer. I just got the result by accident and have no idea why the first call doesn't work. Sorry if this is a dumb question.
[EDIT] The answer is: hostname did not allocate any memory yet and therefore, the gethostname tried to access non-allocated memory, raising the segmentation error. Furthermore, the second LOC did not work legally either, it overwrote other data on the stack and therefore corrupted it. The way to use it is to first allocate some memory and then pass it to gethostname systemcall.
Thanks for your time and information guys! :)
char**.