home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / clients / 274 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.4 KB  |  73 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!gatech!concert!borg.cs.unc.edu!not-for-mail
  2. From: wagner@cs.unc.edu (Michael Wagner)
  3. Newsgroups: comp.client-server
  4. Subject: How to use svc_getcaller((SVCXPRT *) cl)
  5. Date: 12 Jan 1993 13:04:13 -0500
  6. Organization: The University of North Carolina at Chapel Hill
  7. Lines: 61
  8. Distribution: world
  9. Message-ID: <1iv16tINN3jd@paganini.cs.unc.edu>
  10. NNTP-Posting-Host: paganini.cs.unc.edu
  11.  
  12.  
  13. I am developing an application that is using SUN RPC.
  14. The server may be contacted by many different clients,
  15. and needs to know who they are.  My man page says that
  16. svc_getcaller() is the way to do this:
  17.  
  18.      struct sockaddr_in * svc_getcaller(xprt)
  19.      SVCXPRT *xprt;
  20.  
  21.           The approved way of getting the network address of  the
  22.           caller  of  a procedure associated with the RPC service
  23.           transport handle, xprt.
  24.  
  25.  
  26. I tried to use svc_getcaller() as follows (for non-C++ programmers,
  27. think of cout << as a print()).  This *doesn't* work.  I always get
  28. the same family, port, and addrs printed out, even when I have
  29. two clients on different machines.  They all look like nonsense
  30. values.  Am I doing something wrong?  Has anyone else gotten
  31. this to work?
  32.  
  33. /******************************************************************/
  34. struct sockaddr_in old_caller;
  35.  
  36.     /* .
  37.        .
  38.        . */
  39. int
  40. check_caller(CLIENT * cl)
  41. {
  42.         struct sockaddr_in *caller = svc_getcaller((SVCXPRT *) cl);
  43.         cout << "caller: family: " << (unsigned short) caller->sin_family
  44.                                     << "\n";
  45.         cout << "caller: port:   " << caller->sin_port << "\n";
  46.         cout << "caller: addr:   " << (char *) inet_ntoa(caller->sin_addr)
  47.                                     << "\n";
  48.         if ((caller->sin_family == old_caller.sin_family) &&
  49.             (caller->sin_port == old_caller.sin_port) &&
  50.             (caller->sin_addr.s_addr == old_caller.sin_addr.s_addr)) {
  51.                  cout << "callers are the same\n";
  52.                 return (1);
  53.         } else {
  54.                 cout << "callers are different\n";
  55.                 old_caller = *caller;
  56.         }
  57.         return (0);
  58. };
  59. /******************************************************************/
  60.  
  61. Thanks for any help.
  62.  
  63. Mike Wagner
  64. wagner@cs.unc.edu
  65.  
  66.  
  67.  
  68. -- 
  69. .......................................................
  70. michael paul wagner
  71. wagner@hatteras.cs.unc.edu        ahlan wa sahlan
  72. .......................................................
  73.