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