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