[Privoxy-devel] Feature Enhancement: Support for outgoing address (TODO#77)
Fabian Keil
fk at fabiankeil.de
Thu Feb 15 15:50:07 UTC 2018
Christian Kröger <ck at tfmt.de> wrote:
> > On 15. Feb 2018, at 09:54, Fabian Keil <fk at fabiankeil.de> wrote:
> >
> > Christian Kröger <ck at tfmt.de> wrote:
> >> Since I couldn’t find any official Git repository for Privoxy, I’ve made
> >> the changes against 3.0.26-stable and pushed it to a Git(hub) repository
> >> which can be found here:
> >>
> >> https://github.com/commx/privoxy/pull/1
> >
> > Please use "git format-patch" and send the patch to this thread.
Looks like I was a bit unclear. I meant the whole output of
"git format-patch" so one can conveniently apply it with
"git am".
BTW, a test repository can now be cloned with:
$ git clone https://www.privoxy.org/git/privoxy.git
This isn't official yet and hashes will change in the
near future, but the code should stay the same.
The master branch contains the code from the CVS HEAD.
> ---
> config | 27 +++++++++++++++++
This file is generated from doc/source/p-config.sgml
and shouldn't be edited manually.
> diff --git a/jbsockets.c b/jbsockets.c
> index 9db4270..734d15b 100644
> --- a/jbsockets.c
> +++ b/jbsockets.c
> @@ -150,6 +150,98 @@ static void set_no_delay_flag(int fd)
> #endif /* def TCP_NODELAY */
> }
[...]
> +/*********************************************************************
> + *
> + * Function : set_outgoing_address
> + *
> + * Description : Set outgoing address for socket connections.
> + *
> + * Parameters :
> + * 1 : fd = The file descriptor to operate on
> + * 2 : af = Address family (AF_INET or AF_INET6) of the socket
> + * 3 : csp = Current client state (buffers, headers, etc...)
Please move the csp to position 1 to me more consistent with
the other functions.
> + * Returns : void
> + *
> + *********************************************************************/
> +static void set_outgoing_address(int fd, int af, struct client_state *csp)
> +{
> + int i, j, rc, enable = 1;
Please initialise enable after the declaration block.
> + const struct addrinfo *addrinfo[MAX_OUTGOING_ADDRESSES];
> + const struct addrinfo *rp;
> +
> + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) != 0)
> + {
> + log_error(LOG_LEVEL_ERROR,
> + "Failed to set SO_REUSEADDR on socket %d", fd);
> + return;
> + }
> +
> + // filter matching address family
Please use traditional comment markers (/* ... */).
> + for (i = 0, j = 0; i < MAX_OUTGOING_ADDRESSES; i++)
> + {
> + rp = csp->config->outgoing_addresses[i];
> + if (rp != NULL && rp->ai_family == af)
> + addrinfo[j++] = rp;
> + }
> +
> + if (j == 0)
Isn't j always 0 here?
> + {
> + log_error(LOG_LEVEL_ERROR,
> + "No outgoing address for %s found",
> + (af == AF_INET) ? "AF_INET" : "AF_INET6");
> + return;
> + }
>
> + // pick address randomly in case there are more than one
> + i = (j > 1) ? rand() % j : 0;
Please use pick_from_range() here.
Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.privoxy.org/pipermail/privoxy-devel/attachments/20180215/9f3283be/attachment.bin>
More information about the Privoxy-devel
mailing list