View Single Post
Old Mar 1st, 2008, 7:51 PM   #2
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Simple BSD Sockets Problem

Where is your server code?

Well you aren't check the return of "gethostbyname" which could very well be NULL. That would be a quick crash. You also don't zero out you sockaddr_in structure before using it. Here is some code I have that does a similar thing:
cpp Syntax (Toggle Plain Text)
  1. memset(&m_addr, 0, sizeof(m_addr));
  2. m_addr.sin_family = AF_INET; // host byte order
  3. m_addr.sin_port = htons(port); // short, network byte order
  4. m_addr.sin_addr = *((struct in_addr *)he->h_addr);

I think you are trying to do something simular with this:
cpp Syntax (Toggle Plain Text)
  1. memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);

Wikipedia has good article here.
__________________
Robotics @ Maryland AUV Team - Software Lead
Game_Ender is offline   Reply With Quote