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.
 
 
 
 

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