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