Wrapper function that uses gnunet-gns cli tool to resolve an IPv4/6 address.
59{
63 int retry = 0;
64 int out[2];
66
67 if (0 == getuid ())
68 return -2;
69
70query_gns:
71 if (0 != pipe (out))
72 return -1;
75 return -1;
77 {
78 const char *argv[] = { "gnunet-gns",
79 "-r",
80 "-d",
81 "-t",
82 (AF_INET6 == af) ? "AAAA" : "A",
83 "-u",
85 "-T",
87 NULL };
88
89 (void) close (STDOUT_FILENO);
90 if ((0 != close (out[0])) ||
91 (STDOUT_FILENO != dup2 (out[1], STDOUT_FILENO)))
92 _exit (1);
93 (void) execvp ("gnunet-gns", (char* const*)argv);
94 _exit (1);
95 }
96 (void) close (out[1]);
97 p = fdopen (out[0],
"r");
99 {
101 return -1;
102 }
103 while (NULL != fgets (
line,
sizeof(
line),
p))
104 {
106 break;
107 if (
line[strlen (
line) - 1] ==
'\n')
108 {
110 if (AF_INET == af)
111 {
112 if (inet_pton (af,
line, &
u->data.ipv4[
u->count]))
113 {
116 }
117 else
118 {
121 errno = EINVAL;
122 return -1;
123 }
124 }
125 else if (AF_INET6 == af)
126 {
127 if (inet_pton (af,
line, &
u->data.ipv6[
u->count]))
128 {
131 }
132 else
133 {
136 errno = EINVAL;
137 return -1;
138 }
139 }
140 }
141 }
144 if (! WIFEXITED (
ret))
145 return -1;
146 if (4 == WEXITSTATUS (
ret))
147 return -2;
148 if (5 == WEXITSTATUS (
ret))
149 {
150 if (1 == retry)
151 return -2;
152 retry = 1;
153 system ("gnunet-arm -s");
154 goto query_gns;
155 }
156 if (3 == WEXITSTATUS (
ret))
157 return -2;
158 if ((2 == WEXITSTATUS (
ret)) || (1 == WEXITSTATUS (
ret)))
159 return -2;
160 return 0;
161}
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static int ret
Final status code.
static char * line
Desired phone line (string to be converted to a hash).
static char * name
Name (label) of the records to list.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_OS_Process * p
Helper process we started.
static void kwait(pid_t chld)
#define MAX_ENTRIES
Parts taken from nss-mdns.