diff options
author | Damien Miller <djm@mindrot.org> | 2001-01-25 10:32:00 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-01-25 10:32:00 +1100 |
commit | 2a5c1cede026faec14b0903a0cdcc4e7ef554e32 (patch) | |
tree | 2534f2a4499b295d01521a5fe90aa1ba9eeb9146 /bsd-bindresvport.c | |
parent | 12aaa04e96be85a684d3f90db46bb62689796a93 (diff) |
- (djm) Sync bsd-* support files:
- deraadt@cvs.openbsd.org 2000/01/26 03:43:20
[rresvport.c bindresvport.c]
new bindresvport() semantics that itojun, shin, jean-luc and i have
agreed on, which will be happy for the future. bindresvport_sa() for
sockaddr *, too. docs later..
- deraadt@cvs.openbsd.org 2000/01/24 02:24:21
[bindresvport.c]
in bindresvport(), if sin is non-NULL, example sin->sin_family for
the actual family being processed
Diffstat (limited to 'bsd-bindresvport.c')
-rw-r--r-- | bsd-bindresvport.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/bsd-bindresvport.c b/bsd-bindresvport.c index 7faf73191..332bcb016 100644 --- a/bsd-bindresvport.c +++ b/bsd-bindresvport.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* This file has be modified from the original OpenBSD source */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | 4 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for |
3 | * unrestricted use provided that this legend is included on all tape | 5 | * unrestricted use provided that this legend is included on all tape |
@@ -29,10 +31,10 @@ | |||
29 | 31 | ||
30 | #include "config.h" | 32 | #include "config.h" |
31 | 33 | ||
32 | #ifndef HAVE_BINDRESVPORT_AF | 34 | #ifndef HAVE_BINDRESVPORT_SA |
33 | 35 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char *rcsid = "$OpenBSD: bindresvport.c,v 1.11 1999/12/17 19:22:08 deraadt Exp $"; | 37 | static char *rcsid = "$OpenBSD: bindresvport.c,v 1.13 2000/01/26 03:43:21 deraadt Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 38 | #endif /* LIBC_SCCS and not lint */ |
37 | 39 | ||
38 | /* | 40 | /* |
@@ -51,12 +53,11 @@ static char *rcsid = "$OpenBSD: bindresvport.c,v 1.11 1999/12/17 19:22:08 deraad | |||
51 | * Bind a socket to a privileged IP port | 53 | * Bind a socket to a privileged IP port |
52 | */ | 54 | */ |
53 | int | 55 | int |
54 | bindresvport_af(sd, sa, af) | 56 | bindresvport_sa(sd, sa) |
55 | int sd; | 57 | int sd; |
56 | struct sockaddr *sa; | 58 | struct sockaddr *sa; |
57 | int af; | ||
58 | { | 59 | { |
59 | int error; | 60 | int error, af; |
60 | struct sockaddr_storage myaddr; | 61 | struct sockaddr_storage myaddr; |
61 | struct sockaddr_in *sin; | 62 | struct sockaddr_in *sin; |
62 | struct sockaddr_in6 *sin6; | 63 | struct sockaddr_in6 *sin6; |
@@ -68,7 +69,14 @@ bindresvport_af(sd, sa, af) | |||
68 | if (sa == NULL) { | 69 | if (sa == NULL) { |
69 | memset(&myaddr, 0, sizeof(myaddr)); | 70 | memset(&myaddr, 0, sizeof(myaddr)); |
70 | sa = (struct sockaddr *)&myaddr; | 71 | sa = (struct sockaddr *)&myaddr; |
71 | } | 72 | |
73 | if (getsockname(sd, sa, &salen) == -1) | ||
74 | return -1; /* errno is correctly set */ | ||
75 | |||
76 | af = sa->sa_family; | ||
77 | memset(&myaddr, 0, salen); | ||
78 | } else | ||
79 | af = sa->sa_family; | ||
72 | 80 | ||
73 | if (af == AF_INET) { | 81 | if (af == AF_INET) { |
74 | sin = (struct sockaddr_in *)sa; | 82 | sin = (struct sockaddr_in *)sa; |
@@ -95,7 +103,7 @@ bindresvport_af(sd, sa, af) | |||
95 | *portp = htons(port); | 103 | *portp = htons(port); |
96 | 104 | ||
97 | error = bind(sd, sa, salen); | 105 | error = bind(sd, sa, salen); |
98 | 106 | ||
99 | /* Terminate on success */ | 107 | /* Terminate on success */ |
100 | if (error == 0) | 108 | if (error == 0) |
101 | break; | 109 | break; |
@@ -112,4 +120,4 @@ bindresvport_af(sd, sa, af) | |||
112 | return (error); | 120 | return (error); |
113 | } | 121 | } |
114 | 122 | ||
115 | #endif /* HAVE_BINDRESVPORT_AF */ | 123 | #endif /* HAVE_BINDRESVPORT_SA */ |