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: Re: Note to any fellow DikuMUD coders...
- Message-ID: <1992Dec24.114107.18992@meiko.com>
- Sender: news@meiko.com
- Organization: Meiko Scientific Corp.
- References: <3331@bsu-cs.bsu.edu>
- Date: Thu, 24 Dec 1992 11:41:07 GMT
- Lines: 36
-
- In article <3331@bsu-cs.bsu.edu> decker@bsu-cs.bsu.edu (Alexus Mel Lynn) writes:
- >
- >Have any of you fellow coders worked with getpeername? (I've ported some
- >lpmud code over my very hacked diku, but it always dies on the getpeername...)
- >
- >I've made sure it's not something stupid like bad parameters, etc.
-
- I use this in a MUD that I am running to get the ip address of the caller:
-
- struct sockaddr foo ;
- int r, fooLen ;
- char currentConnectId [20] ;
-
- fooLen = sizeof (foo.sa_data) ;
-
- r = getpeername (n, &foo, &fooLen) ;
- if (r != 0)
- logf ("Bad return from getpeername: ", -1, "\n", 0) ;
- else
- {
- sprintf (currentConnectId, "%d.%d.%d.%d",
- foo.sa_data [2] & 0xFF, foo.sa_data [3] & 0xFF,
- foo.sa_data [4] & 0xFF, foo.sa_data [5] & 0xFF) ;
- logf ("New connect @", itoa (n), ": ", currentConnectId, "\n", 0) ;
- }
-
-
- The variable "n" is the fd of the connection.
-
- This works under SunOS 4.x and Solaris 2.0. you many need to #include
- something like <sys/socket.h> and <netinet/in.h> but you probably already
- have those anyway.
-
- --
- Gordon (Irn-Bru) Henderson
-
-