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