0

So, I'm reading Beej's Guide to Network Programming, and he uses this function:

void *get_in_addr(struct sockaddr *sa)
{
    if (sa->sa_family == AF_INET) {
    return &(((struct sockaddr_in*)sa)->sin_addr);
}

So, I get what its doing in general. What I'm having trouble understanding is what exactly the * in the function declaration is doing. Also, this function seems to be returning a memory location, but its void. Whats going on here?

Nick
  • 371
  • 2
  • 14
  • 3
    Does it help if I write it like this: `void* get_in_addr(struct sockaddr *sa)` – Benjamin Lindley Sep 28 '13 at 01:10
  • 2
    This has the answer: http://stackoverflow.com/questions/4334831/what-is-a-void-pointer-and-what-is-a-null-pointer – shunyo Sep 28 '13 at 01:10
  • Not being funny, but network programming is going to be pretty tough without having a basic understanding of C. – Crowman Sep 28 '13 at 01:13
  • 1
    @PaulGriffiths I hear ya. I actually do have a fairly good understanding of C/C++, its just I've never come across this syntax before. I know I have holes in my knowledge, but hey, I'm in school. Now is the time to fill in the gaps, not say "Oh, I don't know about this, so I shouldn't even try." I appreciate your input, none the less. – Nick Sep 28 '13 at 01:19
  • @Nick: OK. Pointers are really, really fundamental to C. Good luck with your studies. – Crowman Sep 28 '13 at 01:20

1 Answers1

4

The '*' means that the function is returning a void *. This is a pointer which can be cast to any other pointer.

No One in Particular
  • 2,846
  • 4
  • 27
  • 32