Getting IP from client socket
-
Hi, I am working on FTP server and I need to manage IP Access. How can I get IP address from client socket which I accepted ?? And second question: dont you have/know any reliable and tested mechanism for providing IP Access restriction (eg. IP 200.100.50.25 cant access our server between 21.8.2002 23:00 and 22.8.2002 12:30) ??? I chiefly mean the format for saving these rules and for reading them (from textfile or whatever)... Any help will be appreciated !!! Thanks, Standa. Celebrate Mr. Cesilko!
-
Hi, I am working on FTP server and I need to manage IP Access. How can I get IP address from client socket which I accepted ?? And second question: dont you have/know any reliable and tested mechanism for providing IP Access restriction (eg. IP 200.100.50.25 cant access our server between 21.8.2002 23:00 and 22.8.2002 12:30) ??? I chiefly mean the format for saving these rules and for reading them (from textfile or whatever)... Any help will be appreciated !!! Thanks, Standa. Celebrate Mr. Cesilko!
s_k wrote: How can I get IP address from client socket which I accepted ?? With Berkeley sockets you need to pass a sockaddr_in struct to your accept() call like so:
struct sockaddr_in their_addr; /* connector's address information */ /* create a socket and call bind() and listen() */ sin_size = sizeof(struct sockaddr_in); new_fd = accept(sockfd, &their_addr, &sin_size);
Upon connection you can read the values from thetheir_addr
struct and get what you need. As for your other question I personally can't answer it in the context of a forum post. I would just look at how other programs handle rules like that for guidance. It's the kind of thing you can make as complex as you want, but I would really strive for simplicity to reduce logic errors.