INADDR_ANY opposite


 
Thread Tools Search this Thread
Special Forums IP Networking INADDR_ANY opposite
# 1  
Old 11-27-2008
Question INADDR_ANY opposite

Hello, is there some way to obtain system's IP adresses to bind socket to every of them separately instead od INADDR_ANY?

OR

If there is some way to get server's IP to which client has connected, for example:

server_app - bind to listen on INADDR_ANY, gets connected client to 1.2.3.4, communication works fine, but when server_app wants to know to which IP is connected client on it, it will get 0.0.0.0 or 127.0.0.1 which is bad Smilie

I want to know this because when I bind to INADDR_ANY and get incoming connection, I can only get client's IP and port, but don't know how to obtain server's IP which is connected to client (i always get 0.0.0.0).

Thanks for ideas..

//edit: And I forgot to write: unix/linux platform, not winsock
# 2  
Old 12-05-2008
I'm too lazy to do this for you.... Get the Apache source code and see what it does. It somehow knows the IP that served the request and outputs it via the logfile (See custom log format documentation).
# 3  
Old 12-05-2008
I was searching proftpd code, but the answer is hidden as much as possible. So I tried to solve it myself, and here is my solution:

char *ip=malloc(20*sizeof(char));
struct sockaddr_in myAddr;
int sin_size = sizeof(myAddr);

getsockname(clientSocket, (struct sockaddr *)&myAddr, (socklen_t *)&sin_size);
strncpy(ip,inet_ntoa(myAddr.sin_addr),strlen(inet_ntoa(myAddr.sin_addr)));
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What script would I use to count the number of a term and its opposite?

Hello All, I am looking to write a script to count the number of a term and its opposite and create a new file with said list. I can get the terms to print to the file but only one or the other and not both. I tried this: grep -wi done */all.txt | grep -wiv done */all.txt > "filename" ... (5 Replies)
Discussion started by: mcesmcsc
5 Replies

2. UNIX for Beginners Questions & Answers

How to select rows that have opposite values (A vs B, or B vs A) on first two columns?

I have a dateset like this: Gly1 Gly2 2 1 0 Gly3 Gly4 3 4 5 Gly3 Gly5 1 3 2 Gly2 Gly1 3 6 2 Gly4 Gly3 2 2 1 Gly6 Gly4 4 2 1what I expected is: Gly1 Gly2 2 1 0 Gly2 Gly1 3 6 2 Gly3 Gly4 3 4 5 Gly4 Gly3 2 2 1 A vs B, or B vs A are the same... (7 Replies)
Discussion started by: nengcheng
7 Replies

3. UNIX for Dummies Questions & Answers

opposite return status in c shell

there is something wrong with my system. when I do this: diff file1 file1 && echo 1 the output is 1. but diff file1 file2 >/dev/null && echo 1 output nothing while diff file1 file2 >/dev/null || echo 1 shows 1. the same with "grep" return status. they are both GNU utilities.... (5 Replies)
Discussion started by: phil518
5 Replies

4. Programming

SQL: the opposite of "SELECT now() -interval 1 day"

Hi there, if i run SELECT now() -interval 1 day I get all items within the last 24 hours. How would I reverse/adjust this so that i get everything that ISNT in the last 24 hours ? any help on this would be greatly appreciated Cheers (1 Reply)
Discussion started by: rethink
1 Replies

5. IP Networking

UDP server socket inaddr_any - How to get the real IP

Hello ! I seem to have the same problem as in https://www.unix.com/ip-networking/91203-inaddr_any-opposite.html#post302262417 But I can't find a solution. I have a UDP server socket bound to 0.0.0.0. The server hosts the addresses IP1, IP2 and IP3. I get an incoming request to IP1. I use... (1 Reply)
Discussion started by: steinwej
1 Replies

6. IP Networking

Inaddr_any

HI All, This is about the Basics of INADDR_ANY. When we bind to the server by placing the value of sin_addr.s_addr as INADDR_ANY, Does it binds to all the IP addresses( If that system is multi homed one) with the specified port?. i.e if the system is having IP1 , IP2 and IP3 addresses and... (3 Replies)
Discussion started by: athresh
3 Replies

7. Shell Programming and Scripting

Opposite of Split

Hi Folks!! I had a very huge file containing 4GB of data in it and i had to move that to a different server. Since, i thought moving of 4GB data is gonna take more time, i splitted the file into four parts using split command split -b 1499889664 abcd.cpk It splitted the file and now after... (3 Replies)
Discussion started by: ganga.dharan
3 Replies
Login or Register to Ask a Question