diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-07-10 12:55:10 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-07-18 22:57:36 +0400 |
commit | 004db9a22bf2b860cc36f4a1c24d559136b11c82 (patch) | |
tree | 01de763cadc1d8375c2ade47617ac8166bd1746b | |
parent | 36070c83907db169f2e6cd443b216dbbea2e7637 (diff) | |
download | accel-ppp-xebd-004db9a22bf2b860cc36f4a1c24d559136b11c82.tar.gz accel-ppp-xebd-004db9a22bf2b860cc36f4a1c24d559136b11c82.zip |
l2tp: use asprintf() to set sessions channel names
Now that memdebug implements asprintf() we can simplify session's
channel name allocation by replacing the two snprintf() calls.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index d81516e..29ba76c 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -1157,7 +1157,6 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess) struct l2tp_conn_t *conn = sess->paren_conn; int lns_mode = sess->lns_mode; int flg; - int chan_sz; uint16_t peer_port; char addr[17]; @@ -1209,23 +1208,10 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess) u_inet_ntoa(conn->peer_addr.sin_addr.s_addr, addr); peer_port = ntohs(conn->peer_addr.sin_port); - chan_sz = snprintf(NULL, 0, "%s:%i session %i", - addr, peer_port, sess->peer_sid); - if (chan_sz < 0) { + if (_asprintf(&sess->ppp.ses.chan_name, "%s:%i session %i", + addr, peer_port, sess->peer_sid) < 0) { log_session(log_error, sess, "impossible to connect session:" - " snprintf() failed: %s\n", strerror(errno)); - goto out_err; - } - sess->ppp.ses.chan_name = _malloc(chan_sz + 1); - if (sess->ppp.ses.chan_name == NULL) { - log_session(log_error, sess, "impossible to connect session:" - " memory allocation failed\n"); - goto out_err; - } - if (snprintf(sess->ppp.ses.chan_name, chan_sz + 1, "%s:%i session %i", - addr, peer_port, sess->peer_sid) < 0) { - log_session(log_error, sess, "impossible to connect session:" - " snprintf(%i) failed\n", chan_sz + 1); + " setting session's channel name failed\n"); goto out_err; } |