473,473 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to read the unix wtmpx.dat File to show the reult on the textBox from unix wtmpx.dat file?

Hello.
this is beginner programmer.
If u have more time, would you check this code.?
please give me the answer how to slove this problem...?

÷ºÎ ÆÄÀÏ ==> wtmpx.dat ·Î±× ÆÄÀÏ
************************************************** **************************
if( this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
string line = null;

FileStream inStream = new FileStream(this.openFileDialog1.FileName,
FileMode.Open);
StreamReader sr = new StreamReader(inStream, Encoding.Default);

int nCols = 16;

long nBytesToRead = inStream.Length;
if( nBytesToRead > 65536/4)
nBytesToRead = 65536/4;
int nLines = (int)(nBytesToRead/nCols) + 1;
string [] Lines = new string[nLines];
int nBytesRead=0;
for( int i=0; i<nLines ; i++)
{
StringBuilder NextLine = new StringBuilder();
NextLine.Capacity = 2*nCols;
for( int j=0; j< nCols; j++)
{
int NextByte = inStream.ReadByte();
nBytesRead++;
if(NextByte < 0 || nBytesRead > 65536)
break;
char NextChar = (char)NextByte;
if(NextChar < 16)
//NextLine.Append(string.Format("{0,1:x}", (int)NextChar));
NextLine.Append(string.Format("{0,1:x}", (int)NextChar));
else if(char.IsLetterOrDigit(NextChar) || char.IsPunctuation(NextChar))
NextLine.Append(" " + NextChar + " ");
else
//NextLine.Append(string.Format("{0,2:x}", (int)NextChar));
NextLine.Append(string.Format("{0,2:x}", (int)NextChar));
}
Lines[i] = NextLine.ToString();
}

inStream.Close();
this.richTextBox1.Lines = Lines;
}

}

************************************************** **************************
*******
À¯´Ð½º c¿¡¼* wtmpx.datÆÄÀÏÀ» ÀоîµéÀÌ´Â ¼Ò½º
************************************************** **************************
*******
#include <stdio.h>
#include <utmpx.h>
#include <errno.h>
#include <time.h>

main(int argc,char *argv[])
{
FILE *fp;
struct utmpx buffer;
int count = 0;
char yn;
struct tm *wtm;
char title[1024];

if(argc != 2){
printf("Usage : %s wtmpx\n",argv[0]);
exit(-1);
}

if((fp = fopen(argv[1],"r")) == NULL){
printf("FILE OPEN FAIL errno[%d]\n",errno);
exit(-1);
}
memset(title,0x00,sizeof(title));
sprintf(title,"%10s %32s %4s %32s %4s %4s %4s %4s %32s %257s\n",
"COUNT","USER","ID","DEVICE NAME","PID",
"TYPE","TERM","EXIT","TIME","HOST");
memset(&buffer,0x00,sizeof(buffer));
printf("%s",title);

printf("========================================== ================\n");
while(fread(&buffer,sizeof(buffer),1,fp) != 0){
count++;
printf("%10d ",count);
printf("%32s ",buffer.ut_user);
printf("%4s ",buffer.ut_id);
printf("%32s ",buffer.ut_line);
printf("%4d ",buffer.ut_pid);
printf("%4d ",buffer.ut_type);
printf("%4d ",buffer.ut_exit.e_termination);
printf("%4d ",buffer.ut_exit.e_exit);
printf("%32s ",ctime((const time_t *)&buffer.ut_tv));
printf("%257s ",buffer.ut_host);
printf("\n");
if(!(count%10)){

printf("========================================== =====;
printf("continue([y]/n)?");
yn=getchar();
if(yn == 'N' || yn == 'n'){
break;
}
printf("%s",title);
}
memset(&buffer,0x00,sizeof(buffer));
}
printf("END\n");
}
************************************************** **************************
************
utmp ±¸Á¶
************************************************** **************************
************
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */

/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */

/*
* Copyright (c) 1996-1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
#ifndef _UTMP_H
#define _UTMP_H

#pragma ident "@(#)utmp.h 1.17 97/08/23 SMI" /* SVr4.0 1.5.1.7 */

/*
* Note: The getutent(3c) family of interfaces are obsolete.
* The getutxent(3c) family provide a superset of this functionality
* and should be used in place of getutent(3c).
*/

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#define UTMP_FILE "/var/adm/utmp"
#define WTMP_FILE "/var/adm/wtmp"
#endif

#define ut_name ut_user

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
struct exit_status {
short e_termination; /* Process termination status */
short e_exit; /* Process exit status */
};
#else
struct ut_exit_status {
short ut_e_termination; /* Process termination status */
short ut_e_exit; /* Process exit status */
};
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)

