Advertisement

Network Programming

Started by May 09, 2000 07:27 AM
0 comments, last by oWen 24 years, 7 months ago
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
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.

This topic is closed to new replies.

Advertisement