mirror of
https://github.com/moparisthebest/sslh
synced 2025-02-16 06:50:14 -05:00
Simplify function signatures
This commit is contained in:
parent
bcad6fbade
commit
d7bbec0dc7
12
common.c
12
common.c
@ -126,22 +126,22 @@ int bind_peer(int fd, int fd_from)
|
||||
/* Connect to first address that works and returns a file descriptor, or -1 if
|
||||
* none work.
|
||||
* If transparent proxying is on, use fd_from peer address on external address
|
||||
* of new file descriptor.
|
||||
* cnx_name points to the name of the service (for logging) */
|
||||
int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name)
|
||||
* of new file descriptor. */
|
||||
int connect_addr(struct connection *cnx, int fd_from)
|
||||
{
|
||||
struct addrinfo *a;
|
||||
char buf[NI_MAXHOST];
|
||||
int fd, res;
|
||||
|
||||
for (a = addr; a; a = a->ai_next) {
|
||||
for (a = cnx->proto->saddr; a; a = a->ai_next) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "connecting to %s family %d len %d\n",
|
||||
sprintaddr(buf, sizeof(buf), a),
|
||||
a->ai_addr->sa_family, a->ai_addrlen);
|
||||
fd = socket(a->ai_family, SOCK_STREAM, 0);
|
||||
if (fd == -1) {
|
||||
log_message(LOG_ERR, "forward to %s failed:socket: %s\n", cnx_name, strerror(errno));
|
||||
log_message(LOG_ERR, "forward to %s failed:socket: %s\n",
|
||||
cnx->proto->description, strerror(errno));
|
||||
} else {
|
||||
if (transparent) {
|
||||
res = bind_peer(fd, fd_from);
|
||||
@ -150,7 +150,7 @@ int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name)
|
||||
res = connect(fd, a->ai_addr, a->ai_addrlen);
|
||||
if (res == -1) {
|
||||
log_message(LOG_ERR, "forward to %s failed:connect: %s\n",
|
||||
cnx_name, strerror(errno));
|
||||
cnx->proto->description, strerror(errno));
|
||||
} else {
|
||||
return fd;
|
||||
}
|
||||
|
2
common.h
2
common.h
@ -84,7 +84,7 @@ struct connection {
|
||||
|
||||
/* common.c */
|
||||
void init_cnx(struct connection *cnx);
|
||||
int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name);
|
||||
int connect_addr(struct connection *cnx, int fd_from);
|
||||
int fd2fd(struct queue *target, struct queue *from);
|
||||
char* sprintaddr(char* buf, size_t size, struct addrinfo *a);
|
||||
void resolve_name(struct addrinfo **out, char* fullname);
|
||||
|
@ -69,7 +69,6 @@ void start_shoveler(int in_socket)
|
||||
{
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
struct addrinfo *saddr;
|
||||
int res = PROBE_AGAIN;
|
||||
int out_socket;
|
||||
struct connection cnx;
|
||||
@ -99,14 +98,13 @@ void start_shoveler(int in_socket)
|
||||
}
|
||||
}
|
||||
|
||||
saddr = cnx.proto->saddr;
|
||||
if (cnx.proto->service &&
|
||||
check_access_rights(in_socket, cnx.proto->service)) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Connect the target socket */
|
||||
out_socket = connect_addr(saddr, in_socket, cnx.proto->description);
|
||||
out_socket = connect_addr(&cnx, in_socket);
|
||||
CHECK_RES_DIE(out_socket, "connect");
|
||||
|
||||
cnx.q[1].fd = out_socket;
|
||||
|
@ -129,13 +129,11 @@ int accept_new_connection(int listen_socket, struct connection *cnx[], int* cnx_
|
||||
|
||||
|
||||
/* Connect queue 1 of connection to SSL; returns new file descriptor */
|
||||
int connect_queue(struct connection *cnx, struct addrinfo *addr,
|
||||
const char* cnx_name,
|
||||
fd_set *fds_r, fd_set *fds_w)
|
||||
int connect_queue(struct connection *cnx, fd_set *fds_r, fd_set *fds_w)
|
||||
{
|
||||
struct queue *q = &cnx->q[1];
|
||||
|
||||
q->fd = connect_addr(addr, cnx->q[0].fd, cnx_name);
|
||||
q->fd = connect_addr(cnx, cnx->q[0].fd);
|
||||
if ((q->fd != -1) && fd_is_in_range(q->fd)) {
|
||||
log_connection(cnx);
|
||||
set_nonblock(q->fd);
|
||||
@ -322,10 +320,7 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
||||
tidy_connection(&cnx[i], &fds_r, &fds_w);
|
||||
res = -1;
|
||||
} else {
|
||||
res = connect_queue(&cnx[i],
|
||||
cnx[i].proto->saddr,
|
||||
cnx[i].proto->description,
|
||||
&fds_r, &fds_w);
|
||||
res = connect_queue(&cnx[i], &fds_r, &fds_w);
|
||||
}
|
||||
|
||||
if (res >= max_fd)
|
||||
|
Loading…
Reference in New Issue
Block a user