/*
* This data structure describes the utmp entries returned by
* the getutent(3c) family of APIs. It does not (necessarily)
* correspond to the contents of the utmp or wtmp files.
*
* Applications should only interact with this subsystem via
* the getutxent(3c) family of APIs, as the getutent(3c) family
* are obsolete.
*/
struct utmp {
char ut_user[8]; /* User login name */
char ut_id[4]; /* /etc/inittab id(usually line #)
*/
char ut_line[12]; /* device name (console, lnxx) */
short ut_pid; /* short for compat. - process id */
short ut_type; /* type of entry */
struct exit_status ut_exit; /* The exit status of a process */
/* marked as DEAD_PROCESS. */
time_t ut_time; /* time entry was made */
};

#include <sys/types32.h>
#include <inttypes.h>

/*
* This data structure describes the utmp *file* contents using
* fixed-width data types. It should only be used by the implementation.
*
* Applications should use the getutxent(3c) family of routines to interact
* with this database.
*/

struct futmp {
char ut_user[8]; /* User login name */
char ut_id[4]; /* /etc/inittab id */
char ut_line[12]; /* device name (console, lnxx) */
int16_t ut_pid; /* process id */
int16_t ut_type; /* type of entry */
struct {
int16_t e_termination; /* Process termination status */
int16_t e_exit; /* Process exit status */
} ut_exit; /* The exit status of a process */
time32_t ut_time; /* time entry was made */
};

#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

/* Definitions for ut_type */

#define EMPTY 0
#define RUN_LVL 1
#define BOOT_TIME 2
#define OLD_TIME 3
#define NEW_TIME 4
#define INIT_PROCESS 5 /* Process spawned by "init" */
#define LOGIN_PROCESS 6 /* A "getty" process waiting for login */
#define USER_PROCESS 7 /* A user process */
#define DEAD_PROCESS 8

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)

#define ACCOUNTING 9

#define UTMAXTYPE ACCOUNTING /* Largest legal value of ut_type */

/* Special strings or formats used in the "ut_line" field when */
/* accounting for something other than a process. */
/* No string for the ut_line field can be more than 11 chars + */
/* a NULL in length. */

#define RUNLVL_MSG "run-level %c"
#define BOOT_MSG "system boot"
#define OTIME_MSG "old time"
#define NTIME_MSG "new time"
#define PSRADM_MSG "%03d %s" /* processor on or off */

/* Define and macro for determing if a normal user wrote the entry */
À¯´Ð½º ·Î±× ÆÄÀÏ wtmpx.dat ÀÌÁø ÆÄÀÏÀ» ¿øÆû ÅؽºÆ® ¹Ú½º·Î ³ªÅ¸³»·Á°í ÇÕ´Ï´Ù.
************************************************** **************************
***
/* and marking the utmpx entry as a normal user */
#define NONROOT_USR 2
#define nonuser(ut) ((ut).ut_exit.e_exit == NONROOT_USR ? 1 : 0)
#define setuser(ut) ((ut).ut_exit.e_exit = NONROOT_USR)
#if defined(__STDC__)
extern void endutent(void);
extern struct utmp *getutent(void);
extern struct utmp *getutid(const struct utmp *);
extern struct utmp *getutline(const struct utmp *);
extern struct utmp *pututline(const struct utmp *);
extern void setutent(void);
extern int utmpname(const char *);
#else
extern void endutent();
extern struct utmp *getutent();
extern struct utmp *getutid();
extern struct utmp *getutline();
extern struct utmp *pututline();
extern void setutent();
extern int utmpname();
#endif

#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

#ifdef __cplusplus
}
#endif

#endif /* _UTMP_H */

Nov 15 '05 #1
0 3708

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lpe540 | last post by:
Hi, I'm having trouble using istream to read in a file in its entirety on UNIX. I've written a dummy program that essencially reads in a file from stdin and writes it out to a file. When I cat a...
0
by: sangui | last post by:
Helllo. this is biginner programmer. Would u check the file that I programed on c#(winform)? I tryed to make the program reading the binary file by C# programming but I failed. If u have...
16
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
2
by: Stan Sainte-Rose | last post by:
Hi, I need to read a kind of text file from vb.net I do know how to read a simple file, but this one seems to have special characters. Some characters appears like squares when open this file...
6
by: dylan.boudreau | last post by:
My configuration is Apache/2.0.59 (Unix) mod_ssl/2.0.59 OpenSSL/0.9.7d PHP/5.0.4 on Solaris 10. phpinfo() lists the location of php.ini as /usr/local/apache/conf and my php.ini file is there but...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
23
by: asit dhal | last post by:
hello friends, can anyone explain me how to use read() write() function in C. and also how to read a file from disk and show it on the monitor using onlu read(), write() function ??????
1
by: Tony | last post by:
Hi all, I found the /var/adm/wtmpx file growing very fast because there are huge "db2fmcdfmcSFèê" strings repeating in the file. My environment is DB2 v8(FP14) + Solaris v9. Is that the DB2...
16
by: mazwolfe | last post by:
Someone recently asked about reading lines. I had this code written some time ago (part of a BASIC-style interpreter based on H. Shildts in Art of C) to read a file with the lines ended in any...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.