diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-05-08 12:02:49 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-05-08 12:02:49 +0000 |
commit | 2912ade365b2f3192f42af5aca9edd29256e0956 (patch) | |
tree | 6da4e4da16d377fe822283a075982e0303702b44 /src/gns/nss | |
parent | 95c53a7451be0ede2a2bad5ee8f7160e85342a11 (diff) | |
download | gnunet-2912ade365b2f3192f42af5aca9edd29256e0956.tar.gz gnunet-2912ade365b2f3192f42af5aca9edd29256e0956.zip |
-nss build files
Diffstat (limited to 'src/gns/nss')
-rw-r--r-- | src/gns/nss/Makefile.am | 57 | ||||
-rw-r--r-- | src/gns/nss/map-file | 14 | ||||
-rw-r--r-- | src/gns/nss/nss_gns.c | 7 | ||||
-rw-r--r-- | src/gns/nss/query.h | 56 | ||||
-rw-r--r-- | src/gns/nss/util.c | 207 | ||||
-rw-r--r-- | src/gns/nss/util.h | 47 |
6 files changed, 384 insertions, 4 deletions
diff --git a/src/gns/nss/Makefile.am b/src/gns/nss/Makefile.am new file mode 100644 index 000000000..f77743e5c --- /dev/null +++ b/src/gns/nss/Makefile.am | |||
@@ -0,0 +1,57 @@ | |||
1 | # $Id$ | ||
2 | # | ||
3 | # This file taken and modified from nss-gns. | ||
4 | # | ||
5 | # nss-gns is free software; you can redistribute it and/or modify it | ||
6 | # under the terms of the GNU Lesser General Public License as | ||
7 | # published by the Free Software Foundation; either version 2 of the | ||
8 | # License, or (at your option) any later version. | ||
9 | # | ||
10 | # nss-gns is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU Lesser General Public | ||
16 | # License along with nss-gns; if not, write to the Free Software | ||
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
18 | # USA. | ||
19 | |||
20 | EXTRA_DIST = map-file | ||
21 | |||
22 | # This cool debug trap works on i386/gcc only | ||
23 | AM_CFLAGS='-DDEBUG_TRAP=__asm__("int $$3")' | ||
24 | |||
25 | AM_LDFLAGS=-avoid-version -module -export-dynamic | ||
26 | |||
27 | lib_LTLIBRARIES = | ||
28 | |||
29 | lib_LTLIBRARIES += \ | ||
30 | libnss_gns.la \ | ||
31 | libnss_gns4.la \ | ||
32 | libnss_gns6.la | ||
33 | |||
34 | sources = util.c util.h query.h | ||
35 | |||
36 | # GNU Libc | ||
37 | libnss_gns_la_SOURCES= $(sources) nss_gns.c | ||
38 | libnss_gns_la_CFLAGS=$(AM_CFLAGS) | ||
39 | libnss_gns_la_LDFLAGS=$(AM_LDFLAGS) -shrext .so.2 -Wl,-version-script=$(srcdir)/map-file | ||
40 | |||
41 | libnss_gns4_la_SOURCES=$(libnss_gns_la_SOURCES) | ||
42 | libnss_gns4_la_CFLAGS=$(libnss_gns_la_CFLAGS) -DNSS_IPV4_ONLY=1 | ||
43 | libnss_gns4_la_LDFLAGS=$(libnss_gns_la_LDFLAGS) | ||
44 | |||
45 | libnss_gns6_la_SOURCES=$(libnss_gns_la_SOURCES) | ||
46 | libnss_gns6_la_CFLAGS=$(libnss_gns_la_CFLAGS) -DNSS_IPV6_ONLY=1 | ||
47 | libnss_gns6_la_LDFLAGS=$(libnss_gns_la_LDFLAGS) | ||
48 | |||
49 | install-exec-hook: | ||
50 | rm -f $(DESTDIR)$(libdir)/libnss_gns.la | ||
51 | rm -f $(DESTDIR)$(libdir)/libnss_gns4.la | ||
52 | rm -f $(DESTDIR)$(libdir)/libnss_gns6.la | ||
53 | |||
54 | uninstall-hook: | ||
55 | rm -f $(DESTDIR)$(libdir)/libnss_gns.so.2 | ||
56 | rm -f $(DESTDIR)$(libdir)/libnss_gns4.so.2 | ||
57 | rm -f $(DESTDIR)$(libdir)/libnss_gns6.so.2 | ||
diff --git a/src/gns/nss/map-file b/src/gns/nss/map-file new file mode 100644 index 000000000..476d0ac3e --- /dev/null +++ b/src/gns/nss/map-file | |||
@@ -0,0 +1,14 @@ | |||
1 | NSSGNS_0 { | ||
2 | global: | ||
3 | _nss_gns_gethostbyaddr_r; | ||
4 | _nss_gns4_gethostbyaddr_r; | ||
5 | _nss_gns6_gethostbyaddr_r; | ||
6 | _nss_gns_gethostbyname_r; | ||
7 | _nss_gns4_gethostbyname_r; | ||
8 | _nss_gns6_gethostbyname_r; | ||
9 | _nss_gns_gethostbyname2_r; | ||
10 | _nss_gns4_gethostbyname2_r; | ||
11 | _nss_gns6_gethostbyname2_r; | ||
12 | local: | ||
13 | *; | ||
14 | }; | ||
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index 9755ea111..0fe8a75ba 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c | |||
@@ -19,10 +19,7 @@ | |||
19 | USA. | 19 | USA. |
20 | ***/ | 20 | ***/ |
21 | 21 | ||
22 | #ifdef HAVE_CONFIG_H | 22 | #include <gnunet_config.h> |
23 | #include <config.h> | ||
24 | #endif | ||
25 | |||
26 | #include <unistd.h> | 23 | #include <unistd.h> |
27 | #include <errno.h> | 24 | #include <errno.h> |
28 | #include <string.h> | 25 | #include <string.h> |
@@ -33,6 +30,8 @@ | |||
33 | #include <stdio.h> | 30 | #include <stdio.h> |
34 | #include <stdlib.h> | 31 | #include <stdlib.h> |
35 | 32 | ||
33 | #include "query.h" | ||
34 | |||
36 | #ifdef NSS_IPV4_ONLY | 35 | #ifdef NSS_IPV4_ONLY |
37 | #define _nss_mdns_gethostbyname2_r _nss_gns4_minimal_gethostbyname2_r | 36 | #define _nss_mdns_gethostbyname2_r _nss_gns4_minimal_gethostbyname2_r |
38 | #define _nss_mdns_gethostbyname_r _nss_gns4_minimal_gethostbyname_r | 37 | #define _nss_mdns_gethostbyname_r _nss_gns4_minimal_gethostbyname_r |
diff --git a/src/gns/nss/query.h b/src/gns/nss/query.h new file mode 100644 index 000000000..03148f60b --- /dev/null +++ b/src/gns/nss/query.h | |||
@@ -0,0 +1,56 @@ | |||
1 | #ifndef fooqueryhfoo | ||
2 | #define fooqueryhfoo | ||
3 | |||
4 | /* $Id$ */ | ||
5 | |||
6 | /*** | ||
7 | This file is part of nss-mdns. | ||
8 | |||
9 | nss-mdns is free software; you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Lesser General Public License as | ||
11 | published by the Free Software Foundation; either version 2 of the | ||
12 | License, or (at your option) any later version. | ||
13 | |||
14 | nss-mdns is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU Lesser General Public | ||
20 | License along with nss-mdns; if not, write to the Free Software | ||
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
22 | USA. | ||
23 | ***/ | ||
24 | |||
25 | #include <inttypes.h> | ||
26 | |||
27 | typedef struct { | ||
28 | uint32_t address; | ||
29 | } ipv4_address_t; | ||
30 | |||
31 | typedef struct { | ||
32 | uint8_t address[16]; | ||
33 | } ipv6_address_t; | ||
34 | |||
35 | int gns_open_socket(void); | ||
36 | |||
37 | int gns_query_name(int fd, | ||
38 | const char *name, | ||
39 | void (*ipv4_func)(const ipv4_address_t *ipv4, void *userdata), | ||
40 | void (*ipv6_func)(const ipv6_address_t *ipv6, void *userdata), | ||
41 | void *userdata); | ||
42 | |||
43 | #ifndef NSS_IPV6_ONLY | ||
44 | int gns_query_ipv4(int fd, | ||
45 | const ipv4_address_t *ipv4, | ||
46 | void (*name_func)(const char *name, void *userdata), | ||
47 | void *userdata); | ||
48 | #endif | ||
49 | #ifndef NSS_IPV4_ONLY | ||
50 | int gns_query_ipv6(int fd, | ||
51 | const ipv6_address_t *ipv6, | ||
52 | void (*name_func)(const char *name, void *userdata), | ||
53 | void *userdata); | ||
54 | #endif | ||
55 | |||
56 | #endif | ||
diff --git a/src/gns/nss/util.c b/src/gns/nss/util.c new file mode 100644 index 000000000..7349d6b1f --- /dev/null +++ b/src/gns/nss/util.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | /*** | ||
4 | This file is part of nss-mdns. | ||
5 | |||
6 | nss-mdns is free software; you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Lesser General Public License as | ||
8 | published by the Free Software Foundation; either version 2 of the | ||
9 | License, or (at your option) any later version. | ||
10 | |||
11 | nss-mdns is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with nss-mdns; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | USA. | ||
20 | ***/ | ||
21 | |||
22 | #include <gnunet_config.h> | ||
23 | |||
24 | #include <sys/select.h> | ||
25 | #include <errno.h> | ||
26 | #include <string.h> | ||
27 | #include <assert.h> | ||
28 | #include <fcntl.h> | ||
29 | |||
30 | #include "util.h" | ||
31 | |||
32 | #ifdef ENABLE_LEGACY | ||
33 | |||
34 | /* Calculate the difference between the two specfified timeval | ||
35 | * timestamsps. */ | ||
36 | usec_t timeval_diff(const struct timeval *a, const struct timeval *b) { | ||
37 | usec_t r; | ||
38 | assert(a && b); | ||
39 | |||
40 | /* Check which whan is the earlier time and swap the two arguments if reuqired. */ | ||
41 | if (timeval_cmp(a, b) < 0) { | ||
42 | const struct timeval *c; | ||
43 | c = a; | ||
44 | a = b; | ||
45 | b = c; | ||
46 | } | ||
47 | |||
48 | /* Calculate the second difference*/ | ||
49 | r = ((usec_t) a->tv_sec - b->tv_sec)* 1000000; | ||
50 | |||
51 | /* Calculate the microsecond difference */ | ||
52 | if (a->tv_usec > b->tv_usec) | ||
53 | r += ((usec_t) a->tv_usec - b->tv_usec); | ||
54 | else if (a->tv_usec < b->tv_usec) | ||
55 | r -= ((usec_t) b->tv_usec - a->tv_usec); | ||
56 | |||
57 | return r; | ||
58 | } | ||
59 | |||
60 | /* Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwse */ | ||
61 | int timeval_cmp(const struct timeval *a, const struct timeval *b) { | ||
62 | assert(a && b); | ||
63 | |||
64 | if (a->tv_sec < b->tv_sec) | ||
65 | return -1; | ||
66 | |||
67 | if (a->tv_sec > b->tv_sec) | ||
68 | return 1; | ||
69 | |||
70 | if (a->tv_usec < b->tv_usec) | ||
71 | return -1; | ||
72 | |||
73 | if (a->tv_usec > b->tv_usec) | ||
74 | return 1; | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | /* Return the time difference between now and the specified timestamp */ | ||
80 | usec_t timeval_age(const struct timeval *tv) { | ||
81 | struct timeval now; | ||
82 | assert(tv); | ||
83 | gettimeofday(&now, NULL); | ||
84 | return timeval_diff(&now, tv); | ||
85 | } | ||
86 | |||
87 | /* Add the specified time inmicroseconds to the specified timeval structure */ | ||
88 | void timeval_add(struct timeval *tv, usec_t v) { | ||
89 | unsigned long secs; | ||
90 | assert(tv); | ||
91 | |||
92 | secs = (v/1000000); | ||
93 | tv->tv_sec += (unsigned long) secs; | ||
94 | v -= secs*1000000; | ||
95 | |||
96 | tv->tv_usec += v; | ||
97 | |||
98 | /* Normalize */ | ||
99 | while (tv->tv_usec >= 1000000) { | ||
100 | tv->tv_sec++; | ||
101 | tv->tv_usec -= 1000000; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | int set_nonblock(int fd) { | ||
106 | int n; | ||
107 | assert(fd >= 0); | ||
108 | |||
109 | if ((n = fcntl(fd, F_GETFL)) < 0) | ||
110 | return -1; | ||
111 | |||
112 | if (n & O_NONBLOCK) | ||
113 | return 0; | ||
114 | |||
115 | return fcntl(fd, F_SETFL, n|O_NONBLOCK); | ||
116 | } | ||
117 | |||
118 | int wait_for_write(int fd, struct timeval *end) { | ||
119 | struct timeval now; | ||
120 | |||
121 | if (end) | ||
122 | gettimeofday(&now, NULL); | ||
123 | |||
124 | for (;;) { | ||
125 | struct timeval tv; | ||
126 | fd_set fds; | ||
127 | int r; | ||
128 | |||
129 | FD_ZERO(&fds); | ||
130 | FD_SET(fd, &fds); | ||
131 | |||
132 | if (end) { | ||
133 | if (timeval_cmp(&now, end) >= 0) | ||
134 | return 1; | ||
135 | |||
136 | tv.tv_sec = tv.tv_usec = 0; | ||
137 | timeval_add(&tv, timeval_diff(end, &now)); | ||
138 | } | ||
139 | |||
140 | if ((r = select(fd+1, NULL, &fds, NULL, end ? &tv : NULL)) < 0) { | ||
141 | if (errno != EINTR) | ||
142 | return -1; | ||
143 | } else if (r == 0) | ||
144 | return 1; | ||
145 | else { | ||
146 | if (FD_ISSET(fd, &fds)) | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | if (end) | ||
151 | gettimeofday(&now, NULL); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | int wait_for_read(int fd, struct timeval *end) { | ||
156 | struct timeval now; | ||
157 | |||
158 | if (end) | ||
159 | gettimeofday(&now, NULL); | ||
160 | |||
161 | for (;;) { | ||
162 | struct timeval tv; | ||
163 | fd_set fds; | ||
164 | int r; | ||
165 | |||
166 | FD_ZERO(&fds); | ||
167 | FD_SET(fd, &fds); | ||
168 | |||
169 | if (end) { | ||
170 | if (timeval_cmp(&now, end) >= 0) | ||
171 | return 1; | ||
172 | |||
173 | tv.tv_sec = tv.tv_usec = 0; | ||
174 | timeval_add(&tv, timeval_diff(end, &now)); | ||
175 | } | ||
176 | |||
177 | if ((r = select(fd+1, &fds, NULL, NULL, end ? &tv : NULL)) < 0) { | ||
178 | if (errno != EINTR) | ||
179 | return -1; | ||
180 | } else if (r == 0) | ||
181 | return 1; | ||
182 | else { | ||
183 | |||
184 | if (FD_ISSET(fd, &fds)) | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | if (end) | ||
189 | gettimeofday(&now, NULL); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | #endif | ||
194 | |||
195 | int set_cloexec(int fd) { | ||
196 | int n; | ||
197 | assert(fd >= 0); | ||
198 | |||
199 | if ((n = fcntl(fd, F_GETFD)) < 0) | ||
200 | return -1; | ||
201 | |||
202 | if (n & FD_CLOEXEC) | ||
203 | return 0; | ||
204 | |||
205 | return fcntl(fd, F_SETFD, n|FD_CLOEXEC); | ||
206 | } | ||
207 | |||
diff --git a/src/gns/nss/util.h b/src/gns/nss/util.h new file mode 100644 index 000000000..e2334ad23 --- /dev/null +++ b/src/gns/nss/util.h | |||
@@ -0,0 +1,47 @@ | |||
1 | #ifndef fooutilhfoo | ||
2 | #define fooutilhfoo | ||
3 | |||
4 | /* $Id$ */ | ||
5 | |||
6 | /*** | ||
7 | This file is part of nss-mdns. | ||
8 | |||
9 | nss-mdns is free software; you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Lesser General Public License as | ||
11 | published by the Free Software Foundation; either version 2 of the | ||
12 | License, or (at your option) any later version. | ||
13 | |||
14 | nss-mdns is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU Lesser General Public | ||
20 | License along with nss-mdns; if not, write to the Free Software | ||
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
22 | USA. | ||
23 | ***/ | ||
24 | |||
25 | #include <sys/time.h> | ||
26 | #include <time.h> | ||
27 | #include <inttypes.h> | ||
28 | |||
29 | #ifdef ENABLE_LEGACY | ||
30 | typedef uint64_t usec_t; | ||
31 | |||
32 | usec_t timeval_diff(const struct timeval *a, const struct timeval *b); | ||
33 | int timeval_cmp(const struct timeval *a, const struct timeval *b); | ||
34 | usec_t timeval_age(const struct timeval *tv); | ||
35 | void timeval_add(struct timeval *tv, usec_t v); | ||
36 | |||
37 | int set_nonblock(int fd); | ||
38 | |||
39 | int wait_for_write(int fd, struct timeval *end); | ||
40 | int wait_for_read(int fd, struct timeval *end); | ||
41 | |||
42 | #endif | ||
43 | |||
44 | int set_cloexec(int fd); | ||
45 | |||
46 | |||
47 | #endif | ||