if your $PATH includes “.” you need to edit /etc/sysconfig/suseconfig and set
CWD_IN_USER_PATH=”no”
CWD_IN_ROOT_PATH=”no”
20/433
Uncategorized
socktest
Have you ever wanted to test a connection to only one port, and found nmap overkill, and you like to do it in C?
Normally I’d recommend something like
echo “~.” | telnet -r $H $X 2>&1| grep -i connected | wc -l | sed ‘s/ //g’`
But, if the host doesn’t answer the default tcp/ip timeout for a socket is 3 minutes!!!! You have to wait long
time…
You don’t want to wait too long for that, so you can use a program to test a socket connection, like socktest.c,
it tries to connect and if it can’t within 5 seconds it will bail out.
you should compile with gcc, if using solaris “gcc -o socktest -lsocket -lnsl socktest.c” will suffice.
So, for instance you want to test port 80 and port 44 in google.com:
bash-3.00$ ./socktest google.com 80 ; echo $?
Connection to port successful
bash-3.00$ ./socktest google.com 44 ; echo $?
ERROR: Timeout or error() 4 – Interrupted system call
1
You can get the exit code 0 as successful, 1 as not successful.
Source here:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <sys/fcntl.h>
//—————————————–
// Roberto Dircio Palacios-Macedo
// socktest – program to test a connection
// to a host in a specific port
// usage – ./socktest <host> <port>
//—————————————–
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
80/433
{
int res,valopt;
struct timeval tv;
fd_set myset;
socklen_t lon;
int soc, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc < 3) {
fprintf(stderr,”usage %s hostname portn”, argv[0]);
exit(1);
}
portno = atoi(argv[2]);
server = gethostbyname(argv[1]);
soc = socket(AF_INET, SOCK_STREAM, 0);
if (soc < 0) {
error(“ERROR: opening socket”);
exit(1);
}
if (server == NULL) {
fprintf(stderr,”ERROR: no such hostn”);
exit(1);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
long arg = fcntl(soc, F_GETFL, NULL);
arg |= O_NONBLOCK;
fcntl(soc, F_SETFL, arg);
res=connect(soc, &serv_addr,sizeof(serv_addr));
if (res < 0) {
if (errno == EINPROGRESS) {
tv.tv_sec = 5;
tv.tv_usec = 0;
FD_ZERO(&myset);
FD_SET(soc, &myset);
if (select(soc+1, NULL, &myset, NULL, &tv) > 0) {
lon = sizeof(int);
getsockopt(soc, SOL_SOCKET, SO_ERROR, (void*)(&valopt) , &lon);
if (valopt) {
fprintf(stderr, “ERROR: Error in connection() %d – %sn”, valopt, strerror(valopt) );
exit(1);
}
}
else {
fprintf(stderr, “ERROR: Timeout or error() %d – %sn”, valopt, strerror(valopt) );
exit(1);
}
}
81/433
else {
fprintf(stderr, “ERROR: Error connecting %d – %sn”, errno, strerror(errno)) ;
exit(1);
}
}
arg = fcntl(soc, F_GETFL, NULL);
arg &= (~O_NONBLOCK) ;
fcntl(soc, F_SETFL, arg);
fprintf(stdout, “Connection to port successfuln”);
exit(0);
}
Enjoy!
82/433
Multiseat xorg+gdm on slackware 13 x86_64
One computer, two people using it, that means
– 2 video cards, one in the motherboard, and another in PCI-E
– 2 monitors, 2 keyboards, 2 mouses
lspci says:
root@kraftek:~# lspci | grep -i vga
02:00.0 VGA compatible controller: nVidia Corporation C77 [GeForce 8200] (rev a2)
03:00.0 VGA compatible controller: nVidia Corporation G98 [GeForce 8400 GS] (rev a1)
Make sure you select the pci-e as the first card to be initialised in the bios
To find out which mouse and keyboard is which, for each /dev/input/mouse1 /dev/input/mouse2 and /dev/input/event0 /dev/input/event1 /dev/input/event10 /dev/input/event11 /dev/input/event12 /dev/input/event13 /dev/input/event2 /dev/input/event3 /dev/input/event5 /dev/input/event7 /dev/input/event8 /dev/input/event9 do a:
# cat /dev/input/mouse X
# cat /dev/input/eventX
and move the mouse or type in the keyboard, if you see characters in the terminal, that is your kb or mouse.
Also make sure you enable this on the ServerFlags section in xorg.conf so that xorg honors the devices you
select in xorg.conf
Option “AutoAddDevices” “false”
/etc/X11/xorg.conf
30/433
/etc/X11/gdm/custom.conf
The gdm custom.conf is necessary so you have 2 login screens, one on each screen, the important part is:
[servers]
0=Standard device=/dev/console
1=Standard1
[server-Standard]
name=Standard server
command=/usr/X11R6/bin/X -nolisten tcp -novtswitch -sharevts -layout seat1
flexible=true
[server-Standard 1]
name=Standard server
command=/usr/X11R6/bin/X -nolisten tcp -novtswitch -sharevts -layout seat2
flexible=true
enjoy!
31/433
soft partition create, grow, delete on SVM (Sun Volume Manager/Solstice Disksuite)
You have a parition d50 comprising slice 0 of a disk:
d50 1 1 c7t60060E80042AEE0000002AEE00000019d0s0
now you want to create soft partitions in it, you can create a 5gb soft partition just by:
# metainit d55 -p d50 5gb
# newfs /dev/md/dsk/d55
You can destroy it by unmounting it, and clearing it
# metaclear d55
You can grow this partition
# metattach d55 1gb
# growfs -M /mount/point /dev/md/rdsk/d55
261/433
Adding udev rules
I inspected all the devices i wanted to add to udev using “udevadm info” for each path i knew was the device i needed.
udevadm info -a -p $(udevadm info -q path -n /dev/video1)
udevadm info -a -p $(udevadm info -q path -n /dev/video0)
udevadm info -a -p $(udevadm info -q path -n /dev/input/mouse1)
udevadm info -a -p $(udevadm info -q path -n /dev/input/event1)
udevadm info -a -p $(udevadm info -q path -n /dev/input/event2)
udevadm info -a -p $(udevadm info -q path -n /dev/input/mouse2)
Then just created the udev file /etc/udev/rules. d/95-my.rules
KERNEL==”video*”, SUBSYSTEM==”video4linux”, ATTR{name}==”saa7133*”, SYMLINK+=”tvcard”
SUBSYSTEM==”video4linux”, ATTR{name}==”gspca main driver”, SYMLINK+=”geniuscam”
KERNEL==”mouse*”, ATTRS{name}==”Microsoft Basic Optical Mouse”, SYMLINK+=”input/cecimouse”
KERNEL==”event*”, ATTRS{name}==”AT Translated Set 2 keyboard”, SYMLINK+=”input/cecikb”
KERNEL==”event*”, ATTRS{name}==”Logitech Logitech USB Keyboard”, SYMLINK+=”input/betokb”
KERNEL==”mouse*”, ATTRS{name}==”USB Optical Mouse”, SYMLINK+=”input/betomouse”
reboot, and i get pretty aliases for all my devs 🙂
Disable password aging for a particular account using “chage”
If you want a user’s password to never expire use:
# chage -I -1 -m 0 -M 99999 -E -1 theuser
If you just want to check the user’s password expiry then
# chage -l theuser
# passwd -Sa | grep -i theuser
build an iso image
if you want to make a cdrom image of a file, you can just run:
mkisofs -o the_iso.iso -R -v the_file.tar.gz
92/433
find files that have grown in the latest 5 days, and print them sorted by size
# find . -mount -mtime -5 -exec du -sk {} ; | sort -n
93/433
Building gnophone
Problems building gnophone… solved using this:
http://forums.gentoo.org/viewtopic-t-118309-highlight-gnophone.html?sid=88ab1b0aa8bc97b17c3290be 0ed95817
i quote:
Odd that this problem should be the same now as it was when those other posts were made, but in case anyone else is
having this problem, here is how to make it compile:
there are two files with multi-line strings in them. GCC doesn’t seem to allow this… perhaps other versions do? I dunno.
Here is a diff of the file that ships with it, and the file fixed: (sounds/raw2h.c)
Code:
31c31,44
Signed 16-bit audio datan n
Source: %sn
n
Copyright (C) 1999, Mark Spencer and Linux Support Servicesn
n
Distributed under the terms of the GNU General Public Licensen
n
/nnnstatic signed short %s[] = {n”,
argv[1], n);
—
> fprintf(o,
> “/
>
Signed 16-bit audio data
>
>
Source: %s
>
>
Copyright (C) 1999, Mark Spencer and Linux Support Services
>
>
Distributed under the terms of the GNU General Public License
>
>
/
>
> static signed short %s[] = {
> “, argv[1], n);
(sounds/mkdtmf.c)
Code:
28c28,40
n Signed 16-bit audio data representing ‘%s’ in dtmfn
n
Copyright (C) 2000, Linux Support Services, Inc.n
n
Distributed under the terms of the GNU Generaln
Public Licensen
n
/nnstatic short %s[] = { n”, argv[1],
argv[2]);
—
> printf(
> “/
>
Signed 16-bit audio data representing ‘%s’ in dtmf
280/433
>
>
Copyright (C) 2000, Linux Support Services, Inc.
>
>
Distributed under the terms of the GNU General
>
Public License
>
> POSTS/
>
> static short %s[] = {
> “, argv[1], argv[2]);
then in src/gnophone_gui.c, below the line 1399, you need to add a line that says “break;” after the line with “default:” on
it.
Here is the diff:
Code:
1399d1398
Finally, some may have one last problem that I had. After some searching, it was found that the file:
/usr/include/linux/ixjuser.h line 353 needs to be changed from:
Code:
IXJ_CADENCE_ELEMENT __user *ce;
to
Code:
IXJ_CADENCE_ELEMENT __user, *ce;
after that, it should compile correctly. Maybe someday someone will make an ebuild that does this automatically, or
something. Hope this helps someone.
281/433
mount a .dmg on macosx using only the terminal
if you have no gui access to the mac, you can:
$ hdiutil attach DarwinPorts-1.7.0-10.4-Tiger.dmg -verbose
67/433