home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: rec.games.mud.misc
- Path: sparky!uunet!noc.near.net!meiko.com!gordon
- From: gordon@meiko.com (Gordon Henderson)
- Subject: All I have to say on this (longish)
- Message-ID: <1992Dec28.144945.15143@meiko.com>
- Sender: news@meiko.com
- Organization: Meiko Scientific Corp.
- References: <jck1H8e5mb@atlantis.psu.edu> <1992Dec25.192450.3167@meiko.com> <SCG.92Dec27225529@mentor.cc.purdue.edu>
- Date: Mon, 28 Dec 1992 14:49:45 GMT
- Lines: 81
-
- This is the last thing I'm going to add to this thread, lifes too short ...
-
- Some posts back, out of the goodness of my heart, I replyd to a posters
- query about getpeername. I posted some code that I had inserted into an
- UberMUD server to do just that. It workd for me.
-
- I get "what vomit is this" and "why don't you use inet_ntoa() ..." or
- words to that effect. there then follows discussion about vendor bugs,
- parameters needed by inet_ntoa(), struct sockaddr and struct
- sockaddr_in, and whatnot.
-
- What did I start? Perhaps I'll just keep my mouth shut in future.
- Perhaps not. This had been usefull to me, and I've learned a little from
- it. Until today, I hadn't really had time to look at just what it all
- means. I have been a unix/c programmer for over 10 years, but until
- recently, when I added the getpeername to Uber, never had anything to
- do with these socket things. I typed "man socket", in the see-also
- section, I homed in on getsockname. "man getsockname" mentioned
- getpeername. I looked this up, and took it from there. They all seemed
- to have "get" and "name" in them, and as I wanted to get a name, what
- else was I to do?
-
- I wasn't given an example of non-vomit code, but by reading this thread
- and spending some time, searching through the manuals, and
- experimenting, I came up with the following, which I'm sure anyone
- could have, given a spare hour or 2 to look it up and play with it.
-
- struct sockaddr and struct sockaddr_in are basically the same.
- sockaddr_in just seems to fill in the fields a bit better. (and in that
- respect is probably more future-proof). accept() returns the same info as
- getpeername and thus saves a system call. As an excercise, and to learn
- a bit more myself, I removed my original getpeername mod and used the
- new accept/inet_ntoa thing. (My new mods are at the end of the file, just
- incase the original poster is still reading, and is not really a programmer,
- but would like to understand things a bit better - I'm too generous. Perhaps
- thats my fault. Bah-Humbug.)
-
- Well - what do you know. It seems to work. It looks like inet_ntoa
- works under Solaris 2.0 fcs. Someone mentioned that it didn't work
- under SunOs. I had a look at the sources. (I have access to sunos and
- solaris sources). I can't print the sources, but they are both
- identical (save for the sccs Ids), and use sprintf. Perhaps it's
- sprintf thats broken. Who knows. As someone whos been involved in
- porting a unix to a new platform, it's inevetable that a few things get
- broken allong the way. They get fixed eventually. Thats just the way it is.
-
- Someone else mentioned that this isn't the place to discuss server
- programming. You are probably right, but Multi-User whatnots and server
- programming seem to go together quite well!
-
- Well, I'm going back to hacking my UberMUD now. If anyone wants to play
- a working UberMUD, they can on 192.131.108.55, port 6123. It may be up
- & down for the next day or 2, but look-out for a proper ad. in
- r.g.m.announce at the start of the new-year.
-
- Have a good one.
-
- Gordon Henderson
-
- ----
- ....
- struct sockaddr_in sin ;
- int sinLen = sizeof (sin) ;
- ....
- n = accept(serfd,(struct sockaddr *)&sin,&sinLen);
- ....
- strcpy (bp->ipAddress, inet_ntoa (sin.sin_addr)) ;
- logf ("New connect @", bp->ipAddress, "\n", 0) ;
- ....
-
- +--+ +--+ +--+
- |- +--+ +--+ -|
- +---+ - - -+---+
- | - - -|
- |- - - |
- | - - -+-------------------------------------------------------------+
- |- - Arch Wizard Irn-Bru - Creator of Drogon - gordon@meiko.com - - -|
- +--------------------------------------------------------------------+
- | Drogon is a Multi-User Adventure Game on 192.131.108.55, port 6123 |
- +--------------------------------------------------------------------+
-
-