9 int aimutil_put8(u_char *buf, u_char data)
11 buf[0] = (u_char)data&0xff;
15 u_char aimutil_get8(u_char *buf)
21 * Endian-ness issues here?
23 int aimutil_put16(u_char *buf, u_short data)
25 buf[0] = (u_char)(data>>8)&0xff;
26 buf[1] = (u_char)(data)&0xff;
30 u_short aimutil_get16(u_char *buf)
33 val = (buf[0] << 8) & 0xff00;
34 val+= (buf[1]) & 0xff;
38 int aimutil_put32(u_char *buf, u_long data)
40 buf[0] = (u_char)(data>>24)&0xff;
41 buf[1] = (u_char)(data>>16)&0xff;
42 buf[2] = (u_char)(data>>8)&0xff;
43 buf[3] = (u_char)(data)&0xff;
47 u_long aimutil_get32(u_char *buf)
50 val = (buf[0] << 24) & 0xff000000;
51 val+= (buf[1] << 16) & 0x00ff0000;
52 val+= (buf[2] << 8) & 0x0000ff00;
53 val+= (buf[3] ) & 0x000000ff;
57 int aimutil_putstr(u_char *dest, const u_char *src, int len)
59 memcpy(dest, src, len);
64 * Tokenizing functions. Used to portably replace strtok/sep.
68 int aimutil_tokslen(char *toSearch, int index, char dl)
76 next = strchr(toSearch, dl);
78 while(curCount < index && next != NULL)
82 next = strchr(last, dl);
85 if ((curCount < index) || (next == NULL))
86 toReturn = strlen(toSearch) - (curCount - 1);
88 toReturn = next - toSearch - (curCount - 1);
93 int aimutil_itemcnt(char *toSearch, char dl)
100 next = strchr(toSearch, dl);
105 next = strchr(next + 1, dl);
111 char *aimutil_itemidx(char *toSearch, int index, char dl)
121 next = strchr(toSearch, dl);
123 while(curCount < index && next != NULL)
127 next = strchr(last, dl);
130 if (curCount < index)
132 toReturn = malloc(sizeof(char));
135 next = strchr(last, dl);
137 if (curCount < index)
139 toReturn = malloc(sizeof(char));
146 toReturn = malloc((strlen(last) + 1) * sizeof(char));
147 strcpy(toReturn, last);
151 toReturn = malloc((next - last + 1) * sizeof(char));
152 memcpy(toReturn, last, (next - last));
153 toReturn[next - last] = '\0';