Jump to content
  • Advertisement

Archived

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

oWen

Network Programming

This topic is 6923 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

I''m trying to "bind" my ip address to an ip address on my system, but it''s not the one I''m using now. The server i''m connecting to only accpets connections from this address, so I have to use this ip address. Here''s what I tried, and it doesnt work I was unsure howto do this, so I just through somethings together and tested it. Any suggestions? struct sockaddr_in sl_sin; memset(&sl_sin, 0, sizeof(sl_sin)); int lfd, ret; sl_sin.sin_family = AF_INET; sl_sin.sin_port = 0; sl_sin.sin_addr.s_addr = inet_addr("219.31.213.12"); lfd = socket(AF_INET, SOCK_STREAM, 0); ret = bind(lfd, (struct sockaddr *) &sl_sin, sizeof(struct sockaddr)); ...I replaced the original ip with 219.31.213.12

Share this post


Link to post
Share on other sites
Advertisement
Um, the bind doesn''t work that way. bind() assigns a local interface protocol address to a socket. That is to say a call to bind() that doesn''t specify a valid IP on the host machine should return a socket error. In any case it sounds like you''re trying to connect to a foreign host. bind() is only useful for creating a socket on the local host.

In order to create a socket on an IP address, you need to actually have an interface with that IP address assigned. Otherwise it won''t handle ARPs properly. Sure you could forge packets to be sent that look like they come from a given IP address, but without and actual assigned interface you''ll never get any packets back.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!