home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4558 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.1 KB  |  35 lines

  1. Path: sparky!uunet!contex!felix.contex.com!avinash
  2. From: avinash@felix.contex.com (Avinash Chopde)
  3. Newsgroups: comp.unix.programmer
  4. Subject: bind() and unassigned local port numbers.
  5. Message-ID: <2930@contex.contex.com>
  6. Date: 7 Sep 92 18:00:50 GMT
  7. Sender: news@contex.contex.com
  8. Lines: 25
  9.  
  10. I am experimenting with Berkeley sockets, and was going through an
  11. example in the Silicon Graphics IRIX Network Programming Guide.
  12.  
  13. The example mentions that the "sin_port" field may be assigned to 0
  14. for a bind() call, in which case the system will assign an appropriate
  15. port number to it.
  16. Well, how does the program then find out what port number was assigned ?
  17.  
  18. Here's a sketch of what I wrote:
  19.  
  20. ....
  21. struct sockaddr_in sin;
  22. ...
  23. sin.sin_addr.s_addr = htonl(INADDR_ANY);
  24. sin.sin_port = htons(0);
  25. bind(s, (struct sockaddr*) &sin, sizeof(sin));
  26.  
  27. ... Now, I looked into sin.sin_port, it still contained 0.
  28. So, how does one get the assigned port number ?
  29.  
  30. Thanks a lot for any pointers....
  31. -- 
  32. ---------------------------
  33. Avinash Chopde         office : 617 246 1776x5582
  34. avinash@contex.com     (...!uunet!contex!avinash)
  35.