tags:

views:

99

answers:

2

I'm attempting to create a wrapper around libdnet for the D programming language. The issue I have run into is not knowing what the underlining types for eth_addr_t, ip_addr_t, and ip6_addr_t while converting addr.h. The last mystery type is sockaddr

And I'm also interest in why there is a do while loop that is always false.

#define addr_pack(addr, type, bits, data, len) do { \
    (addr)->addr_type = type; \
    (addr)->addr_bits = bits; \
    memmove((addr)->addr_data8, (char *)data, len); \
} while (0)

is it required for C to execute the code in the macro?

+1  A: 

That is a define macro for the c preprocessor. Those backslashes at the end is because is its all one definition that spans multiple lines. A do while loop is like a while loop with the exception of the evaluation is done at the end allowing it to always execute at least once. In this case the developer has used that while loop as a kind of hack to allow his code to be put into its own scope.

From eth.h in the same directory:

typedef struct eth_addr {
        uint8_t         data[ETH_ADDR_LEN];
} eth_addr_t;

ip.h:

typedef uint32_t        ip_addr_t;

ip6.h:

typedef struct ip6_addr {
        uint8_t         data[IP6_ADDR_LEN];
} ip6_addr_t;

honeyd-1.1.1/unused/WinSock.h:

/*
 * Structure used by kernel to store most
 * addresses.
 */
struct sockaddr {
        u_short sa_family;              /* address family */
        char    sa_data[14];            /* up to 14 bytes of direct address */
};
Tim Matthews
Thanks, spent lots of time using grep and Google yesterday, just didn't know what I was looking for. Also I think the sockaddr I'm looking for is from sys/socket.h
he_the_great
A: 

Have you taken a look at htod?

BCS