Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining structure definitions using man pages

Is it possible to view structure definitions using man pages the way we can see function definitions in UNIX?

For instance, for network programming, we use a structure called struct sockaddr_in . Is there anyway to see how sockaddr_in has been defined in the library using man pages?

Any help will be appreciated! Thanks!

like image 984
Amal Antony Avatar asked Nov 20 '11 12:11

Amal Antony


3 Answers

For any given header:

echo '#include <netinet/in.h>' | gcc -E - | less

Which generates of relevant interest:

# 225 "/usr/include/netinet/in.h" 3 4
struct sockaddr_in
  {
    sa_family_t sin_family;
    in_port_t sin_port;
    struct in_addr sin_addr;


    unsigned char sin_zero[sizeof (struct sockaddr) -
      (sizeof (unsigned short int)) -
      sizeof (in_port_t) -
      sizeof (struct in_addr)];
  };

This can be done using any compiler with a preprocessor option (every C compiler I know of can do this).

like image 155
Matt Joiner Avatar answered Nov 02 '22 09:11

Matt Joiner


It depends on the function. For example, you can get the definition of struct sockaddr by looking at the man page of bind(2).

Unfortunately, there's no man page specifically for struct sockaddr.

Other ways to get this information would be to search for it the appropriate header files.

like image 4
Anthony Avatar answered Nov 02 '22 08:11

Anthony


man-pages is just a files written by human or generated by wish of human. Usually all related structures is mentioned in man-pages with functions they used with. Sometimes you can find pages for header-files ( time.h(0p) ). Sometimes there is pages for a whole libraries ( libsensors(3) ). Sometimes there is actual pages for structures ( XAnyEvent(3) ).

You may want to check apropos and whatis. Sometimes they able to find pages related with what you are looking for.

like image 2
ony Avatar answered Nov 02 '22 09:11

ony