2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is MPEG4IP.
14
* The Initial Developer of the Original Code is Cisco Systems Inc.
15
* Portions created by Cisco Systems Inc. are
16
* Copyright (C) Cisco Systems Inc. 2000, 2001. All Rights Reserved.
19
* Bill May wmay@cisco.com
22
* ip_port.cpp - reserve IP port numbers for audio/video RTP streams
26
#include "player_util.h"
27
#include "our_config_file.h"
30
* CIpPort::CIpPort() - create ip socket, bind it to the local address
31
* (which assigns it a port number), and figure out what the port number
34
CIpPort::CIpPort (in_port_t startport, in_port_t maxport)
36
struct sockaddr_in saddr;
40
for (m_sock = -1; m_sock == -1 && startport <= maxport; startport++) {
41
// Start with min, go to max
42
m_sock = socket(AF_INET, SOCK_DGRAM, 0);
46
saddr.sin_family = AF_INET;
47
saddr.sin_addr.s_addr = INADDR_ANY;
48
saddr.sin_port = htons(startport);
49
if (bind(m_sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
58
socklen = sizeof(saddr);
59
if (getsockname(m_sock, (struct sockaddr *)&saddr, &socklen) < 0) {
65
m_port_num = ntohs(saddr.sin_port);
69
* CIpPort::~CIpPort() - close the socket we opened.
71
CIpPort::~CIpPort (void)
80
* C2ConsecIpPort::C2ConsecIpPort() - get 2 consecutive, even-odd, ip
83
C2ConsecIpPort::C2ConsecIpPort (CIpPort **global, in_port_t start_port)
86
m_first = m_second = NULL;
87
in_port_t firstport, maxport;
89
maxport = (in_port_t)~0;
90
if (start_port == 0) {
92
if (config.get_config_value(CONFIG_IPPORT_MIN) != UINT32_MAX) {
93
firstport = config.get_config_value(CONFIG_IPPORT_MIN);
94
if (config.get_config_value(CONFIG_IPPORT_MAX) != UINT32_MAX) {
95
maxport = config.get_config_value(CONFIG_IPPORT_MAX);
96
if (maxport <= firstport) {
97
player_error_message("IP port configuration error - %u %u - using 65535 as max port value",
99
maxport = (in_port_t)~0;
104
firstport = start_port;
107
// first, get an even port number. If not even, save it in the
110
newone = new CIpPort(firstport, maxport);
111
if (newone->valid() == 0)
113
if ((newone->get_port_num() & 0x1) == 0x1) {
114
newone->set_next(*global);
118
} while ((newone->get_port_num() & 0x1) == 0x1);
120
player_debug_message("First port is %d", newone->get_port_num());
122
// Okay, save the first, get the 2nd. If okay, just return
125
next = m_first->get_port_num() + 1;
126
m_second = new CIpPort(next, next);
127
if ((m_second->valid() == 1) &&
128
(m_second->get_port_num() == next)) {
129
player_debug_message("Ip ports are %u %u", next - 1, next);
132
player_debug_message("Got port %d invalid %d", m_second->get_port_num(),
135
// Not okay - save both off in the global queue, and try again...
136
m_first->set_next(*global);
139
firstport = m_second->get_port_num() + 1;
140
m_second->set_next(*global);
147
* C2ConsecIpPort::~C2ConsecIpPort() - just delete the CIpPorts that
150
C2ConsecIpPort::~C2ConsecIpPort (void)