summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl/l2tp/l2tp.c
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2012-07-12 15:22:07 +0200
committerKozlov Dmitry <xeb@mail.ru>2012-07-13 10:20:27 +0400
commit0b99fef73bce3f1abed63e581594de9d1f132312 (patch)
tree13c2d3cd7aac06d61cb64ae75699b1bae65e69a0 /accel-pppd/ctrl/l2tp/l2tp.c
parent130e1d534f0520d7be3e8812a602c189e3db058d (diff)
downloadaccel-ppp-0b99fef73bce3f1abed63e581594de9d1f132312.tar.gz
accel-ppp-0b99fef73bce3f1abed63e581594de9d1f132312.zip
L2TP: Fix socket() error handling in l2tp_connect()
Check if the tunnel file descriptor has been successfully created. Explicitely check for negative values to detect socket() errors. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/ctrl/l2tp/l2tp.c')
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index d8a98f8..5bba25e 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -384,7 +384,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
pppox_addr.pppol2tp.d_tunnel = conn->peer_tid;
conn->tunnel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
- if (!conn->ppp.fd) {
+ if (conn->tunnel_fd < 0) {
log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno));
return -1;
}
@@ -392,13 +392,13 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
fcntl(conn->tunnel_fd, F_SETFD, fcntl(conn->tunnel_fd, F_GETFD) | FD_CLOEXEC);
conn->ppp.fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
- if (!conn->ppp.fd) {
+ if (conn->ppp.fd < 0) {
close(conn->tunnel_fd);
conn->tunnel_fd = -1;
log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno));
return -1;
}
-
+
fcntl(conn->ppp.fd, F_SETFD, fcntl(conn->ppp.fd, F_GETFD) | FD_CLOEXEC);
if (connect(conn->tunnel_fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {