Lines 196-209
int callmgr_main(int argc, char **argv,
Link Here
|
196 |
/* Step 5b: Handle new connection to UNIX socket */ |
196 |
/* Step 5b: Handle new connection to UNIX socket */ |
197 |
if (FD_ISSET(unix_sock, &read_set)) { |
197 |
if (FD_ISSET(unix_sock, &read_set)) { |
198 |
/* New call! */ |
198 |
/* New call! */ |
199 |
struct sockaddr_un from; |
199 |
union { |
200 |
socklen_t len = sizeof(from); |
200 |
struct sockaddr a; |
|
|
201 |
struct sockaddr_un u; |
202 |
} from; |
203 |
socklen_t len = sizeof(from.u); |
201 |
PPTP_CALL * call; |
204 |
PPTP_CALL * call; |
202 |
struct local_callinfo *lci; |
205 |
struct local_callinfo *lci; |
203 |
int s; |
206 |
int s; |
204 |
/* Accept the socket */ |
207 |
/* Accept the socket */ |
205 |
FD_CLR (unix_sock, &read_set); |
208 |
FD_CLR (unix_sock, &read_set); |
206 |
if ((s = accept(unix_sock, (struct sockaddr *) &from, &len)) < 0) { |
209 |
if ((s = accept(unix_sock, &from.a, &len)) < 0) { |
207 |
warn("Socket not accepted: %s", strerror(errno)); |
210 |
warn("Socket not accepted: %s", strerror(errno)); |
208 |
goto skip_accept; |
211 |
goto skip_accept; |
209 |
} |
212 |
} |
Lines 313-323
cleanup:
Link Here
|
313 |
/*** open_inetsock ************************************************************/ |
316 |
/*** open_inetsock ************************************************************/ |
314 |
int open_inetsock(struct in_addr inetaddr) |
317 |
int open_inetsock(struct in_addr inetaddr) |
315 |
{ |
318 |
{ |
316 |
struct sockaddr_in dest, src; |
319 |
union { |
|
|
320 |
struct sockaddr a; |
321 |
struct sockaddr_in i; |
322 |
} dest, src; |
317 |
int s; |
323 |
int s; |
318 |
dest.sin_family = AF_INET; |
324 |
dest.i.sin_family = AF_INET; |
319 |
dest.sin_port = htons(PPTP_PORT); |
325 |
dest.i.sin_port = htons(PPTP_PORT); |
320 |
dest.sin_addr = inetaddr; |
326 |
dest.i.sin_addr = inetaddr; |
321 |
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
327 |
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
322 |
warn("socket: %s", strerror(errno)); |
328 |
warn("socket: %s", strerror(errno)); |
323 |
return s; |
329 |
return s; |
Lines 332-345
int open_inetsock(struct in_addr inetadd
Link Here
|
332 |
#endif |
338 |
#endif |
333 |
if (localbind.s_addr != INADDR_NONE) { |
339 |
if (localbind.s_addr != INADDR_NONE) { |
334 |
bzero(&src, sizeof(src)); |
340 |
bzero(&src, sizeof(src)); |
335 |
src.sin_family = AF_INET; |
341 |
src.i.sin_family = AF_INET; |
336 |
src.sin_addr = localbind; |
342 |
src.i.sin_addr = localbind; |
337 |
if (bind(s, (struct sockaddr *) &src, sizeof(src)) != 0) { |
343 |
if (bind(s, &src.a, sizeof(src.i)) != 0) { |
338 |
warn("bind: %s", strerror(errno)); |
344 |
warn("bind: %s", strerror(errno)); |
339 |
close(s); return -1; |
345 |
close(s); return -1; |
340 |
} |
346 |
} |
341 |
} |
347 |
} |
342 |
if (connect(s, (struct sockaddr *) &dest, sizeof(dest)) < 0) { |
348 |
if (connect(s, &dest.a, sizeof(dest.i)) < 0) { |
343 |
warn("connect: %s", strerror(errno)); |
349 |
warn("connect: %s", strerror(errno)); |
344 |
close(s); return -1; |
350 |
close(s); return -1; |
345 |
} |
351 |
} |
Lines 349-355
int open_inetsock(struct in_addr inetadd
Link Here
|
349 |
/*** open_unixsock ************************************************************/ |
355 |
/*** open_unixsock ************************************************************/ |
350 |
int open_unixsock(struct in_addr inetaddr) |
356 |
int open_unixsock(struct in_addr inetaddr) |
351 |
{ |
357 |
{ |
352 |
struct sockaddr_un where; |
358 |
union { |
|
|
359 |
struct sockaddr a; |
360 |
struct sockaddr_un u; |
361 |
} where; |
353 |
struct stat st; |
362 |
struct stat st; |
354 |
char *dir; |
363 |
char *dir; |
355 |
int s; |
364 |
int s; |
Lines 357-377
int open_unixsock(struct in_addr inetadd
Link Here
|
357 |
warn("socket: %s", strerror(errno)); |
366 |
warn("socket: %s", strerror(errno)); |
358 |
return s; |
367 |
return s; |
359 |
} |
368 |
} |
360 |
callmgr_name_unixsock( &where, inetaddr, localbind); |
369 |
callmgr_name_unixsock( &where.u, inetaddr, localbind); |
361 |
if (stat(where.sun_path, &st) >= 0) { |
370 |
if (stat(where.u.sun_path, &st) >= 0) { |
362 |
warn("Call manager for %s is already running.", inet_ntoa(inetaddr)); |
371 |
warn("Call manager for %s is already running.", inet_ntoa(inetaddr)); |
363 |
close(s); return -1; |
372 |
close(s); return -1; |
364 |
} |
373 |
} |
365 |
/* Make sure path is valid. */ |
374 |
/* Make sure path is valid. */ |
366 |
dir = dirname(where.sun_path); |
375 |
dir = dirname(where.u.sun_path); |
367 |
if (!make_valid_path(dir, 0770)) |
376 |
if (!make_valid_path(dir, 0770)) |
368 |
fatal("Could not make path to %s: %s", where.sun_path, strerror(errno)); |
377 |
fatal("Could not make path to %s: %s", where.u.sun_path, strerror(errno)); |
369 |
free(dir); |
378 |
free(dir); |
370 |
if (bind(s, (struct sockaddr *) &where, sizeof(where)) < 0) { |
379 |
if (bind(s, &where.a, sizeof(where.u)) < 0) { |
371 |
warn("bind: %s", strerror(errno)); |
380 |
warn("bind: %s", strerror(errno)); |
372 |
close(s); return -1; |
381 |
close(s); return -1; |
373 |
} |
382 |
} |
374 |
chmod(where.sun_path, 0777); |
383 |
chmod(where.u.sun_path, 0777); |
375 |
listen(s, 127); |
384 |
listen(s, 127); |
376 |
return s; |
385 |
return s; |
377 |
} |
386 |
} |