Check-in [525f68fcf8]
Overview
Comment:Added working addr and ipv4 conversion functions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 525f68fcf86ab5296a2b7a0480976eca7ac3bddd
User & Date: rkeene on 2006-12-17 03:35:15
Other Links: manifest | tags
Context
2006-12-17
03:48
Removed attempts to set lc_errno to NONE check-in: 8e434a0cbf user: rkeene tags: trunk
03:35
Added working addr and ipv4 conversion functions check-in: 525f68fcf8 user: rkeene tags: trunk
03:04
Added an "ADDR" var type (since it was already documented) Removed brain-dead (void *) to type casts in lc_handle_...() check-in: e07808cac6 user: rkeene tags: trunk
Changes

Modified config.h.in from [003ec03eae] to [282078a7c0].

19
20
21
22
23
24
25






26
27
28
29
30
31
32
#undef HAVE_INTTYPES_H

/* Define to 1 if you have fopen_net from libopennet */
#undef HAVE_LIBOPENNET

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H







/* Define to 1 if you have the <opennet.h> header file. */
#undef HAVE_OPENNET_H

/* Define to 1 if you have the <pwd.h> header file. */
#undef HAVE_PWD_H








>
>
>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#undef HAVE_INTTYPES_H

/* Define to 1 if you have fopen_net from libopennet */
#undef HAVE_LIBOPENNET

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H

/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H

/* Define to 1 if you have the <opennet.h> header file. */
#undef HAVE_OPENNET_H

/* Define to 1 if you have the <pwd.h> header file. */
#undef HAVE_PWD_H

Modified configure from [9aa86e081f] to [cbe500dd7e].

16644
16645
16646
16647
16648
16649
16650


16651
16652
16653
16654
16655
16656
16657
16658









for ac_header in ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo $ECHO_N "(cached) $ECHO_C" >&6







>
>
|







16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660









for ac_header in ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h netdb.h netinet/in.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
16792
16793
16794
16795
16796
16797
16798

16799
16800
16801
16802
16803
16804
16805
  cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF

fi

done


echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5
echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6
if test "${ac_cv_header_time+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  cat >conftest.$ac_ext <<_ACEOF







>







16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
  cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF

fi

done


echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5
echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6
if test "${ac_cv_header_time+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  cat >conftest.$ac_ext <<_ACEOF

Modified configure.ac from [1472e5abb5] to [a132a6477f].

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44

dnl Get shared objects flags, calls DC_SYNC_SHLIBOBJS but if libobjs is
dnl changed later (by AC_REPLACE_FUNCS, for example) you must call
dnl DC_SYNC_SHLIBOBJS again.
DC_GET_SHOBJFLAGS

dnl This stuff has to come after the shobjtest to verify that it is correct
AC_CHECK_HEADERS(ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h)

AC_HEADER_TIME

AC_REPLACE_FUNCS(strsep strtoll getuid)
AC_CHECK_FUNCS(getpwuid)

dnl This MUST be last.
DC_SYNC_SHLIBOBJS







|
>







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

dnl Get shared objects flags, calls DC_SYNC_SHLIBOBJS but if libobjs is
dnl changed later (by AC_REPLACE_FUNCS, for example) you must call
dnl DC_SYNC_SHLIBOBJS again.
DC_GET_SHOBJFLAGS

dnl This stuff has to come after the shobjtest to verify that it is correct
AC_CHECK_HEADERS(ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h netdb.h netinet/in.h)

AC_HEADER_TIME

AC_REPLACE_FUNCS(strsep strtoll getuid)
AC_CHECK_FUNCS(getpwuid)

dnl This MUST be last.
DC_SYNC_SHLIBOBJS

Modified libconfig.c from [a6cd32cb12] to [ccb1bb4c78].

31
32
33
34
35
36
37




38
39
40
41
42
43
44
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_PWD_H
#include <pwd.h>
#endif





struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;
const char *lc_err_usererrmsg = NULL;
const char *lc_errfile = NULL;
int lc_optind = 0;
int lc_errline = 0;







