Reputation: 1063
I'm following Beej's Guide to Network Programming, and I'm using VC++ 2010, but when I copy paste the structs into my program, some of the types come up as incorrect identifiers. For example:
u_int32_t
came up as that, and after some searching I found out those are old types from the C language circa 1999. I could have just included stdint.h, but that would require me to remember what they meant. Instead I used the standard int
, which is 32 bits long (4 bytes), and for the other ones which are 64 bits long (8 bytes), I used long long int
.
Anyways, I'm narrowing down to my last syntax error and it says sa_family_t
is an invalid indentifier. I don't have a clue what its supposed to be and searching has turned up nothing. That's my problem, I don't know what I should specify for a type identifier for that.
Another thing that's bothering me is this: char __ss_pad1[_SS_PAD1SIZE];
The SS_PAD1SIZE
thing comes up in red as invalid too.
Upvotes: 5
Views: 22392
Reputation: 2065
In case anyone arrives at this answer and is looking for sa_family_t;
under Linux, it is defined here:
typedef __kernel_sa_family_t sa_family_t;
In turn, __kernel_sa_family_t
is defined here:
typedef unsigned short __kernel_sa_family_t;
So ultimately, sa_family_t
is an unsigned short
, i.e. 2 bytes. This brings the entire struct sockaddr
to a neat 16 bytes:
struct sockaddr {
sa_family_t sa_family; // unsigned short
char sa_data[14];
Upvotes: 5
Reputation: 6846
sa_family_t should be an unsigned integer. The Windows header files don't conform to that standard. Winsock.h defines the sockaddr struct as follows:
struct sockaddr {
u_short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
};
So to compile your code you're going to need to typedef sa_family_t yourself.
Upvotes: 8