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