Reputation: 91
bind () error : Cannot assign requested address.
new_socket= socket(AF_INET, SOCK_DGRAM, 0);
localIP = "128.1.1.64";
memset(&socket_data, 0, sizeof(socket_data));
// Fill the socket structure
socket_data.sin_family = AF_INET;
socket_data.sin_addr.s_addr = inet_addr(localIP);
socket_data.sin_port = htons(PortNumber);
bind( new_socket, (struct sockaddr*) &socket_data, sizeof(socket_data))
Does any one know why the bind()
is failing?
Upvotes: 2
Views: 2795
Reputation: 597941
You can only bind()
to an IP that has been assigned to one of the network interfaces of the local machine.
Upvotes: 1
Reputation: 53
I guess 128.1.1.64 is an arbitrary IP which does not exist in any of your net interfaces. If you want to spoof the source IP, probably you need to use SOCK_RAW
instead.
Upvotes: 2