Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

237 lines
5.4 KiB

  1. #include "fmt.h"
  2. #include "scan.h"
  3. #include "str.h"
  4. #include "uint16.h"
  5. #include "uint32.h"
  6. #include "stralloc.h"
  7. #include "socket.h"
  8. #include "buffer.h"
  9. #include "ip4.h"
  10. #include "ip6.h"
  11. #include "mmap.h"
  12. #include "open.h"
  13. #include "byte.h"
  14. #include "textcode.h"
  15. #include "dns.h"
  16. #include "case.h"
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <string.h>
  21. #define rdtscl(low) \
  22. __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
  23. int main(int argc,char* argv[]) {
  24. char ip[16];
  25. char buf[32];
  26. printf("%d (expect 2)\n",scan_ip6("::",ip));
  27. printf("%d (expect 3)\n",scan_ip6("::1",ip));
  28. printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip));
  29. printf("%.*s\n",fmt_ip6(buf,ip),buf);
  30. #if 0
  31. static stralloc s,t;
  32. stralloc_copys(&s,"fnord");
  33. stralloc_copys(&t,"abc"); printf("%d\n",stralloc_diff(&s,&t));
  34. stralloc_copys(&t,"fnor"); printf("%d\n",stralloc_diff(&s,&t));
  35. stralloc_copys(&t,"fnord"); printf("%d\n",stralloc_diff(&s,&t));
  36. stralloc_copys(&t,"fnordh"); printf("%d\n",stralloc_diff(&s,&t));
  37. stralloc_copys(&t,"hausen"); printf("%d\n",stralloc_diff(&s,&t));
  38. #endif
  39. #if 0
  40. static stralloc s;
  41. stralloc_copys(&s,"fnord");
  42. printf("%d\n",stralloc_diffs(&s,"abc"));
  43. printf("%d\n",stralloc_diffs(&s,"fnor"));
  44. printf("%d\n",stralloc_diffs(&s,"fnord"));
  45. printf("%d\n",stralloc_diffs(&s,"fnordh"));
  46. printf("%d\n",stralloc_diffs(&s,"hausen"));
  47. #endif
  48. #if 0
  49. printf("%d\n",case_starts("fnordhausen","FnOrD"));
  50. printf("%d\n",case_starts("fnordhausen","blah"));
  51. #endif
  52. #if 0
  53. char buf[]="FnOrD";
  54. case_lowers(buf);
  55. puts(buf);
  56. #endif
  57. #if 0
  58. char buf[100]="foo bar baz";
  59. printf("%d (expect 7)\n",byte_rchr(buf,11,' '));
  60. #endif
  61. #if 0
  62. unsigned long size;
  63. char* buf=mmap_read(argv[1],&size);
  64. if (buf) {
  65. unsigned int x=fmt_yenc(0,buf,size);
  66. unsigned int y;
  67. char* tmp=malloc(x+1);
  68. y=fmt_yenc(tmp,buf,size);
  69. write(1,tmp,x);
  70. }
  71. #endif
  72. #if 0
  73. char buf[100];
  74. char buf2[100];
  75. unsigned int len,len2;
  76. buf[fmt_yenc(buf,"http://localhost/~fefe",22)]=0;
  77. buffer_puts(buffer_1,buf);
  78. buffer_putsflush(buffer_1,"\n");
  79. if ((buf[len2=scan_yenc(buf,buf2,&len)])!='\n') {
  80. buffer_putsflush(buffer_2,"parse error!\n");
  81. return 1;
  82. }
  83. buffer_put(buffer_1,buf2,len2);
  84. buffer_putsflush(buffer_1,"\n");
  85. return 0;
  86. #endif
  87. #if 0
  88. char buf[100];
  89. char buf2[100];
  90. unsigned int len,len2;
  91. buf[fmt_base64(buf,"foo:bar",7)]=0;
  92. buffer_puts(buffer_1,buf);
  93. buffer_putsflush(buffer_1,"\n");
  94. if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) {
  95. buffer_putsflush(buffer_2,"parse error!\n");
  96. return 1;
  97. }
  98. buffer_put(buffer_1,buf2,len2);
  99. buffer_putsflush(buffer_1,"\n");
  100. return 0;
  101. #endif
  102. #if 0
  103. unsigned long size;
  104. char* buf=mmap_read(argv[1],&size);
  105. if (buf) {
  106. unsigned int x=fmt_uuencoded(0,buf,size);
  107. unsigned int y;
  108. char* tmp=malloc(x+1);
  109. y=fmt_uuencoded(tmp,buf,size);
  110. write(1,tmp,x);
  111. }
  112. #endif
  113. #if 0
  114. char buf[]="00000000000000000000000000000001";
  115. char ip[16];
  116. if (scan_ip6_flat(buf,ip) != str_len(buf))
  117. buffer_putsflush(buffer_2,"parse error!\n");
  118. #endif
  119. #if 0
  120. int fd=open_read("t.c");
  121. buffer b;
  122. char buf[1024];
  123. char line[20];
  124. int i;
  125. buffer_init(&b,read,fd,buf,1024);
  126. i=buffer_getline(&b,line,19);
  127. buffer_puts(buffer_1,"getline returned ");
  128. buffer_putulong(buffer_1,i);
  129. buffer_puts(buffer_1,"\n");
  130. buffer_puts(buffer_1,line);
  131. buffer_flush(buffer_1);
  132. #endif
  133. #if 0
  134. buffer_putulong(buffer_1,23);
  135. // buffer_putspace(buffer_1);
  136. buffer_putsflush(buffer_1,"\n");
  137. // buffer_flush(buffer_1);
  138. #endif
  139. #if 0
  140. long a,b,c;
  141. char buf[4096];
  142. char buf2[4096];
  143. memcpy(buf,buf2,4096);
  144. byte_copy(buf,4096,buf2);
  145. rdtscl(a);
  146. memcpy(buf,buf2,4096);
  147. rdtscl(b);
  148. byte_copy(buf,4096,buf2);
  149. rdtscl(c);
  150. printf("memcpy: %d - byte_copy: %d\n",b-a,c-b);
  151. #endif
  152. #if 0
  153. char ip[16];
  154. int i;
  155. if ((i=scan_ip6(argv[1],ip))) {
  156. char buf[128];
  157. buf[fmt_ip6(buf,ip)]=0;
  158. puts(buf);
  159. }
  160. #endif
  161. #if 0
  162. char buf[100];
  163. strcpy(buf,"foobarbaz");
  164. buf[fmt_fill(buf,3,5,100)]=0;
  165. printf("\"%s\"\n",buf);
  166. #endif
  167. #if 0
  168. unsigned long len;
  169. char *c=mmap_read("/etc/passwd",&len);
  170. printf("got map %p of len %lu\n",c,len);
  171. #endif
  172. #if 0
  173. char c;
  174. printf("%d\n",buffer_getc(buffer_0,&c));
  175. printf("%c\n",c);
  176. #endif
  177. #if 0
  178. char buf[100]="01234567890123456789012345678901234567890123456789";
  179. long a,b,c;
  180. #endif
  181. #if 0
  182. buf[ip4_fmt(buf,ip4loopback)]=0;
  183. buffer_puts(buffer_1small,buf);
  184. buffer_flush(buffer_1small);
  185. #endif
  186. #if 0
  187. buf[0]=0;
  188. buf[fmt_8long(buf,0)]=0;
  189. puts(buf);
  190. rdtscl(a);
  191. c=str_len(buf);
  192. rdtscl(b);
  193. /*byte_zero_djb(buf,j); */
  194. // printf("\n%lu %d\n",b-a,c);
  195. #endif
  196. #if 0
  197. buffer_puts(buffer_1small,"hello, world\n");
  198. buffer_flush(buffer_1small);
  199. #endif
  200. #if 0
  201. int s=socket_tcp4();
  202. char ip[4]={127,0,0,1};
  203. int t=socket_connect4(s,ip,80);
  204. #endif
  205. #if 0
  206. char buf[100]="foo bar baz fnord ";
  207. char buf2[100]="foo braz fnord";
  208. long a,b,c;
  209. long i=0,j=0,k=0;
  210. double d;
  211. uint32 l,m,n;
  212. stralloc sa={0};
  213. stralloc_copys(&sa,"fnord");
  214. stralloc_catlong0(&sa,-23,5);
  215. stralloc_append(&sa,"\n");
  216. printf("%d %d\n",str_equal("fnord","fnord1"),str_equal("fnord1","fnord"));
  217. write(1,sa.s,sa.len);
  218. printf("%d %d\n",stralloc_starts(&sa,"fnord"),stralloc_starts(&sa,"fnord\na"));
  219. l=0xdeadbeef;
  220. uint32_pack_big((char*)&m,l);
  221. uint32_unpack_big((char*)&m,&n);
  222. printf("%x %x %x\n",l,m,n);
  223. rdtscl(a);
  224. /* i=scan_double("3.1415",&d); */
  225. rdtscl(b);
  226. /*byte_zero_djb(buf,j); */
  227. rdtscl(c);
  228. printf("%lu %lu\n",b-a,c-b);
  229. #endif
  230. }