-
- if (ret != 0)
- rprintf(FERROR, "failed to set socket option %s: %s\n", tok,
- strerror(errno));
- }
-
- free(options);
-}
-
-/****************************************************************************
-become a daemon, discarding the controlling terminal
-****************************************************************************/
-void become_daemon(void)
-{
- int i;
-
- if (fork()) {
- _exit(0);
- }
-
- /* detach from the terminal */
-#ifdef HAVE_SETSID
- setsid();
-#else
-#ifdef TIOCNOTTY
- i = open("/dev/tty", O_RDWR);
- if (i >= 0) {
- ioctl(i, (int) TIOCNOTTY, (char *)0);
- close(i);
- }
-#endif /* TIOCNOTTY */
-#endif
- /* make sure that stdin, stdout an stderr don't stuff things
- up (library functions, for example) */
- for (i=0;i<3;i++) {
- close(i);
- open("/dev/null", O_RDWR);
- }
-}
-
-/*******************************************************************
- return the IP addr of the client as a string
- ******************************************************************/
-char *client_addr(int fd)
-{
- struct sockaddr sa;
- struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
- socklen_t length = sizeof(sa);
- static char addr_buf[100];
- static int initialised;
-
- if (initialised) return addr_buf;
-
- initialised = 1;
-
- if (getpeername(fd, &sa, &length)) {
- exit_cleanup(RERR_SOCKETIO);
- }
-
- strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf));
- return addr_buf;
-}
-
-
-/*******************************************************************
- return the DNS name of the client
- ******************************************************************/
-char *client_name(int fd)
-{
- struct sockaddr sa;
- struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
- socklen_t length = sizeof(sa);
- static char name_buf[100];
- struct hostent *hp;
- char **p;
- char *def = "UNKNOWN";
- static int initialised;
-
- if (initialised) return name_buf;
-
- initialised = 1;
-
- strcpy(name_buf,def);
-
- if (getpeername(fd, &sa, &length)) {
- exit_cleanup(RERR_SOCKETIO);
- }