| | |
Display IP Address from /var/log/wtmp
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
How would I display an IP address from /var/log/wtmp? I know I could use utmpdump, but that's not what I'm going for. I have included bits/utmp.h and can display other members of the struct, but when i try to display the ut_addr_v6 member, I get a random hex address instead. Any thoughts?
CPP Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::endl; using std::cerr; using std::ios; using std::left; #include <utmp.h> #include <iomanip> using std::setw; #include <cstdlib> using std::exit; #include <fstream> using std::ifstream; using std::ostream; void outputLine(ostream&, const struct utmp); int main() { //open log file ifstream logfile("wtmp", ios::in | ios::out | ios::binary); if (!logfile) { cerr << "File Could Not Be Opened" << endl; exit(1); } struct utmp log; logfile.read(reinterpret_cast<char *>(&log), sizeof(struct utmp)); while (logfile && !logfile.eof()) { if (log.ut_type != 0) outputLine(cout, log); logfile.read(reinterpret_cast<char *>(&log), sizeof(struct utmp)); } return 0; } void outputLine(ostream &output, const struct utmp record) { output << "USER: " << setw(15) << left << record.ut_user << "HOST: " << setw(25) << record.ut_host << "IP: " << setw(15) << record.ut_addr_v6 << endl; }
Last edited by TheFueley; Mar 26th, 2008 at 11:53 pm.
Rivera
![]() |
Similar Threads
- samba 3.0.22 on solaris 9 (Getting Started and Choosing a Distro)
Other Threads in the C++ Forum
- Previous Thread: Writing a program with an array that averages 10 numbers
- Next Thread: Blur Function for Program
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





