home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / rec / games / mud / misc / 1741 < prev    next >
Encoding:
Text File  |  1992-12-28  |  4.2 KB  |  93 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: All I have to say on this (longish)
  5. Message-ID: <1992Dec28.144945.15143@meiko.com>
  6. Sender: news@meiko.com
  7. Organization: Meiko Scientific Corp.
  8. References: <jck1H8e5mb@atlantis.psu.edu> <1992Dec25.192450.3167@meiko.com> <SCG.92Dec27225529@mentor.cc.purdue.edu>
  9. Date: Mon, 28 Dec 1992 14:49:45 GMT
  10. Lines: 81
  11.  
  12. This is the last thing I'm going to add to this thread, lifes too short ...
  13.  
  14.   Some posts back, out of the goodness of my heart, I replyd to a posters
  15.   query about getpeername. I posted some code that I had inserted into an
  16.   UberMUD server to do just that. It workd for me.
  17.  
  18.   I get "what vomit is this" and "why don't you use inet_ntoa() ..." or
  19.   words to that effect. there then follows discussion about vendor bugs,
  20.   parameters needed by inet_ntoa(), struct sockaddr and struct
  21.   sockaddr_in, and whatnot.
  22.  
  23.   What did I start? Perhaps I'll just keep my mouth shut in future.
  24.   Perhaps not. This had been usefull to me, and I've learned a little from
  25.   it. Until today, I hadn't really had time to look at just what it all
  26.   means. I have been a unix/c programmer for over 10 years, but until
  27.   recently, when I added the getpeername to Uber, never had anything to
  28.   do with these socket things. I typed "man socket", in the see-also
  29.   section, I homed in on getsockname. "man getsockname" mentioned
  30.   getpeername. I looked this up, and took it from there. They all seemed
  31.   to have "get" and "name" in them, and as I wanted to get a name, what
  32.   else was I to do?
  33.  
  34.   I wasn't given an example of non-vomit code, but by reading this thread
  35.   and spending some time, searching through the manuals, and
  36.   experimenting, I came up with the following, which I'm sure anyone
  37.   could have, given a spare hour or 2 to look it up and play with it.
  38.  
  39.   struct sockaddr and struct sockaddr_in are basically the same.
  40.   sockaddr_in just seems to fill in the fields a bit better. (and in that
  41.   respect is probably more future-proof). accept() returns the same info as
  42.   getpeername and thus saves a system call. As an excercise, and to learn
  43.   a bit more myself, I removed my original getpeername mod and used the
  44.   new accept/inet_ntoa thing. (My new mods are at the end of the file, just
  45.   incase the original poster is still reading, and is not really a programmer,
  46.   but would like to understand things a bit better - I'm too generous. Perhaps
  47.   thats my fault. Bah-Humbug.)
  48.  
  49.   Well - what do you know. It seems to work. It looks like inet_ntoa
  50.   works under Solaris 2.0 fcs. Someone mentioned that it didn't work
  51.   under SunOs. I had a look at the sources. (I have access to sunos and
  52.   solaris sources). I can't print the sources, but they are both
  53.   identical (save for the sccs Ids), and use sprintf. Perhaps it's
  54.   sprintf thats broken. Who knows. As someone whos been involved in
  55.   porting a unix to a new platform, it's inevetable that a few things get
  56.   broken allong the way. They get fixed eventually. Thats just the way it is.
  57.  
  58.   Someone else mentioned that this isn't the place to discuss server
  59.   programming. You are probably right, but Multi-User whatnots and server
  60.   programming seem to go together quite well!
  61.  
  62.   Well, I'm going back to hacking my UberMUD now. If anyone wants to play
  63.   a working UberMUD, they can on 192.131.108.55, port 6123. It may be up
  64.   & down for the next day or 2, but look-out for a proper ad. in
  65.   r.g.m.announce at the start of the new-year.
  66.  
  67.   Have a good one.
  68.  
  69. Gordon Henderson
  70.  
  71. ----
  72.     ....
  73.     struct    sockaddr_in sin ;
  74.     int    sinLen = sizeof (sin) ;
  75.     ....
  76.         n = accept(serfd,(struct sockaddr *)&sin,&sinLen);
  77.     ....
  78.             strcpy (bp->ipAddress, inet_ntoa (sin.sin_addr)) ;
  79.             logf ("New connect @", bp->ipAddress, "\n", 0) ;
  80.     ....
  81.  
  82.  +--+  +--+  +--+
  83.  |- +--+  +--+ -|
  84.  +---+ - - -+---+
  85.      | - - -|
  86.      |- - - |
  87.      | - - -+-------------------------------------------------------------+
  88.      |- - Arch Wizard Irn-Bru - Creator of Drogon - gordon@meiko.com - - -|
  89.      +--------------------------------------------------------------------+
  90.      | Drogon is a Multi-User Adventure Game on 192.131.108.55, port 6123 |
  91.      +--------------------------------------------------------------------+
  92.  
  93.