home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / rec / games / mud / misc / 1725 < prev    next >
Encoding:
Text File  |  1992-12-24  |  1.4 KB  |  48 lines

  1. Newsgroups: rec.games.mud.misc
  2. Path: sparky!uunet!noc.near.net!meiko.com!gordon
  3. From: gordon@meiko.com (Gordon Henderson)
  4. Subject: Re: Note to any fellow DikuMUD coders...
  5. Message-ID: <1992Dec24.114107.18992@meiko.com>
  6. Sender: news@meiko.com
  7. Organization: Meiko Scientific Corp.
  8. References: <3331@bsu-cs.bsu.edu>
  9. Date: Thu, 24 Dec 1992 11:41:07 GMT
  10. Lines: 36
  11.  
  12. In article <3331@bsu-cs.bsu.edu> decker@bsu-cs.bsu.edu (Alexus Mel Lynn) writes:
  13. >
  14. >Have any of you fellow coders worked with getpeername?  (I've ported some
  15. >lpmud code over my very hacked diku, but it always dies on the getpeername...)
  16. >
  17. >I've made sure it's not something stupid like bad parameters, etc.
  18.  
  19. I use this in a MUD that I am running to get the ip address of the caller:
  20.  
  21.   struct sockaddr foo ;
  22.   int r, fooLen ;
  23.   char currentConnectId [20] ;
  24.  
  25.   fooLen = sizeof (foo.sa_data) ;
  26.  
  27.   r = getpeername (n, &foo, &fooLen) ;
  28.   if (r != 0)
  29.     logf ("Bad return from getpeername: ", -1, "\n", 0) ;
  30.   else
  31.   {
  32.     sprintf (currentConnectId, "%d.%d.%d.%d",
  33.         foo.sa_data [2] & 0xFF, foo.sa_data [3] & 0xFF,
  34.         foo.sa_data [4] & 0xFF, foo.sa_data [5] & 0xFF) ;
  35.     logf ("New connect @", itoa (n), ": ", currentConnectId, "\n", 0) ;
  36.   }
  37.  
  38.  
  39. The variable "n" is the fd of the connection.
  40.  
  41. This works under SunOS 4.x and Solaris 2.0. you many need to #include
  42. something like <sys/socket.h> and <netinet/in.h> but you probably already
  43. have those anyway.
  44.  
  45. --
  46.   Gordon (Irn-Bru) Henderson
  47.  
  48.