home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4663 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  2.7 KB

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!spool.mu.edu!uwm.edu!ogicse!news.u.washington.edu!carson.u.washington.edu!donn
  2. From: donn@carson.u.washington.edu (Donn Cave)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: getservbyname(), getprotobyname(), gethostbyname()
  5. Message-ID: <1992Sep15.163829.26987@u.washington.edu>
  6. Date: 15 Sep 92 16:38:29 GMT
  7. Article-I.D.: u.1992Sep15.163829.26987
  8. References: <1992Sep2.184623.3900@Urmel.Informatik.RWTH-Aachen.DE> <Btyu5o.Cxv@encore.com>
  9. Sender: news@u.washington.edu (USENET News System)
  10. Organization: University of Washington
  11. Lines: 45
  12.  
  13. epeterso@encore.com (Eric Peterson) writes:
  14.  
  15. >berg@physik.tu-muenchen.de (Stephen R. van den Berg) writes:
  16.  
  17. >| Now, in order to that, I have to find out the following:
  18. >| 
  19. >|     1. gethostbyname("localhost.or.something.else")
  20. >|     2. getservbyname("biff")
  21. >|     3. getprotobyname("udp")
  22. >| 
  23. >| Well, so far so good, the only trouble is, these calls are done every time
  24. >| when mail arrives.  I was wondering, what is common practice in this case?
  25. >| 
  26. >|     a. Go by the book and make all three calls at runtime?
  27. >|     b. Do 1. and 2. at runtime, 3. at compile time?
  28. >|     c. Do 1. at runtime, 2. and 3. at compile time?
  29. >|     d. Do all three at compile time?  (By compile-time I mean: compile
  30. >|        a separate program that makes these calls, and then use the output
  31. >|        from this program to hardcode the number(s) in the real program).
  32. ...
  33. > I would consider *ONLY* (a) to be acceptable practice.  These functions
  34. > are system database query functions, and the intent of making them
  35. > functions and not, say, header file definitions was to sever the dependency
  36. > between the code and the data (ie, you wouldn't have to rebuild if you
  37. > decided to change the UDP protocol number).
  38.  
  39. > Having said that, you could probably safely get away with hard-coding
  40. > these numbers into your code if you wanted to (except for the
  41. > gethostbyname() call) since they are so common that they probably
  42. > won't change.
  43.  
  44. Not only that, but perhaps you don't want to know if they do change.  Maybe
  45. I don't understand something here, but doesn't getservbyname("biff") tell
  46. me what port biff uses on_my_local_system?  If I want to connect to the
  47. "biff" service on "localhost.or.something.else", it's to be hoped that they
  48. will both use the same port, but if they don't, I certainly don't want to
  49. know about the local installation.
  50.  
  51. /etc/services is a useful way to advertise port numbers between programmers
  52. and system administrators, who otherwise would have no way to reserve a port,
  53. but whether applications should refer to that file is open to question,
  54. depending particularly on the system administration context.
  55.  
  56.     Donn Cave, University Computing Services, University of Washington
  57.     donn@cac.washington.edu
  58.