Try to enumerate all network interfaces using 'ifconfig'.
54{
55 int i;
59 char ifc[12];
60 char addrstr[128];
61 char bcstr[128];
62 char netmaskstr[128];
64 int have_ifc;
65 struct sockaddr_in a4;
66 struct sockaddr_in6 a6;
67 struct in_addr v4;
68 struct in6_addr v6;
69 struct sockaddr_in bcaddr;
70 struct sockaddr_in netmask;
71 struct sockaddr_in6 netmask6;
72 struct sockaddr *pass_bcaddr;
73 struct sockaddr *pass_netmask;
74 int prefixlen;
75 static char *pcall;
76
77 if (NULL == pcall)
78 {
79 const char *sbin_ifconfig;
80
81#ifdef IFCONFIG
82 if (0 == access (IFCONFIG, X_OK))
83 sbin_ifconfig = IFCONFIG;
84 else
85#endif
86 if (0 == access ("/sbin/ifconfig", X_OK))
87 sbin_ifconfig = "/sbin/ifconfig";
88 else if (0 == access ("/usr/sbin/ifconfig", X_OK))
89 sbin_ifconfig = "/usr/sbin/ifconfig";
90 else
91 sbin_ifconfig = "ifconfig";
93 "%s -a 2> /dev/null",
94 sbin_ifconfig);
95 }
96 f = popen (pcall,
"r");
98 {
100 "popen",
101 "ifconfig");
102
104 }
105
107 ifc[11] = '\0';
108 while (NULL != fgets (
line,
sizeof(
line),
f))
109 {
110 if (strlen (
line) == 0)
111 {
113 continue;
114 }
115 if (! isspace (
line[0]))
116 {
118
119 if (ifc[strlen (ifc) - 1] == ':')
120 ifc[strlen (ifc) - 1] = '\0';
121 continue;
122 }
123 if (! have_ifc)
124 continue;
125
126
128 {
131 }
132 prefixlen = -1;
133
135 while ((
'\0' != *
start) && (isspace (*
start)))
137
138
139 memset (addrstr, 0, 128);
140 memset (netmaskstr, 0, 128);
141 memset (bcstr, 0, 128);
142 prefixlen = 0;
143
144 if (
145 (3 == sscanf (
start,
"inet addr:%127s Bcast:%127s Mask:%127s", addrstr,
146 bcstr, netmaskstr)) ||
147 (2 == sscanf (
start,
"inet addr:%127s Mask:%127s", addrstr,
148 netmaskstr)) ||
149 (2 == sscanf (
start,
"inet6 addr:%127s %d", addrstr, &prefixlen)) ||
150
151 (1 == sscanf (
start,
"inet %127s", addrstr)) ||
152 (1 == sscanf (
start,
"inet6 %127s", addrstr)))
153 {
154
155 if (1 == inet_pton (AF_INET, addrstr, &v4))
156 {
157 memset (&a4, 0, sizeof(a4));
158 a4.sin_family = AF_INET;
159#if HAVE_SOCKADDR_IN_SIN_LEN
160 a4.sin_len = (u_char) sizeof(struct sockaddr_in);
161#endif
162 a4.sin_addr = v4;
163
164 pass_bcaddr = NULL;
165 pass_netmask = NULL;
166 if (1 == inet_pton (AF_INET, bcstr, &v4))
167 {
168 memset (&bcaddr, 0, sizeof(bcaddr));
169 bcaddr.sin_family = AF_INET;
170#if HAVE_SOCKADDR_IN_SIN_LEN
171 bcaddr.sin_len = (u_char) sizeof(struct sockaddr_in);
172#endif
173 bcaddr.sin_addr = v4;
174 pass_bcaddr = (struct sockaddr *) &bcaddr;
175 }
176 if (1 == inet_pton (AF_INET, netmaskstr, &v4))
177 {
178 memset (&netmask, 0, sizeof(netmask));
179 netmask.sin_family = AF_INET;
180#if HAVE_SOCKADDR_IN_SIN_LEN
181 netmask.sin_len = (u_char) sizeof(struct sockaddr_in);
182#endif
183 netmask.sin_addr = v4;
184 pass_netmask = (struct sockaddr *) &netmask;
185 }
186
187
189 proc (proc_cls, ifc,(0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE)),
190 (const struct sockaddr *) &a4,
191 pass_bcaddr, pass_netmask, sizeof(a4)))
192 break;
193 continue;
194 }
195
196 if (1 == inet_pton (AF_INET6, addrstr, &v6))
197 {
198 memset (&a6, 0, sizeof(a6));
199 a6.sin6_family = AF_INET6;
200#if HAVE_SOCKADDR_IN_SIN_LEN
201 a6.sin6_len = (u_char) sizeof(struct sockaddr_in6);
202#endif
203 a6.sin6_addr = v6;
204
205 pass_netmask = NULL;
206 if (prefixlen != -1)
207 {
208 memset (v6.s6_addr, 0, sizeof(v6.s6_addr));
209 for (i = 0; i < prefixlen; i++)
210 {
211 v6.s6_addr[i >> 3] |= 1 << (i & 7);
212 }
213 memset (&netmask6, 0, sizeof(netmask6));
214 netmask6.sin6_family = AF_INET6;
215#if HAVE_SOCKADDR_IN_SIN_LEN
216 netmask6.sin6_len = (u_char) sizeof(struct sockaddr_in6);
217#endif
218 netmask6.sin6_addr = v6;
219
220 pass_netmask = (struct sockaddr *) &netmask6;
221 }
222
224 proc (proc_cls, ifc,(0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE)),
225 (const struct sockaddr *) &a6,
226 NULL, pass_netmask, sizeof(a6)))
227 break;
228 continue;
229 }
230 }
231 }
234}
static int start
Set if we are to start default services (including ARM).
static char * line
Desired phone line (string to be converted to a hash).
static int replace
Replace DID Document Flag.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define LOG_STRERROR_FILE(kind, syscall, filename)