~ubuntu-branches/ubuntu/utopic/eglibc/utopic

« back to all changes in this revision

Viewing changes to .pc/any/local-bindresvport_blacklist.diff/sunrpc/bindrsvprt.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-10-26 05:14:58 UTC
  • mfrom: (1.5.1) (4.4.22 experimental)
  • Revision ID: package-import@ubuntu.com-20121026051458-oryotr4i03ob5pab
Tags: 2.16-0ubuntu1
* Merge with unreleased 2.16 in Debian experimental, remaining changes:
  - Drop the Breaks line from libc6, which refers to a Debian transition
  - Remove the libc6 recommends on libc6-i686, which we don't build
  - Enable libc6{,-dev}-armel on armhf and libc6{-dev}-armhf on armel
  - Ship update-locale and validlocale in /usr/sbin in libc-bin
  - Don't build locales or locales-all in Ubuntu, we rely on langpacks
  - Heavily mangle the way we do service restarting on major upgrades
  - Use different MIN_KERNEL_SUPPORTED versions than Debian, due to
    buildd needs.  This should be universally bumped to 3.2.0 once all
    our buildds (including the PPA guests) are running precise kernels
  - Build i386 variants as -march=i686, build amd64 with -O3, and build
    ppc64 variants (both 64-bit and 32-bit) with -O3 -fno-tree-vectorize
  - Re-enable unsubmitted-ldconfig-cache-abi.diff and rebuild the cache
    on upgrades from previous versions that used a different constant
  - debian/patches/any/local-CVE-2012-3406.diff: switch to malloc when
    array grows too large to handle via alloca extension (CVE-2012-3406)
  - Build generic i386/i686 flavour with -mno-tls-direct-seg-refs
* Changes added/dropped with this merge while reducing our delta:
  - Stop building glibc docs from the eglibc source, and instead make
    the glibc-docs stub have a hard dependency on glibc-doc-reference
  - Remove outdated conflicts against ancient versions of ia32-libs
  - Drop the tzdata dependency from libc6, it's in required and minimal
  - Use gcc-4.7/g++-4.7 by default on all our supported architectures
  - Save our historical changelog as changelog.ubuntu in the source
  - Drop nscd's libaudit build-dep for now, as libaudit is in universe
  - Drop the unnecessary Breaks from libc6 to locales and locales-all
  - Ship xen's ld.so.conf.d snippet as /etc/ld.so.conf.d/libc6-xen.conf
* Disable hard failures on the test suite for the first upload to raring

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010, Oracle America, Inc.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
8
 *     * Redistributions of source code must retain the above copyright
 
9
 *       notice, this list of conditions and the following disclaimer.
 
10
 *     * Redistributions in binary form must reproduce the above
 
11
 *       copyright notice, this list of conditions and the following
 
12
 *       disclaimer in the documentation and/or other materials
 
13
 *       provided with the distribution.
 
14
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
 
15
 *       contributors may be used to endorse or promote products derived
 
16
 *       from this software without specific prior written permission.
 
17
 *
 
18
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
21
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
22
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
23
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
24
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 
25
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
26
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
27
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
28
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
29
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
30
 */
 
31
 
 
32
#include <errno.h>
 
33
#include <unistd.h>
 
34
#include <string.h>
 
35
#include <sys/types.h>
 
36
#include <sys/socket.h>
 
37
#include <netinet/in.h>
 
38
 
 
39
/*
 
40
 * Bind a socket to a privileged IP port
 
41
 */
 
42
int
 
43
bindresvport (int sd, struct sockaddr_in *sin)
 
44
{
 
45
  static short port;
 
46
  struct sockaddr_in myaddr;
 
47
  int i;
 
48
 
 
49
#define STARTPORT 600
 
50
#define LOWPORT 512
 
51
#define ENDPORT (IPPORT_RESERVED - 1)
 
52
#define NPORTS  (ENDPORT - STARTPORT + 1)
 
53
  static short startport = STARTPORT;
 
54
 
 
55
  if (sin == (struct sockaddr_in *) 0)
 
56
    {
 
57
      sin = &myaddr;
 
58
      __bzero (sin, sizeof (*sin));
 
59
      sin->sin_family = AF_INET;
 
60
    }
 
61
  else if (sin->sin_family != AF_INET)
 
62
    {
 
63
      __set_errno (EAFNOSUPPORT);
 
64
      return -1;
 
65
    }
 
66
 
 
67
  if (port == 0)
 
68
    {
 
69
      port = (__getpid () % NPORTS) + STARTPORT;
 
70
    }
 
71
 
 
72
  /* Initialize to make gcc happy.  */
 
73
  int res = -1;
 
74
 
 
75
  int nports = ENDPORT - startport + 1;
 
76
  int endport = ENDPORT;
 
77
 again:
 
78
  for (i = 0; i < nports; ++i)
 
79
    {
 
80
      sin->sin_port = htons (port++);
 
81
      if (port > endport)
 
82
        port = startport;
 
83
      res = __bind (sd, sin, sizeof (struct sockaddr_in));
 
84
      if (res >= 0 || errno != EADDRINUSE)
 
85
        break;
 
86
    }
 
87
 
 
88
  if (i == nports && startport != LOWPORT)
 
89
    {
 
90
      startport = LOWPORT;
 
91
      endport = STARTPORT - 1;
 
92
      nports = STARTPORT - LOWPORT;
 
93
      port = LOWPORT + port % (STARTPORT - LOWPORT);
 
94
      goto again;
 
95
    }
 
96
 
 
97
  return res;
 
98
}
 
99
libc_hidden_def (bindresvport)