Hi all,

here is a little c++ program which u can use to determine your utmp/wtmp 
format to use it correctly with hostsentry. It works fine for me and maybe it 
can be added to future releases of hostsentry cause it may be usefull for 
some ppl. :-)

I have attached an C++ and C Version!

Kind regards,
        Marc
// to compile: "gcc -o showwtmp showwtmp.c"
#include <stdio.h>
#include <utmp.h>

main() {
  int
  	s_utmp,
	s_ut_type,
	s_pid_t,
	o_tty_name,
	s_tty_name,
	o_username,
	s_username,
	o_hostname,
	s_hostname;
  s_utmp    = sizeof(struct utmp);
  s_ut_type = sizeof(short);
  s_pid_t   = sizeof(pid_t);
  o_tty_name = s_pid_t + s_ut_type;
  s_tty_name = UT_LINESIZE;
  o_username = o_tty_name + s_tty_name + 4; //4=sizeof(abbrev. ttyname)
  s_username = UT_NAMESIZE;
  o_hostname = o_username + s_username;
  s_hostname = UT_HOSTSIZE;
  printf("size of utmp struct: %d\n", s_utmp);
  printf("size of ut_type:     %d\n", s_ut_type);
  printf("size of pid_t:       %d\n", s_pid_t);
  printf("offset of tty name:  %d\n", o_tty_name);
  printf("size of tty name:    %d\n", s_tty_name);
  printf("offset of username:  %d\n", o_username);
  printf("size of username:    %d\n", s_username);
  printf("offset of hostname:  %d\n", o_hostname);
  printf("size of hostname:    %d\n", s_hostname);
  printf("\nformat:\n");
  printf("\"%d/%d:%d/%d:%d/%d:%d\"\n", s_utmp, o_tty_name, s_tty_name, o_username, s_username, o_hostname, s_hostname);
  return 0;
}
// to compile: "g++ -o showwtmp showwtmp.cpp"
#include <stdio.h>
#include <utmp.h>

int main(int argc, char **argv) {
  int
  	s_utmp    = sizeof(struct utmp),
	s_ut_type = sizeof(short),
	s_pid_t   = sizeof(pid_t),
	o_tty_name = s_pid_t + s_ut_type,
	s_tty_name = UT_LINESIZE,
	o_username = o_tty_name + s_tty_name + 4, //4=sizeof(abbrev. ttyname)
	s_username = UT_NAMESIZE,
	o_hostname = o_username + s_username,
	s_hostname = UT_HOSTSIZE;
  printf("size of utmp struct: %d\n", s_utmp);
  printf("size of ut_type:     %d\n", s_ut_type);
  printf("size of pid_t:       %d\n", s_pid_t);
  printf("offset of tty name:  %d\n", o_tty_name);
  printf("size of tty name:    %d\n", s_tty_name);
  printf("offset of username:  %d\n", o_username);
  printf("size of username:    %d\n", s_username);
  printf("offset of hostname:  %d\n", o_hostname);
  printf("size of hostname:    %d\n", s_hostname);
  printf("\nformat:\n");
  printf("\"%d/%d:%d/%d:%d/%d:%d\"\n", s_utmp, o_tty_name, s_tty_name, o_username, s_username, o_hostname, s_hostname);
  return 0;
}

Reply via email to