2

I am reading about socket programming and got to know that ip is assigned to socket with bind() call before connection to server.Is my thinking of binding address means to bind any ip address correct.

asked Sep 2, 2016 at 14:05
1
  • If your country uses a proxy to restrict which sites you can access, then it is very likely that all connections between a computer physically within your country to a computer physically outside your country must go through that proxy. Commented Sep 2, 2016 at 14:37

1 Answer 1

1

bind() defines a relationship between the socket you created and the addresses that are available on your host. For example you can bind a socket on all addresses or on a specific IP which has been configured on a network adapter by the host's operating system.

Here is an example how to bind a socket to all available addresses on the host that runs this code:

struct sockaddr_in name;
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind (socket, (struct sockaddr *) &name, sizeof (name)) < 0) {
 perror ("bind");
 exit (-1);
}

For a server application, users sometimes like to restrict the socket to be bound only to a certain address for security reasons or just to map the services where they want them to be available. This is why most servers allow to configure bind addresses for the users easily with the application's configuration file.

answered Sep 4, 2016 at 7:20
2
  • so as a client i can only bind my ip address or any ip address Commented Sep 4, 2016 at 7:22
  • There is already an answered question about this here: stackoverflow.com/q/12763268/6769270 Commented Sep 4, 2016 at 7:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.