Annotation of dietlibc/t.c, revision 1.183
1.56 fefe 1: #define _GNU_SOURCE
1.47 fefe 2: #define _FILE_OFFSET_BITS 64
1.1 cvs 3: #include <unistd.h>
4: #include <endian.h>
5: #include <stdlib.h>
6: #include <dirent.h>
7: #include <pwd.h>
1.40 fefe 8: #include <shadow.h>
1.1 cvs 9: #include <stdio.h>
10: #include <assert.h>
11: #include <sys/mount.h>
1.7 fefe 12: #include <time.h>
1.9 fefe 13: #include <sys/stat.h>
1.10 fefe 14: #include <stdio.h>
1.12 fefe 15: #include <arpa/inet.h>
1.13 fefe 16: #include <sys/sem.h>
1.14 fefe 17: #include <sys/shm.h>
1.17 fefe 18: #include <math.h>
1.20 fefe 19: #include <termios.h>
1.22 fefe 20: #include <netdb.h>
1.38 fefe 21: #include <sys/mman.h>
1.45 fefe 22: #include <ctype.h>
1.49 fefe 23: #include <mntent.h>
1.53 fefe 24: #include <regex.h>
1.56 fefe 25: #include <sys/types.h>
26: #include <sys/msg.h>
1.63 fefe 27: #include <string.h>
1.76 fefe 28: #include <sys/socket.h>
29: #include <netdb.h>
1.86 fefe 30: #include <signal.h>
1.88 fefe 31: #include <sys/io.h>
1.97 fefe 32: #include <getopt.h>
1.101 fefe 33: #include <arpa/nameser.h>
34: #include <resolv.h>
1.102 fefe 35: #include <fnmatch.h>
1.109 fefe 36: #include <stdarg.h>
1.118 fefe 37: #include <sys/wait.h>
1.133 fefe 38: #include <libgen.h>
1.144 fefe 39: #include <math.h>
1.121 fefe 40: #include <errno.h>
41: #include <syslog.h>
42: #include <sys/un.h>
43: #include <fcntl.h>
1.150 fefe 44: #include <iconv.h>
1.166 fefe 45: #include <features.h>
46: #ifdef __dietlibc__
47: #include <md5.h>
1.170 fefe 48: #include <write12.h>
1.166 fefe 49: #endif
1.121 fefe 50:
51: #if 0
52: static const char* Ident;
53: static int Option;
54: static int Facility;
55: static struct sockaddr_un sock;
56: static int fd=-1;
57:
58: static void syslogconnect(void) {
59: sock.sun_family=AF_UNIX;
60: strcpy(sock.sun_path,"/dev/log");
61: if ((fd=socket(AF_UNIX,SOCK_STREAM,0))==-1) return;
62: if (connect(fd,(struct sockaddr*)&sock,sizeof(sock))==-1) {
63: int save=errno;
64: close(fd);
65: fd=-1;
1.109 fefe 66: }
1.121 fefe 67: fcntl(fd,F_SETFL,FD_CLOEXEC); /* doesn't work? too bad */
1.109 fefe 68: }
1.107 fefe 69:
1.121 fefe 70: void openlog(const char *ident, int option, int facility) {
71: Ident=ident;
72: Option=option;
73: Facility=facility;
74: syslogconnect();
1.116 fefe 75: }
76:
1.121 fefe 77: void syslog(int priority, const char *format, ...) {
78: /* write(fd,"<13>Jun 29 19:21:32 leitner: fnord",...) */
79: }
80:
81: void closelog(void) {
82: }
83: #endif
84:
1.139 fefe 85: void foo(int tmp,...) {
86: long long l;
87: va_list va;
88: va_start(va,tmp);
89: l=va_arg(va,long long);
90: if (l!=-1) write(2,"kaputt\n",7);
91: }
92:
1.176 fefe 93: int compint(const void *a, const void *b) {
1.179 fefe 94: register const int* A=a;
95: register const int* B=b;
1.176 fefe 96: return *B-*A;
97: }
98:
1.164 fefe 99: extern char* strcpy2(char*a,char*b);
100:
101: #define rdtscl(low) \
102: __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
103:
1.174 fefe 104: #if 0
1.171 fefe 105: int traverse(const char* file, const struct stat* sb, int flag) {
106: __write1("found ");
107: __write1(file);
108: __write1("\n");
109: return 0;
110: }
1.174 fefe 111: #endif
1.171 fefe 112:
1.97 fefe 113: int main(int argc,char *argv[]) {
1.183 ! fefe 114: #ifdef NEW
! 115: struct protoent se,*tmp;
! 116: char buf[1000];
! 117: while (getprotoent_r(&se,buf,sizeof(buf),&tmp)==0) {
1.181 fefe 118: int i;
1.183 ! fefe 119: printf("name %s\tproto %d\n",se.p_name,se.p_proto);
1.182 fefe 120: for (i=0; i<16; ++i) {
1.183 ! fefe 121: if (!se.p_aliases[i]) break;
! 122: printf(" alias %s\n",se.p_aliases[i]);
1.182 fefe 123: }
1.181 fefe 124: }
1.183 ! fefe 125: #else
! 126: struct protoent* se;
! 127: while (se=getprotoent()) {
! 128: int i;
! 129: printf("name %s\tproto %d\n",se->p_name,se->p_proto);
! 130: for (i=0; i<16; ++i) {
! 131: if (!se->p_aliases[i]) break;
! 132: printf(" alias %s\n",se->p_aliases[i]);
! 133: }
! 134: }
! 135: #endif
1.181 fefe 136: #if 0
1.180 fefe 137: fd_set f;
138: struct timeval tv;
139: FD_ZERO(&f);
140: tv.tv_sec=3; tv.tv_usec=0;
141: select(1,&f,0,0,&tv);
1.181 fefe 142: #endif
1.180 fefe 143: #if 0
1.179 fefe 144: char server_version_string[]="SSH-1.99-OpenSSH_2.9p2\n";
145: int remote_major, remote_minor;
146: char remote_version[1000];
147: if (sscanf(server_version_string, "SSH-%d.%d-%[^\n]\n",
148: &remote_major, &remote_minor, remote_version) != 3) puts("punt");
149: printf("%d.%d.%.100s\n",remote_major,remote_minor,remote_version);
1.180 fefe 150: #endif
1.172 fefe 151: #if 0
1.171 fefe 152: ftw("/tmp",traverse,10);
1.172 fefe 153: #endif
1.168 fefe 154: #if 0
1.169 fefe 155: printf("%u\n",getuid32());
156: #endif
157: #if 0
1.167 fefe 158: FILE *f;
159: int i;
160: char addr6p[8][5];
161: int plen, scope, dad_status, if_idx;
162: char addr6[40], devname[20];
163: if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) {
164: while ((i=fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
165: addr6p[0], addr6p[1], addr6p[2], addr6p[3],
166: addr6p[4], addr6p[5], addr6p[6], addr6p[7],
167: &if_idx, &plen, &scope, &dad_status, devname)) != EOF) {
168: printf("i=%d\n",i);
169: }
170: }
1.168 fefe 171: #endif
1.169 fefe 172: #if 0
1.166 fefe 173: printf("%s\n",crypt("test","$1$"));
1.167 fefe 174: #endif
1.173 fefe 175: #if 0
1.166 fefe 176: MD5_CTX x;
177: unsigned char md5[16];
178: MD5Init(&x);
1.167 fefe 179: MD5Update(&x,"a",1);
1.166 fefe 180: MD5Final(md5,&x);
181: {
182: int i;
183: for (i=0; i<16; ++i) {
184: printf("%02x",md5[i]);
185: }
186: putchar('\n');
187: }
1.167 fefe 188: #endif
189: #if 0
1.165 fefe 190: printf("%d\n",memchr("aaaa",'x',4));
1.166 fefe 191: #endif
1.164 fefe 192: #if 0
193: long a,b,c;
1.161 fefe 194: char buf[20]="fnord";
1.164 fefe 195: strcpy(buf,"Fnordhausen");
196: strcpy2(buf,"Fnordhausen");
197: rdtscl(a);
198: strcpy(buf,"Fnordhausen");
199: rdtscl(b);
200: strcpy2(buf,"Fnordhausen");
201: rdtscl(c);
202: printf("C: %d ticks, asm: %d ticks\n",b-a,c-b);
203: #endif
204:
1.163 fefe 205: /* printf("%d\n",strcmp(buf,"fnord")); */
1.157 fefe 206: #if 0
207: regex_t r;
208: // printf("regcomp %d\n",regcomp(&r,"^(re([\\[0-9\\]+])*|aw):[ \t]*",REG_EXTENDED));
209: printf("regcomp %d\n",regcomp(&r,"^([A-Za-z ]+>|[]>:|}-][]>:|}-]*)",REG_EXTENDED));
210: printf("regexec %d\n",regexec(&r,"Marketing-Laufbahn hinterdir.",1,0,REG_NOSUB));
211: #endif
212: #if 0
1.156 fefe 213: FILE *f=fopen("/home/leitner/Mail/outbox","r");
214: char buf[1024];
215: int i=0;
216: if (f) {
217: while (fgets(buf,1023,f)) {
218: ++i;
219: printf("%d %lu %s",i,ftell(f),buf);
220: }
221: }
1.157 fefe 222: #endif
1.152 fefe 223: #if 0
1.151 fefe 224: char template[]="/tmp/duh/fnord-XXXXXX";
225: printf("%d\n",mkdtemp(template));
1.152 fefe 226: #endif
1.151 fefe 227: #if 0
1.150 fefe 228: char *inbuf="\xe2\x89\xa0";
229: // char *inbuf="\xc2\xa9";
230: char outbuf[100];
231: char *obptr=&outbuf;
232: size_t iblen=strlen(inbuf);
233: size_t oblen=100;
234: iconv_t i=iconv_open("utf-8","utf-8");
235: iconv(i,&inbuf,&iblen,&obptr,&oblen);
236: iconv_close(i);
237: outbuf[100-oblen]=0;
238: puts(outbuf);
1.151 fefe 239: #endif
1.150 fefe 240: #if 0
1.149 fefe 241: printf("%c %c\n",tolower('C'),toupper('c'));
1.150 fefe 242: #endif
1.147 fefe 243: #if 0
1.145 fefe 244: printf("foo\n");
1.146 fefe 245: #endif
1.145 fefe 246: #if 0
247: char strport[10];
248: int i;
249: for (i=0; i<10; ++i) strport[i]=i+'0';
250: snprintf( strport, sizeof(strport), "%d", 80 );
251: puts(strport);
252: #endif
1.179 fefe 253: #if 0
1.145 fefe 254: struct addrinfo *ai;
255: struct addrinfo hints;
256: char buf[16];
257: memset(&hints,0,sizeof(hints));
1.157 fefe 258: #if 0
1.145 fefe 259: hints.ai_family = AF_UNSPEC;
260: hints.ai_flags = AI_PASSIVE;
261: hints.ai_socktype = SOCK_STREAM;
1.157 fefe 262: #endif
263: hints.ai_family=0;
264: hints.ai_flags=0;
265: hints.ai_socktype=1;
266: hints.ai_protocol=0;
267: hints.ai_addrlen=0;
268: hints.ai_addr=0;
269: hints.ai_canonname=0;
270: hints.ai_next=0;
271: printf("%d\n",getaddrinfo("news.fu-berlin.de","119",&hints,&ai));
1.145 fefe 272: while (ai) {
273: printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
274: ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
275: ((struct sockaddr_in*)ai->ai_addr)->sin_port),
276: ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
277: ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
278: {
279: char buf[100];
280: inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
281: (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
282: (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
283: printf(" %s\n",buf);
284: }
285: ai=ai->ai_next;
286: }
287: #endif
1.144 fefe 288: #if 0
289: char buf[101];
290: __dtostr(M_PI,buf,100,6);
291: #endif
1.145 fefe 292: #if 0
1.144 fefe 293: printf("%d\n",strcasecmp("foo","FOO"));
1.145 fefe 294: #endif
1.144 fefe 295: #if 0
1.143 fefe 296: printf("%.24s", "Sun Jan 2 08:29:13 1994\n");
1.144 fefe 297: #endif
1.143 fefe 298: #if 0
299: printf("%.*s\n",13,"fnord");
300: #endif
1.141 fefe 301: #if 0
1.140 fefe 302: double d=strtod(argv[1],0);
303: printf("%g|\n",d);
1.141 fefe 304: #endif
1.140 fefe 305: #if 0
1.139 fefe 306: char buf[100];
307: printf("%d\n",__lltostr(buf,30,-1ll,10,0));
308: puts(buf);
1.140 fefe 309: #endif
310: #if 0
1.139 fefe 311: printf("%lld\n",-1ll);
312: #endif
1.143 fefe 313: #if 0
1.139 fefe 314: char *str="e";
315: setbuf(stdout,0);
316: printf("foo\n");
317: fputc(toupper(*str++),stdout);
318: printf("bar\n");
1.138 fefe 319: #endif
1.137 fefe 320: #if 0
1.136 fefe 321: fwrite("foobar",6,1,stdout);
1.137 fefe 322: #endif
1.136 fefe 323: #if 0
1.135 fefe 324: char x[5];
325: x[4]='x';
326: fgets(x,4,stdin);
327: puts(x);
328: printf("%c\n",x[4]);
1.136 fefe 329: #endif
1.134 fefe 330: #if 0
1.133 fefe 331: char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
332: char* want[]={"/usr","/",".","/",".","."};
333: int i;
334: for (i=0; i<6; ++i) {
335: printf("%s\t%s\t%s\n",paths[i],want[i],dirname(strdup(paths[i])));
336: }
1.134 fefe 337: #endif
1.133 fefe 338: #if 0
339: char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
340: char* want[]={"lib","usr","usr","/",".",".."};
341: int i;
342: for (i=0; i<6; ++i) {
343: printf("%s\t%s\t%s\n",paths[i],want[i],basename(strdup(paths[i])));
344: }
345: #endif
346: #if 0
1.132 fefe 347: int i;
348: for (i=0; i<255; ++i) {
349: int a=isalpha(i);
350: int b=(i>='a' && i<='z') || (i>='A' && i<='Z');
351: if (a!=b) printf("%d: %d %d\n",i,a,b);
352: }
1.133 fefe 353: #endif
1.131 fefe 354: #if 0
1.130 fefe 355: char* name;
356: int ptyfd,ttyfd;
357: int i=openpty(&ptyfd,&ttyfd,0,0,0);
358: if (i<0) perror("openpty");
359: printf("%d %d\n",ptyfd,ttyfd);
360: printf("%s %s\n",ttyname(ptyfd),ttyname(ttyfd));
1.131 fefe 361: #endif
1.129 fefe 362: #if 0
363: printf("0x%8.7lx\n",0xfefe);
364: #endif
365: #if 0
1.128 fefe 366: puts(ttyname(0));
1.129 fefe 367: #endif
1.178 fefe 368: #if 0
1.125 fefe 369: char buf[1024];
370: struct hostent* r;
1.177 fefe 371: r=gethostbyname("line.org");
1.174 fefe 372: if (!r) {
373: printf("dns error: %s\n",hstrerror(h_errno));
374: }
1.152 fefe 375: {
376: /* while (r=gethostent_r(buf,1024)) { */
1.125 fefe 377: if (r && r->h_name) {
1.152 fefe 378: int i;
379: printf("name \"%s\"; ", r->h_name);
380: for (i=0; i<8; ++i)
381: if (r->h_aliases[i]) {
382: printf("alias \"%s\"; ",r->h_aliases[i]);
1.174 fefe 383: } else break;
1.152 fefe 384: if ((r->h_addr_list)[0]) {
385: struct in_addr address;
386: address = *((struct in_addr *) (r->h_addr_list)[0]);
387: printf("addr %s; ", inet_ntoa(address));
388: }
389: putchar('\n');
1.125 fefe 390: }
391: }
392: #endif
393: #if 0
1.124 fefe 394: char *tmp;
395: printf("%lu\n",strtol("0xf0000000",&tmp,0));
1.125 fefe 396: #endif
1.128 fefe 397: #if 0
1.123 fefe 398: struct mntent* me;
1.127 fefe 399: FILE* f=fopen("/etc/fstab","r");
1.123 fefe 400: while (me=getmntent(f)) {
1.139 fefe 401: printf("%s\n",hasmntopt(me,"defaults"));
1.123 fefe 402: printf("%s %s %s %s %d %d\n",me->mnt_fsname,me->mnt_dir,me->mnt_type,me->mnt_opts,me->mnt_freq,me->mnt_passno);
1.139 fefe 403: break;
1.123 fefe 404: }
1.124 fefe 405: #endif
1.123 fefe 406: #if 0
407: char *tmp;
408: printf("%x\n",strtol("0Xffff",&tmp,16));
409: #endif
1.155 fefe 410: /* putchar('c');
411: write(1,"fnord\n",6); */
1.176 fefe 412: #if 0
1.121 fefe 413: struct addrinfo *ai;
1.175 fefe 414: // getaddrinfo("xorn","22",0,&ai);
415: puts(gai_strerror(getaddrinfo("xorn","22",0,&ai)));
1.121 fefe 416: #endif
1.122 fefe 417: #if 0
1.121 fefe 418: struct hostent host,*res;
419: char buf[4096];
420: int fnord;
421:
1.131 fefe 422: gethostbyname2_r("nagus",AF_INET,&host,buf,4096,&res,&fnord);
1.122 fefe 423: #endif
1.121 fefe 424: #if 0
1.119 fefe 425: char buf[128];
1.120 fefe 426: strcpy(buf,"/tmp/fnord/foo.XXXXXXX");
1.119 fefe 427: printf("%d\n",mkdtemp(buf));
428: printf("%s\n",buf);
1.120 fefe 429: #endif
1.119 fefe 430: #if 0
1.118 fefe 431: printf("%d\n",WEXITSTATUS(system("exit 17")));
1.119 fefe 432: #endif
1.113 fefe 433: #if 0
1.109 fefe 434: fnord("fnord","foo\n","bar\n",0);
1.112 fefe 435: assert(0);
1.113 fefe 436: #endif
1.105 fefe 437: #if 0
438: printf("%hd %hhd\n",-5,-1234567);
439: #endif
1.103 fefe 440: #if 0
1.102 fefe 441: printf("%d\n",fnmatch("*.o", "x.o", FNM_PATHNAME));
442: printf("%d\n",fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME));
1.103 fefe 443: #endif
1.102 fefe 444: #if 0
1.101 fefe 445: char buf[1024];
446: int len;
447: len=res_search("fu-berlin.de",ns_c_in,ns_t_ns,buf,sizeof(buf));
1.102 fefe 448: #endif
1.114 fefe 449: #if 0
1.100 fefe 450: regex_t t;
451: regmatch_t rm;
1.103 fefe 452: // regcomp(&t,"^ *read",0);
1.113 fefe 453: regcomp(&t,"\\<foo\\>",0);
454: printf("%d\n",regexec(&t," blub foo,",1,&rm,0));
1.100 fefe 455: printf("ofs %d\n",rm.rm_so);
1.101 fefe 456: #endif
1.100 fefe 457: #if 0
1.98 fefe 458: char buf[100];
1.99 fefe 459: printf("%d\n",fread(buf,1,0,stdin));
1.100 fefe 460: #endif
1.99 fefe 461: #if 0
462: char buf[100];
1.98 fefe 463: memset(buf,17,100);
464: buf[0]=0;
465: strncat(buf,"foobarbaz23",10);
466: puts(buf);
1.99 fefe 467: #endif
1.98 fefe 468: #if 0
1.97 fefe 469: int aflag = 0;
470: int bflag = 0;
471: char *cvalue = NULL;
472: int index;
473: int c;
474:
475: opterr = 1;
476:
477: while ((c = getopt (argc, argv, "abc:")) != -1)
478: switch (c)
479: {
480: case 'a':
481: aflag = 1;
482: break;
483: case 'b':
484: bflag = 1;
485: break;
486: case 'c':
487: cvalue = optarg;
488: break;
489: case '?':
490: if (isprint (optopt))
491: fprintf (stderr, "Unknown option `-%c'.\n", optopt);
492: else
493: fprintf (stderr,
494: "Unknown option character `\\x%x'.\n",
495: optopt);
496: return 1;
497: default:
498: abort ();
499: }
1.96 fefe 500:
1.97 fefe 501: printf ("aflag = %d, bflag = %d, cvalue = %s\n",
502: aflag, bflag, cvalue);
503:
504: for (index = optind; index < argc; index++)
505: printf ("Non-option argument %s\n", argv[index]);
506: return 0;
1.98 fefe 507: #endif
1.97 fefe 508: #if 0
1.96 fefe 509: char *t="foobar";
510: char *c;
511: char buf[1000];
512: puts(strcat(strcpy(buf,"HOME="),t));
1.97 fefe 513: #endif
1.89 fefe 514: #if 0
515: struct netent* n=getnetbyname("loopback");
516: printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
517: #endif
518: #if 0
1.88 fefe 519: fprintf(stdout,"foo\n");
520: sleep(1);
521: fprintf(stdout,"bar");
522: fprintf(stderr,"blonk");
523: sleep(1);
524: fprintf(stdout,"\rbz");
525: sleep(1);
526: fprintf(stdout,"\n");
527: sleep(1);
1.89 fefe 528: #endif
1.87 fefe 529: #if 0
1.86 fefe 530: sigset_t s; /* sigsetops */
531:
532: sigemptyset(&s);
533: sigaddset(&s,SIGCHLD);
534: sigaddset(&s,SIGHUP);
535: sigsuspend(&s);
1.87 fefe 536: #endif
1.85 fefe 537: #if 0
1.84 fefe 538: char buf[1024];
539: FILE *f=popen("uname -srm","r");
540: fgets(buf,1023,f);
541: pclose(f);
542: write(1,buf,strlen(buf));
1.85 fefe 543: #endif
1.84 fefe 544: #if 0
1.82 fefe 545: char type[64];
1.83 fefe 546: char filename[256];
547: int major,minor;
1.82 fefe 548: int len;
1.83 fefe 549: printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
550: printf("%s %s %d %d\n",type,filename,major,minor);
1.84 fefe 551: #endif
1.82 fefe 552: #if 0
1.81 fefe 553: char buf[100];
554: char ip[16];
555: memset(ip,0,16);
556: printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
557: puts(buf);
1.82 fefe 558: #endif
1.127 fefe 559: #if 0
1.76 fefe 560: struct addrinfo *ai;
1.78 fefe 561: struct addrinfo hints;
1.79 fefe 562: char buf[16];
1.78 fefe 563: hints.ai_family = AF_UNSPEC;
1.79 fefe 564: hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
1.78 fefe 565: hints.ai_socktype = SOCK_STREAM;
1.126 fefe 566: printf("%d\n",getaddrinfo("xorn.continuum.local","ssh",0,&ai));
1.76 fefe 567: while (ai) {
568: printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
569: ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
570: ((struct sockaddr_in*)ai->ai_addr)->sin_port),
571: ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
572: ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
1.80 fefe 573: {
574: char buf[100];
575: inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
576: (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
577: (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
578: printf(" %s\n",buf);
579: }
1.76 fefe 580: ai=ai->ai_next;
581: }
1.81 fefe 582: #endif
1.76 fefe 583: #if 0
1.71 fefe 584: int i=foo;
1.75 fefe 585: printf("load average is %3.2f\n",0.0);
1.76 fefe 586: #endif
1.70 fefe 587: #if 0
1.69 fefe 588: struct dirent **namelist;
589: int n;
1.16 fefe 590:
1.69 fefe 591: n = scandir(".", &namelist, 0, alphasort);
592: if (n < 0)
593: perror("scandir");
594: else {
595: while(n--) {
596: printf("%s\n", namelist[n]->d_name);
597: free(namelist[n]);
598: }
599: free(namelist);
600: }
1.70 fefe 601: #endif
1.68 fefe 602: #if 0
1.67 fefe 603: char foo[10]="none,zlib";
604: char *tmp,*tmp2=foo;
605: while (tmp=strsep(&tmp2,",")) {
606: puts(tmp);
607: }
1.68 fefe 608: #endif
1.65 fefe 609: #if 0
1.61 fefe 610: char foo[10];
1.64 fefe 611: printf("%d %d\n",abs(-3),abs(23));
1.63 fefe 612: strcpy(foo,"foo");
613: strncat(foo,"barbaz",3);
614: foo[6]=0;
615: puts(foo);
1.65 fefe 616: #endif
1.115 fefe 617: #if 0
1.58 fefe 618: struct hostent * host;
619: struct in_addr i;
1.57 fefe 620:
1.131 fefe 621: host = gethostbyname2("nagus",AF_INET);
1.57 fefe 622:
1.58 fefe 623: if (!host)
624: printf("host null\n");
1.57 fefe 625:
1.58 fefe 626: if (host && host->h_name) {
627: printf("name %s\n", host->h_name);
628: }
629: if (host && (host->h_addr_list)[0]) {
630: struct in_addr address;
631: address = *((struct in_addr *) (host->h_addr_list)[0]);
632: printf("addr %s\n", inet_ntoa(address));
633: }
1.59 fefe 634: #endif
1.57 fefe 635: #if 0
1.56 fefe 636: struct msgbuf bla;
637: bla.mtype=0;
638: bla.mtext[0]='x';
639: msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57 fefe 640: #endif
1.55 fefe 641: #if 0
1.54 fefe 642: char buf[PATH_MAX];
643: printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55 fefe 644: #endif
1.73 fefe 645: #if 0
1.53 fefe 646: regex_t t;
1.68 fefe 647: regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65 fefe 648: printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56 fefe 649: #endif
1.53 fefe 650: #if 0
1.52 fefe 651: float my_float = 9.2334;
652: char buffer[100];
653:
654: sprintf(buffer, "%.2f", my_float);
655: fprintf(stdout, "%s", buffer);
1.53 fefe 656: #endif
1.52 fefe 657: #if 0
1.51 fefe 658: printf("%d\n",setenv("foo","bar",0));
659: printf("%d\n",setenv("foo","bar",1));
660: execlp("printenv","printenv","foo",0);
1.52 fefe 661: #endif
1.106 fefe 662: #if 0
1.59 fefe 663: printf("%d\n",fnmatch("*c*","bin",0));
1.50 fefe 664: if (!fnmatch("s*", "sub", 0))
665: printf("s* sub\n");
666: if (!fnmatch("s*", "glob", 0))
667: printf("s* glob\n");
668: if (!fnmatch("s*b", "sub", 0))
669: printf("s*b sub\n");
670: if (!fnmatch("s*h", "sub", 0))
671: printf("s*h sub\n");
1.51 fefe 672: #endif
1.49 fefe 673: #if 0
1.48 fefe 674: char*tmp;
675: int n=asprintf(&tmp,"foo %s %d\n","bar",23);
676: write(1,tmp,n);
677: free(tmp);
1.49 fefe 678: #endif
1.41 fefe 679: #if 0
1.40 fefe 680: struct passwd *p=getpwnam("leitner");
1.41 fefe 681: struct spwd *s=getspnam("leitner");
1.39 fefe 682: printf("%g\n",30.0123);
1.41 fefe 683: #endif
1.43 fefe 684: #if 0
1.42 fefe 685: initgroups("root",100);
1.43 fefe 686: #endif
1.38 fefe 687: #if 0
1.37 fefe 688: time_t t=time(0);
689: puts(asctime(localtime(&t)));
1.38 fefe 690: #endif
1.135 fefe 691: #if 0
1.134 fefe 692: struct servent *foo=getservbyname("pop-3","tcp");
1.36 fefe 693: if (foo)
694: printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37 fefe 695: #endif
1.121 fefe 696: #if 0
1.33 fefe 697: char buf[128];
1.120 fefe 698: strcpy(buf,"/tmp/blub/foo.XXXXXXX");
1.33 fefe 699: printf("%d\n",mkstemp(buf));
1.34 fefe 700: printf("%s\n",buf);
701: unlink(buf);
1.35 fefe 702: #endif
1.33 fefe 703: #if 0
1.32 fefe 704: char buf[512]="foo";
705: strncat(buf,"barbaz",3);
706: puts(buf);
1.33 fefe 707: #endif
1.32 fefe 708: #if 0
1.31 fefe 709: time_t oink=time(0);
710: struct tm *duh=localtime(&oink);
711: strftime(buf,512,"%A %B %Y\n",duh);
712: puts(buf);
1.32 fefe 713: #endif
1.126 fefe 714: #if 0
1.28 fefe 715: struct in_addr bar;
716: struct hostent *foo;
1.125 fefe 717: inet_aton("160.45.10.8",&bar);
718: /* foo=gethostbyname("zeit.fu-berlin.de"); */
719: foo=gethostbyaddr(&bar,4,AF_INET);
1.30 fefe 720: if (foo)
721: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22 fefe 722: /* printf("%g %g\n",1e-10,1e10); */
1.31 fefe 723: #endif
1.18 fefe 724: #if 0
1.17 fefe 725: double d=0.0;
726: long long t=0x12345678ABCDEF01;
727: d/=0.0;
728: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 729: #endif
1.177 fefe 730: #if 0
1.176 fefe 731: #define SIZE 1000
732: int array[SIZE],array2[SIZE];
1.16 fefe 733: int i,j;
734: long a,b,c;
1.176 fefe 735: int *k;
736: for (i=0; i<SIZE; ++i) array[i]=rand();
737: memcpy(array2,array,sizeof(array));
738: qsort(array,SIZE,sizeof(int),compint);
739: for (i=0; i<SIZE-1; ++i)
740: assert(array[i]>array[i+1]);
741: k=bsearch(array+10,array,SIZE,sizeof(int),compint);
742: printf("%d\n",*k);
743: #endif
744: #if 0
1.16 fefe 745: printf("%p\n",malloc(0));
746: qsort(array,2,sizeof(int),compint);
747: for (i=0; i<SIZE; ++i)
748: array[i]=rand();
749: rdtscl(a);
750: qsort(array,SIZE,sizeof(int),compint);
751: rdtscl(b);
752: j=array[LOOKFOR];
753: res=bsearch(&j,array,SIZE,sizeof(int),compint);
754: rdtscl(c);
755: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
756: for (i=0; i<SIZE-1; ++i)
757: if (array[i]>array[i+1]) {
758: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
759: return 1;
760: }
761: if (*res!=j)
762: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
763: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 764: #endif
1.13 fefe 765: #if 0
1.12 fefe 766: struct in_addr duh;
767: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
768: printf("%x\n",duh.s_addr);
1.13 fefe 769: #endif
1.12 fefe 770: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 771: #if 0
1.10 fefe 772: char buf[100];
773: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
774: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 775: #endif
1.9 fefe 776: #if 0
1.7 fefe 777: struct tm duh;
778: time_t t;
1.8 fefe 779: time(&t);
780: gmtime_r(&t,&duh);
781: printf("%s\n",asctime(&duh));
1.9 fefe 782: #endif
1.8 fefe 783: #if 0
1.7 fefe 784: char buf[30];
785: duh.tm_sec=42;
786: duh.tm_min=23;
787: duh.tm_hour=17;
788: duh.tm_mday=2;
789: duh.tm_mon=7;
790: duh.tm_year=100;
791: t=mktime(&duh);
792: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 793: #endif
1.2 fefe 794: #if 0
1.1 cvs 795: int i;
796: for (i=0; i<5; i++) {
797: fprintf(stdout,"first message\n");
798: fprintf(stdout,"second message\n");
799: fprintf(stdout,"third message\n");
800: printf("foo %d\n",i);
801: }
1.2 fefe 802: #endif
1.1 cvs 803: #if 0
804: char buf[1024];
805: sscanf("foo bar","%s",buf);
806: printf("%s\n",buf);
807: #endif
808: #if 0
809: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
810: perror("mount");
811: #endif
812: #if 0
813: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
814: int i=strtol(t+1,&t,10);
815: printf("%d %s\n",i,t);
816: #endif
817: #if 0
818: char **tmp;
1.115 fefe 819: putenv("A=foo");
1.1 cvs 820: for (tmp=environ; *tmp; tmp++)
821: puts(*tmp);
822: #endif
823: #if 0
824: char buf[1024];
825: printf("%d\n",fprintf(stderr,"duh\n"));
826: #endif
827: #if 0
828: struct passwd *p=getpwuid(100);
829: puts(p->pw_name);
830: #endif
831: #if 0
832: int pid;
833: char name[32];
834: sscanf("1 (init","%d (%15c",&pid,name);
835: printf("pid %d name %s\n",pid,name);
836: #endif
1.109 fefe 837: #if 0
1.1 cvs 838: DIR *d=opendir("/proc");
839: if (d) {
840: struct dirent *D;
841: while (D=readdir(d))
842: puts(D->d_name);
843: closedir(d);
844: }
845: #endif
846: #if 0
847: char buf[1024];
848: int fd=open("/etc/passwd",0);
849: pread(fd,buf,30,32);
850: close(fd);
851: write(1,buf,32);
852: #endif
853: #if 0
854: char *argv[] = {"echo","foo",0};
855: char buf[100];
856: buf[5]='x';
857: sprintf(buf,"foo\n");
858: if (buf[5] == 'x')
859: exit(0);
860: else
861: exit(1);
862: execvp(argv[0],argv);
863: #endif
1.10 fefe 864: #if 0
1.1 cvs 865: struct stat64 f;
866: char buf[128];
867: fstat64(0,&f);
868: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
869: return 0;
870: #endif
871: #if 0
872: FILE *f=fopen("foo","w");
873: fputc('a',f);
874: fputc('b',f);
875: fputc('c',f);
876: #endif
877: /* fprintf(stdout,"foo\n"); */
878: }
LinuxTV legacy CVS <linuxtv.org/cvs>