I am trying to change the source ip address for a tcp packet. Code snippet as given bellow
bzero(&clientaddr,sizeof(clientaddr));
clientaddr.sin_family = AF_INET;
clientaddr.sin_addr.s_addr=inet_addr("172.16.2.10");
clientaddr.sin_port=htons(8080);
if (bind(sockfd, (struct sockaddr *) &clientaddr,
sizeof(clientaddr)) < 0)
{
perror("bind");
}
Binding a particular port is working fine, but when i tried to bind with a diffrent ip adress, the bind is failing with error
bind: Cannot assign requested address
I also tried by setting the socket option as follows,]
setsockopt (sockfd, SOL_IP, IP_TRANSPARENT, &n1, sizeof(int));*
then also its failing with same error.
How could i change my source ip address for packet, originated from my PC. Please help me, its for a proxy application.
OS :Linux 2.6.37-tproxy #1 SMP Wed Apr 3 23:34:00 IST 2013 x86_64 x86_64 x86_64 GNU/Linux
Thanks in advance.