diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-06 17:43:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-06 17:43:29 +0200 |
commit | f6916dbed4233ef0e202d1b299cb5a2e9287a696 (patch) | |
tree | a761598c5f3d6e935239d8631e7f984c4cd490d6 /libbb | |
parent | fcad7681f8a835f5c7b2093da505f46865a89d25 (diff) | |
download | busybox-f6916dbed4233ef0e202d1b299cb5a2e9287a696.tar.gz |
telnetd: fill hostname field in utmp/wtmp records
function old new delta
get_lsa - 109 +109
make_new_session 438 504 +66
get_peer_lsa - 10 +10
ftpd_main 2340 2267 -73
get_sock_lsa 101 10 -91
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/2 up/down: 185/-164) Total: 21 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index d8c8d02d5..c3ee633e4 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -47,25 +47,35 @@ int FAST_FUNC setsockopt_bindtodevice(int fd UNUSED_PARAM, } #endif -len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd) +static len_and_sockaddr* get_lsa(int fd, int (*get_name)(int fd, struct sockaddr *addr, socklen_t *addrlen)) { len_and_sockaddr lsa; len_and_sockaddr *lsa_ptr; lsa.len = LSA_SIZEOF_SA; - if (getsockname(fd, &lsa.u.sa, &lsa.len) != 0) + if (get_name(fd, &lsa.u.sa, &lsa.len) != 0) return NULL; lsa_ptr = xzalloc(LSA_LEN_SIZE + lsa.len); if (lsa.len > LSA_SIZEOF_SA) { /* rarely (if ever) happens */ lsa_ptr->len = lsa.len; - getsockname(fd, &lsa_ptr->u.sa, &lsa_ptr->len); + get_name(fd, &lsa_ptr->u.sa, &lsa_ptr->len); } else { memcpy(lsa_ptr, &lsa, LSA_LEN_SIZE + lsa.len); } return lsa_ptr; } +len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd) +{ + return get_lsa(fd, getsockname); +} + +len_and_sockaddr* FAST_FUNC get_peer_lsa(int fd) +{ + return get_lsa(fd, getpeername); +} + void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) { if (connect(s, s_addr, addrlen) < 0) { |