• Advertisement

Archived

This topic is now archived and is closed to further replies.

Multiple Network Cards

This topic is 5909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement