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