Thread: understanding macro __SOCKADDR_COMMON (sa_);

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    understanding macro __SOCKADDR_COMMON (sa_);

    Hi all:

    Can someone help me to understand this piece of code please? its part of the TCP/IP api. What's the purpose of the macro __SOCKADDR_COMMON in the sockaddr struct ? does that macro apply to the data menbers of the struct ?

    Further more, what should I read to understand this coding format ? I've been reading C books but every time I get into Linux libraries I find myself in front of code that I can not understand...


    Code:
    typedef unsigned short int sa_family_t;
    
    #define	__SOCKADDR_COMMON(sa_prefix) \
    sa_family_t   sa_prefix
    
    struct sockaddr
    {
            __SOCKADDR_COMMON (sa_);	/* Common data: address family and length.  */
            char sa_data[14];		        /* Address data.  */
    };
    Thanks to all.

  2. #2
    Banned
    Join Date
    Jan 2009
    Posts
    30
    To put it in over-simplified terms: since C does not support inheritence, this is the closest thing you can do to achieving that result.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why it is done like that, I have no answer to , but what it really means is that the struct looks like this:
    Code:
    struct sockaddr
    {
            sa_family_t   sa_;
            char sa_data[14];		        /* Address data.  */
    };
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. 1337 bible, Gen 11
    By Paz_Rax in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-20-2005, 09:40 PM
  5. need help with multi line macro usage
    By Cdigitproc1 in forum C Programming
    Replies: 9
    Last Post: 04-29-2005, 09:50 AM