home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / programm / 5682 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  1.1 KB

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