annotate sources/toys/unique-port.sh @ 1196:1cdd44f2bac2

If some clever sysadmin claimed 1024-65535 for local ports, punt.
author Rob Landley <rob@landley.net>
date Thu, 05 Aug 2010 13:10:07 -0500
parents 94b0b4ef1157
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
972
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 unique_port()
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 {
1072
94b0b4ef1157 Add native-build.sh to system-image (it takes only one argument now, the build control system image file). Make system-image.sh script processing understand an INCLUDE syntax to insert unique-port, and trim the unique-port comment to something less distracting.
Rob Landley <rob@landley.net>
parents: 972
diff changeset
3 # Try to find an unused port number for each running instance of the program.
972
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 START=8192
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START]
1196
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
7 if [ $RANGE -lt 8 ]
972
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 then
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 START=$[$(awk '{print $2}' /proc/sys/net/ipv4/ip_local_port_range)]
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 RANGE=$[65535-$START]
1196
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
11 if [ $RANGE -lt 8 ]
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
12 then
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
13 START=16384
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
14 RANGE=32768
1cdd44f2bac2 If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents: 1072
diff changeset
15 fi
972
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 fi
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 echo $[($$%$RANGE)+$START]
cfa6262528f3 Genericize native build.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 }