~ubuntu-branches/ubuntu/karmic/dante/karmic

« back to all changes in this revision

Viewing changes to dlib/Rrresvport.c

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2002-04-07 12:45:55 UTC
  • Revision ID: james.westby@ubuntu.com-20020407124555-qke8rt2tdor0naz2
Tags: upstream-1.1.11.12p1
Import upstream version 1.1.11.12p1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1997, 1998, 1999, 2000, 2001
 
3
 *      Inferno Nettverk A/S, Norway.  All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 * 1. The above copyright notice, this list of conditions and the following
 
9
 *    disclaimer must appear in all copies of the software, derivative works
 
10
 *    or modified versions, and any portions thereof, aswell as in all
 
11
 *    supporting documentation.
 
12
 * 2. All advertising materials mentioning features or use of this software
 
13
 *    must display the following acknowledgement:
 
14
 *      This product includes software developed by
 
15
 *      Inferno Nettverk A/S, Norway.
 
16
 * 3. The name of the author may not be used to endorse or promote products
 
17
 *    derived from this software without specific prior written permission.
 
18
 *
 
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 *
 
30
 * Inferno Nettverk A/S requests users of this software to return to
 
31
 *
 
32
 *  Software Distribution Coordinator  or  sdc@inet.no
 
33
 *  Inferno Nettverk A/S
 
34
 *  Oslo Research Park
 
35
 *  Gaustadall�en 21
 
36
 *  NO-0349 Oslo
 
37
 *  Norway
 
38
 *
 
39
 * any improvements or extensions that they make and grant Inferno Nettverk A/S
 
40
 * the rights to redistribute these changes.
 
41
 *
 
42
 */
 
43
 
 
44
#include "common.h"
 
45
 
 
46
static const char rcsid[] =
 
47
"$Id: Rrresvport.c,v 1.22 2001/12/12 14:42:08 karls Exp $";
 
48
 
 
49
/*
 
50
 * Note that for this function to work the remote socksserver is required
 
51
 * to be using the bind extension.
 
52
 */
 
53
 
 
54
int
 
55
Rrresvport(port)
 
56
        int *port;
 
57
{
 
58
        const char *function = "Rrresvport()";
 
59
        int s;
 
60
        struct sockaddr name;
 
61
        socklen_t namelen;
 
62
 
 
63
        clientinit();
 
64
 
 
65
        slog(LOG_DEBUG, "%s", function);
 
66
 
 
67
        if ((s = rresvport(port)) == -1)
 
68
                return -1;
 
69
 
 
70
        namelen = sizeof(name);
 
71
        if (getsockname(s, &name, &namelen) != 0) {
 
72
                close(s);
 
73
                return -1;
 
74
        }
 
75
 
 
76
        /* Rbind() will accept failure at binding socket that is already bound. */
 
77
        if (Rbind(s, &name, namelen) != 0) {
 
78
                close(s);
 
79
                return -1;
 
80
        }
 
81
 
 
82
        return s;
 
83
}