🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Network programming in C++

Started by
1 comment, last by Shadowdancer 24 years ago
Hi. I'm trying to port my networking routines to C++, but it doesn't seem to work. I'm using something like

struct sockaddr_in MySocket;
int SocketHandle

MySocket.sin_port=22333;

// protocol_number is set correctly
SocketHandle=socket( AF_INET, SOCK_STREAM, protocol_number );
bind( SocketHandle, &MySocket, sizeof( MySocket ) );
 
The compiler doesn't like this. It's telling me that it can't convert between sockaddr_in and sockaddr (which is the type specified in the syntax of bind). Trying to cast this, even with reinterpret_cast or via a void pointer fail. In pure C, this was no problem. The trouble is that I have to set MySocket.sin_port which isn't defined in the normal sockaddr structure. Does anyone know how to fix this? --- ls -lR/rm -rf / (Best compression everywhere. Kids, don't try this as root.) Edited by - Shadowdancer on 6/25/00 10:24:39 AM Edited by - Shadowdancer on 6/25/00 10:26:25 AM
Advertisement
try:

struct sockaddr_in *MySocket;int SocketHandleMySocket->sin_port=22333;// protocol_number is set correctlySocketHandle=socket( AF_INET, SOCK_STREAM, protocol_number );bind( SocketHandle, (sockaddr *)MySocket, sizeof( MySocket ) ); 


(Cast MySocket to type sockaddr instead of sockaddr_in)

Mark Collins (aka Nurgle)
me@thisisnurgle.org.uk

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

Hey, thanks that fixed it. Guess I''ll have to re-read that chapter about using pointers...

---
ls -lR|rm -rf /
(Best compression everywhere. Kids, don''t try this as root.)

This topic is closed to new replies.

Advertisement