kconfig/util.c
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Apr 26 21:31:05 2008 +0000 (2008-04-26)
changeset 454 372b2f397baa
child 943 1cca90ce0481
permissions -rw-r--r--
Configure tsocks with a simple heuristic.

Consider the proxy has to be in a 'local' network. It means it is directly
reachable by the local machine, even if the local machine has to hop through
one or more gates to reach the proxy (often the case in enterprise networks
where class A 10.0.0.0/8 is in fact sub-divided into smaller networks, each
one of them in a different location, eg. 10.1.0.0/16 in a place, while
10.2.0.0/16 would be on the other side of the world). Not being in the same
subnet does not mean the proxy is not available.

So we will build a mask with at most high bits set, which defines a network
that has both the local machine and the proxy. Because a machine may have
more than one interface, build a mask for each of them, removing 127.0.0.1
which is added automagically by tsocks, and removing duplicate masks.

If all of this does not work, then it means the local machine can NOT in fact
reach the proxy, which in turn means the user mis-configured something (most
probably a typo...).

/trunk/scripts/crosstool.sh | 61 52 9 0 +++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 52 insertions(+), 9 deletions(-)
yann@1
     1
/*
yann@1
     2
 * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org>
yann@1
     3
 * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org>
yann@1
     4
 *
yann@1
     5
 * Released under the terms of the GNU GPL v2.0.
yann@1
     6
 */
yann@1
     7
yann@1
     8
#include <string.h>
yann@1
     9
#include "lkc.h"
yann@1
    10
yann@1
    11
/* file already present in list? If not add it */
yann@1
    12
struct file *file_lookup(const char *name)
yann@1
    13
{
yann@1
    14
	struct file *file;
yann@1
    15
yann@1
    16
	for (file = file_list; file; file = file->next) {
yann@1
    17
		if (!strcmp(name, file->name))
yann@1
    18
			return file;
yann@1
    19
	}
yann@1
    20
yann@1
    21
	file = malloc(sizeof(*file));
yann@1
    22
	memset(file, 0, sizeof(*file));
yann@1
    23
	file->name = strdup(name);
yann@1
    24
	file->next = file_list;
yann@1
    25
	file_list = file;
yann@1
    26
	return file;
yann@1
    27
}
yann@1
    28
yann@1
    29
/* write a dependency file as used by kbuild to track dependencies */
yann@1
    30
int file_write_dep(const char *name)
yann@1
    31
{
yann@1
    32
	struct file *file;
yann@1
    33
	FILE *out;
yann@1
    34
yann@1
    35
	if (!name)
yann@1
    36
		name = ".kconfig.d";
yann@1
    37
	out = fopen("..config.tmp", "w");
yann@1
    38
	if (!out)
yann@1
    39
		return 1;
yann@1
    40
	fprintf(out, "deps_config := \\\n");
yann@1
    41
	for (file = file_list; file; file = file->next) {
yann@1
    42
		if (file->next)
yann@1
    43
			fprintf(out, "\t%s \\\n", file->name);
yann@1
    44
		else
yann@1
    45
			fprintf(out, "\t%s\n", file->name);
yann@1
    46
	}
yann@1
    47
	fprintf(out, "\ninclude/config/auto.conf: \\\n"
yann@1
    48
		     "\t$(deps_config)\n\n"
yann@1
    49
		     "$(deps_config): ;\n");
yann@1
    50
	fclose(out);
yann@1
    51
	rename("..config.tmp", name);
yann@1
    52
	return 0;
yann@1
    53
}
yann@1
    54
yann@1
    55
yann@1
    56
/* Allocate initial growable sting */
yann@1
    57
struct gstr str_new(void)
yann@1
    58
{
yann@1
    59
	struct gstr gs;
yann@1
    60
	gs.s = malloc(sizeof(char) * 64);
yann@1
    61
	gs.len = 16;
yann@1
    62
	strcpy(gs.s, "\0");
yann@1
    63
	return gs;
yann@1
    64
}
yann@1
    65
yann@1
    66
/* Allocate and assign growable string */
yann@1
    67
struct gstr str_assign(const char *s)
yann@1
    68
{
yann@1
    69
	struct gstr gs;
yann@1
    70
	gs.s = strdup(s);
yann@1
    71
	gs.len = strlen(s) + 1;
yann@1
    72
	return gs;
yann@1
    73
}
yann@1
    74
yann@1
    75
/* Free storage for growable string */
yann@1
    76
void str_free(struct gstr *gs)
yann@1
    77
{
yann@1
    78
	if (gs->s)
yann@1
    79
		free(gs->s);
yann@1
    80
	gs->s = NULL;
yann@1
    81
	gs->len = 0;
yann@1
    82
}
yann@1
    83
yann@1
    84
/* Append to growable string */
yann@1
    85
void str_append(struct gstr *gs, const char *s)
yann@1
    86
{
yann@1
    87
	size_t l = strlen(gs->s) + strlen(s) + 1;
yann@1
    88
	if (l > gs->len) {
yann@1
    89
		gs->s   = realloc(gs->s, l);
yann@1
    90
		gs->len = l;
yann@1
    91
	}
yann@1
    92
	strcat(gs->s, s);
yann@1
    93
}
yann@1
    94
yann@1
    95
/* Append printf formatted string to growable string */
yann@1
    96
void str_printf(struct gstr *gs, const char *fmt, ...)
yann@1
    97
{
yann@1
    98
	va_list ap;
yann@1
    99
	char s[10000]; /* big enough... */
yann@1
   100
	va_start(ap, fmt);
yann@1
   101
	vsnprintf(s, sizeof(s), fmt, ap);
yann@1
   102
	str_append(gs, s);
yann@1
   103
	va_end(ap);
yann@1
   104
}
yann@1
   105
yann@1
   106
/* Retrieve value of growable string */
yann@1
   107
const char *str_get(struct gstr *gs)
yann@1
   108
{
yann@1
   109
	return gs->s;
yann@1
   110
}
yann@1
   111