home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!inmet!bu.edu!cs!tasos
- From: tasos@cs.bu.edu (Anastasios Kotsikonas)
- Newsgroups: comp.unix.programmer
- Subject: Re: getting a host ip name
- Message-ID: <104537@bu.edu>
- Date: 10 Dec 92 20:54:42 GMT
- References: <1992Dec10.032318.16793@news.tufts.edu>
- Sender: news@bu.edu
- Organization: Computer Science Department, Boston University, Boston, MA, USA
- Lines: 17
-
- In article <1992Dec10.032318.16793@news.tufts.edu> rdorich@jade.tufts.edu (Rob) writes:
- > This is an easy one, once you do a recv or an accept which
- >fills in the structure sockaddr of the connecting peer, how can I get
- >the name in a readable number form? sort of 128.23.34.25
-
- > recv(sockfd,buff,size,0,(struct sockaddr *)&cli_addr,&size);
- >
- > So now how do now how do I get the address from cli_addr????
-
- Here is the piece of code that I am using (totally portable and correct):
-
- hp = gethostbyaddr ((char *) &client.sin_addr,
- sizeof (struct in_addr), client.sin_family);
- sprintf (msg, "Connection request from %s: ",
- upcase ((s = (hp ? hp->h_name : (char *) inet_ntoa (client.sin_addr)))));
-
- Tasos
-