We help IT Professionals succeed at work.
Get Started

how is the sockaddr struct defined

Last Modified: 2012-05-09
I am teaching myself socket programming in C.  I understand how to do the stuff I need to get sockets working and cummunicating.  My question is more about how something underlying works.

in most socket functions you have to cast your address structure to a generic pointer to a sockaddr struct.

My question is how does the definition for the sockaddr struct work and what does the compiler do when it comes upon this "(struct sockaddr *)sockaddr_*"

I have looked at socket.h and I find this a transparent union...  I dont understand much of the transparent union but I am trying to see how that union can be used to cast different size/variable size address structures to a generic sockaddr struct.  

Any one have an idea?
Watch Question
Software Engineering and Matlab Analyst
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE