mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Add Port to *bindAddress.
svn:r1901
This commit is contained in:
parent
553b0a4f51
commit
d95f347b14
2
doc/TODO
2
doc/TODO
@ -15,7 +15,7 @@ For 0.0.7:
|
|||||||
o allow multiple log files
|
o allow multiple log files
|
||||||
o the keep-trying-to-build-intropoints-always bug.
|
o the keep-trying-to-build-intropoints-always bug.
|
||||||
- *bindaddress
|
- *bindaddress
|
||||||
- include the port
|
o include the port
|
||||||
- allow multiple of them
|
- allow multiple of them
|
||||||
- have an allow/deny series for them
|
- have an allow/deny series for them
|
||||||
- break exitpolicy into multiple config lines
|
- break exitpolicy into multiple config lines
|
||||||
|
@ -317,20 +317,37 @@ void connection_expire_held_open(void)
|
|||||||
/** Bind a new non-blocking socket listening to
|
/** Bind a new non-blocking socket listening to
|
||||||
* <b>bindaddress</b>:<b>bindport</b>, and add this new connection
|
* <b>bindaddress</b>:<b>bindport</b>, and add this new connection
|
||||||
* (of type <b>type</b>) to the connection array.
|
* (of type <b>type</b>) to the connection array.
|
||||||
|
*
|
||||||
|
* If <b>bindaddress</b> includes a port, we bind on that port; otherwise, we
|
||||||
|
* use bindport.
|
||||||
*/
|
*/
|
||||||
int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
|
int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
|
||||||
struct sockaddr_in bindaddr; /* where to bind */
|
struct sockaddr_in bindaddr; /* where to bind */
|
||||||
connection_t *conn;
|
connection_t *conn;
|
||||||
|
char *hostname, *cp;
|
||||||
|
int usePort;
|
||||||
int s; /* the socket we're going to make */
|
int s; /* the socket we're going to make */
|
||||||
int one=1;
|
int one=1;
|
||||||
|
|
||||||
|
|
||||||
|
cp = strchr(bindaddress, ':');
|
||||||
|
if (cp) {
|
||||||
|
hostname = tor_strndup(bindaddress, cp-bindaddress);
|
||||||
|
usePort = atoi(cp+1);
|
||||||
|
} else {
|
||||||
|
hostname = tor_strdup(bindaddress);
|
||||||
|
usePort = bindport;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&bindaddr,0,sizeof(struct sockaddr_in));
|
memset(&bindaddr,0,sizeof(struct sockaddr_in));
|
||||||
bindaddr.sin_family = AF_INET;
|
bindaddr.sin_family = AF_INET;
|
||||||
bindaddr.sin_port = htons(bindport);
|
bindaddr.sin_port = htons(usePort);
|
||||||
if(tor_lookup_hostname(bindaddress, &(bindaddr.sin_addr.s_addr)) != 0) {
|
if(tor_lookup_hostname(hostname, &(bindaddr.sin_addr.s_addr)) != 0) {
|
||||||
log_fn(LOG_WARN,"Can't resolve BindAddress %s",bindaddress);
|
log_fn(LOG_WARN,"Can't resolve BindAddress %s",hostname);
|
||||||
|
tor_free(hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
tor_free(hostname);
|
||||||
|
|
||||||
s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
|
s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
@ -341,13 +358,13 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
|
|||||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
|
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
|
||||||
|
|
||||||
if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
|
if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
|
||||||
log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport,
|
log_fn(LOG_WARN,"Could not bind to port %u: %s",usePort,
|
||||||
tor_socket_strerror(tor_socket_errno(s)));
|
tor_socket_strerror(tor_socket_errno(s)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(listen(s,SOMAXCONN) < 0) {
|
if(listen(s,SOMAXCONN) < 0) {
|
||||||
log_fn(LOG_WARN,"Could not listen on port %u: %s",bindport,
|
log_fn(LOG_WARN,"Could not listen on port %u: %s",usePort,
|
||||||
tor_socket_strerror(tor_socket_errno(s)));
|
tor_socket_strerror(tor_socket_errno(s)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -363,7 +380,7 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_fn(LOG_DEBUG,"%s listening on port %u.",conn_type_to_string[type], bindport);
|
log_fn(LOG_DEBUG,"%s listening on port %u.",conn_type_to_string[type], usePort);
|
||||||
|
|
||||||
conn->state = LISTENER_STATE_READY;
|
conn->state = LISTENER_STATE_READY;
|
||||||
connection_start_reading(conn);
|
connection_start_reading(conn);
|
||||||
|
Loading…
Reference in New Issue
Block a user