home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / wizards / 3598 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.6 KB

  1. Xref: sparky comp.unix.wizards:3598 comp.unix.programmer:4280
  2. Path: sparky!uunet!mcsun!sun4nl!tuegate.tue.nl!svin02!wzv!wietse
  3. From: wietse@wzv.win.tue.nl (Wietse Venema)
  4. Newsgroups: comp.unix.wizards,comp.unix.programmer
  5. Subject: Re: Recvfrom() in an inetd server
  6. Message-ID: <3723@wzv.win.tue.nl>
  7. Date: 13 Aug 92 18:22:17 GMT
  8. References: <1992Jul19.221910.5437@massey.ac.nz>
  9. Followup-To: comp.unix.wizards
  10. Organization: Eindhoven University of Technology, The Netherlands
  11. Lines: 31
  12.  
  13. A.Raman@massey.ac.nz (Anand) writes:
  14.  
  15. [getting the remote host name from an UDP connection in a child
  16. process of the inetd]
  17.  
  18. >Regarding the second option of using recvfrom() on fd 0, I had the
  19. >following doubt:  If inetd already receives the packet for us, and
  20. >is known to supply the data field on stdin, then the packet is already
  21. >lost.  In that case, how can recvfrom() return the packet to me?
  22.  
  23. inetd does not receive the packet. It just waits until a packet is
  24. available, then invokes the daemon listed in the inetd.conf file. 
  25.  
  26. With the following code, inetd can non-destructively examine the
  27. UDP packet, and find out the source IP address.
  28.  
  29.     /* In case of UDP, peek at the message without reading it. */
  30.  
  31.     if (recvfrom(0, buf, sizeof(buf), MSG_PEEK, &sa, &length) < 0) {
  32.         syslog(LOG_ERR, "recvfrom: %m");
  33.         ...
  34.     }
  35.  
  36.     /* If all went well, sa.sin_addr is the source IP address. */
  37.  
  38. This trick is used in my tcp wrappers to find out what systems are
  39. connecting to the telnet, finger, tftp and other services, and to do
  40. access control as well. On some Convex systems the MSG_PEEK facility
  41. does not seem to work, however.
  42.  
  43.     Wietse
  44.