projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Convert sizeof foo to sizeof(foo).
[tinc]
/
src
/
uml_device.c
diff --git
a/src/uml_device.c
b/src/uml_device.c
index
26bcb01
..
5dcf8aa
100644
(file)
--- a/
src/uml_device.c
+++ b/
src/uml_device.c
@@
-1,7
+1,7
@@
/*
device.c -- UML network socket
Copyright (C) 2002-2005 Ivo Timmermans,
/*
device.c -- UML network socket
Copyright (C) 2002-2005 Ivo Timmermans,
- 2002-201
1
Guus Sliepen <guus@tinc-vpn.org>
+ 2002-201
2
Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-77,7
+77,11
@@
static bool setup_device(void) {
return false;
}
return false;
}
- setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+#ifdef FD_CLOEXEC
+ fcntl(write_fd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
@@
-91,7
+95,11
@@
static bool setup_device(void) {
return false;
}
return false;
}
- setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+#ifdef FD_CLOEXEC
+ fcntl(data_fd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
@@
-104,9
+112,9
@@
static bool setup_device(void) {
gettimeofday(&tv, NULL);
name.usecs = tv.tv_usec;
data_sun.sun_family = AF_UNIX;
gettimeofday(&tv, NULL);
name.usecs = tv.tv_usec;
data_sun.sun_family = AF_UNIX;
- memcpy(&data_sun.sun_path, &name, sizeof
name
);
+ memcpy(&data_sun.sun_path, &name, sizeof
(name)
);
- if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof
data_sun
) < 0) {
+ if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof
(data_sun)
) < 0) {
logger(LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
running = false;
return false;
logger(LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
running = false;
return false;
@@
-118,7
+126,11
@@
static bool setup_device(void) {
return false;
}
return false;
}
- setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+#ifdef FD_CLOEXEC
+ fcntl(device_fd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
@@
-126,8
+138,8
@@
static bool setup_device(void) {
}
listen_sun.sun_family = AF_UNIX;
}
listen_sun.sun_family = AF_UNIX;
- strncpy(listen_sun.sun_path, device, sizeof
listen_sun.sun_path
);
- if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof
listen_sun
) < 0) {
+ strncpy(listen_sun.sun_path, device, sizeof
(listen_sun.sun_path)
);
+ if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof
(listen_sun)
) < 0) {
logger(LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno));
return false;
}
logger(LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno));
return false;
}
@@
-173,7
+185,7
@@
static bool read_packet(vpn_packet_t *packet) {
switch(state) {
case 0: {
struct sockaddr sa;
switch(state) {
case 0: {
struct sockaddr sa;
- socklen_t salen = sizeof
sa
;
+ socklen_t salen = sizeof
(sa)
;
request_fd = accept(listen_fd, &sa, &salen);
if(request_fd < 0) {
request_fd = accept(listen_fd, &sa, &salen);
if(request_fd < 0) {
@@
-181,6
+193,10
@@
static bool read_packet(vpn_packet_t *packet) {
return false;
}
return false;
}
+#ifdef FD_CLOEXEC
+ fcntl(request_fd, F_SETFD, FD_CLOEXEC);
+#endif
+
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
running = false;
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
running = false;
@@
-196,7
+212,7
@@
static bool read_packet(vpn_packet_t *packet) {
}
case 1: {
}
case 1: {
- if((lenin = read(request_fd, &request, sizeof
request
)) != sizeof request) {
+ if((lenin = read(request_fd, &request, sizeof
(request)
)) != sizeof request) {
logger(LOG_ERR, "Error while reading request from %s %s: %s", device_info,
device, strerror(errno));
running = false;
logger(LOG_ERR, "Error while reading request from %s %s: %s", device_info,
device, strerror(errno));
running = false;
@@
-210,13
+226,13
@@
static bool read_packet(vpn_packet_t *packet) {
return false;
}
return false;
}
- if(connect(write_fd, &request.sock, sizeof
request.sock
) < 0) {
+ if(connect(write_fd, &request.sock, sizeof
(request.sock)
) < 0) {
logger(LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno));
running = false;
return false;
}
logger(LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno));
running = false;
return false;
}
- write(request_fd, &data_sun, sizeof
data_sun
);
+ write(request_fd, &data_sun, sizeof
(data_sun)
);
device_fd = data_fd;
logger(LOG_INFO, "Connection with UML established");
device_fd = data_fd;
logger(LOG_INFO, "Connection with UML established");
@@
-244,7
+260,7
@@
static bool read_packet(vpn_packet_t *packet) {
}
default:
}
default:
- logger(LOG_ERR, "Invalid value for state variable in "
__FILE__
);
+ logger(LOG_ERR, "Invalid value for state variable in "
FILE
);
abort();
}
}
abort();
}
}