🎉 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!

Multiple Network Cards

Started by
2 comments, last by Guardian_Light 22 years, 7 months ago
The software in this problem is of a client/server model. I am trying to run the server application from my home computer. This computer has two network cards (one for my internal network, the other to my internet connecion). My network code base is Winsock (version 2). WIN98se picks my internal network card as the default. I need to use the card connected to the internet. Is there a way in which I can choose a network adapter through the winsock API? Thanks, Michael Sikora
Advertisement
If you have two network cards in your PC then each network card should have a different IP address, one supplied by your ISP for the internet and one (that you have supplied) for your internal home network - there are allocated IP addresses for local networks; i think they begin 192.168.... but I would need to look it up.

Anyway, if you want to use the network adapter connected to the internet connection, use its IP in the sockaddr_in structure. If you want to use your internal network adapter, use its IP in the sockaddr_in structure.

That should work fine.

henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Thank you for your reply, I was using ...

ServerAddress.sin_addr.s_addr = htonl(INADDR_ANY);

I see how it works, hmpf. Thanks again, took me 5 minutes and now I''m up and running =)

"So much fun, so little time."
~Michael Sikora
I''m just starting into WinSock2 myself, but I tend to stick to the BSD Socket commands since I have a little more experience with networking on Unix. In any event, are you using INAPPR_ANY in your bind() call?

I guess your ways of getting the Ext IP address would be to either read in a value at command execution (.ini file or parameter by Cmd line). If you passed the external IP, then you could bind to that.

Alternatively, you could use gethostbyname(). It returns a hostent struct, which includes h_addr_list, which is a null-terminated list of addresses for the host. Since your machine should have its HOSTS file configured with both interfaces, you should get both addresses from this call when you pass your local machine name, which you can also get dynamically with the Win32API. Then you could let the user select which address to use for the bind() call.

There might be a quicker call in the Winsock2 API to get the list of addresses available on the computer, but I don''t know of anything besides this method on Unix (besides reading the host file or doing some calls to the system to get the network configuration).

Check out www.msdn.microsoft.com/library. Then find "Network and Directory Services" -> "Network Protocols" -> "Windows Sockets" -> "SDK Documentation." You''ll find the Winsock 2 API there. Sorry if you already knew this and I insulted you by posting it. No offense intended.

G''luck.

R

This topic is closed to new replies.

Advertisement