home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!contex!felix.contex.com!avinash
- From: avinash@felix.contex.com (Avinash Chopde)
- Newsgroups: comp.unix.programmer
- Subject: bind() and unassigned local port numbers.
- Message-ID: <2930@contex.contex.com>
- Date: 7 Sep 92 18:00:50 GMT
- Sender: news@contex.contex.com
- Lines: 25
-
- I am experimenting with Berkeley sockets, and was going through an
- example in the Silicon Graphics IRIX Network Programming Guide.
-
- The example mentions that the "sin_port" field may be assigned to 0
- for a bind() call, in which case the system will assign an appropriate
- port number to it.
- Well, how does the program then find out what port number was assigned ?
-
- Here's a sketch of what I wrote:
-
- ....
- struct sockaddr_in sin;
- ...
- sin.sin_addr.s_addr = htonl(INADDR_ANY);
- sin.sin_port = htons(0);
- bind(s, (struct sockaddr*) &sin, sizeof(sin));
-
- ... Now, I looked into sin.sin_port, it still contained 0.
- So, how does one get the assigned port number ?
-
- Thanks a lot for any pointers....
- --
- ---------------------------
- Avinash Chopde office : 617 246 1776x5582
- avinash@contex.com (...!uunet!contex!avinash)
-