>
>
>
>







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_PWD_H
#include <pwd.h>
#endif

#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif

struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;
const char *lc_err_usererrmsg = NULL;
const char *lc_errfile = NULL;
int lc_optind = 0;
int lc_errline = 0;
56
57
58
59
60
61
62
63




64
65
66
67

68
69
70

71


72
73
74
75
76
77


















































78
79
80
81
82
83
84
85
86

87

88
89
90

91
92
93
94
95
96
97
98
99
100
101
102

103
104
105


106
107

108
109
110
111
112
113
114
115
116
117
118
119
	return(0);
}

static int lc_process_var_cidr(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) {




	return(-1);
}

static int lc_process_var_addr6(void *data, const char *value, const char **endptr) {

	return(-1);
}


static int lc_process_var_hostname4(uint32_t *data, const char *value, const char **endptr) {


	return(-1);
}

static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
	return(-1);
}



















































static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) {
	const char *dotptr = NULL;
	int tmpval = -1, retval = 0;


	dotptr = value;


	while (1) {
		tmpval = atoi(dotptr);

		if (tmpval < 0) {
			break;
		}

		retval <<= 8;
		retval |= tmpval;

		dotptr = strpbrk(dotptr, "./ \t");
		if (dotptr == NULL) {
			break;
		}
		if (*dotptr != '.') {

			break;
		}
		dotptr++;


	}


	*data = retval;

	*endptr = (char *) dotptr;

	return(0);
}

static int lc_process_var_longlong(long long *data, const char *value, const char **endptr) {
	*data = strtoll(value, (char **) endptr, 10);

	return(0);
}







|
>
>
>
>
|
|

<
>
|
|

>
|
>
>
|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
<
|

>
|
>
|
|
<
>
|
|
|

|
<
|
<
<
<
|
<
>
|
|
|
>
>


>
|
|
<
|
|







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151

152
153
154
155
156
157

158



159

160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
	return(0);
}

static int lc_process_var_cidr(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_hostname4(uint32_t *data, const char *value, const char **endptr) {
	struct hostent *ghbn_ret;

	ghbn_ret = gethostbyname(value);
	if (ghbn_ret == NULL) {
		return(-1);
	}


	if (ghbn_ret->h_length != 4) {
		return(-1);
	}

	memcpy(data, ghbn_ret->h_addr_list[0], sizeof(*data));

	*data = ntohl(*data);

	return(0);
}

static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) {
	uint32_t ipval = 0, curr_ipval = 0;
	const char *valptr;
	int retval = 0;
	int dotcount = 0;

	for (valptr = value; *valptr; valptr++) {
		if (!isdigit(*valptr)) {
			if (*valptr == '.' || *valptr == ',') {
				dotcount++;
				if (dotcount >= 4) {
					retval = -1;
					break;
				}

				if (curr_ipval > 255) {
					retval = -1;
					break;
				}

				ipval <<= 8;
				ipval |= curr_ipval;
				curr_ipval = 0;

				/* For lists */
				if (*valptr == ',') {
					break;
				}

				continue;
			} else {
				retval = -1;
				break;
			}
		}

		curr_ipval *= 10;
		curr_ipval += *valptr - '0';
	}

	if (retval == 0) {
		ipval <<= 8;
		ipval |= curr_ipval;

		*data = ipval;
	}

	return(retval);
}

static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) {

	int lc_pv_ret;

	lc_pv_ret = lc_process_var_ip4(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);
	}


	lc_pv_ret = lc_process_var_hostname4(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);
	}

	return(-1);

}





static int lc_process_var_addr6(void *data, const char *value, const char **endptr) {
	int lc_pv_ret;

	lc_pv_ret = lc_process_var_ip6(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);
	}

	lc_pv_ret = lc_process_var_hostname6(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);

	}
	return(-1);
}

static int lc_process_var_longlong(long long *data, const char *value, const char **endptr) {
	*data = strtoll(value, (char **) endptr, 10);

	return(0);
}