I am trying to change the source IP address for tcp package. Code snippet below
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 to a specific port works fine, but when I tried to bind to a different IP address, binding to an error
bind: Cannot assign requested address
I also tried setting the socket parameter as follows:]
setsockopt (sockfd, SOL_IP, IP_TRANSPARENT, &n1, sizeof(int));*
and then it crashes with the same error.
How can I change my source IP address for a package created 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.
source share