Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: fusl/src/network/res_mkquery.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <resolv.h> 1 #include <resolv.h>
2 #include <string.h> 2 #include <string.h>
3 #include <time.h> 3 #include <time.h>
4 #include "libc.h" 4 #include "libc.h"
5 5
6 int __res_mkquery(int op, const char *dname, int class, int type, 6 int __res_mkquery(int op,
7 » const unsigned char *data, int datalen, 7 const char* dname,
8 » const unsigned char *newrr, unsigned char *buf, int buflen) 8 int class,
9 { 9 int type,
10 » int id, i, j; 10 const unsigned char* data,
11 » unsigned char q[280]; 11 int datalen,
12 » struct timespec ts; 12 const unsigned char* newrr,
13 » size_t l = strnlen(dname, 255); 13 unsigned char* buf,
14 » int n; 14 int buflen) {
15 int id, i, j;
16 unsigned char q[280];
17 struct timespec ts;
18 size_t l = strnlen(dname, 255);
19 int n;
15 20
16 » if (l && dname[l-1]=='.') l--; 21 if (l && dname[l - 1] == '.')
17 » n = 17+l+!!l; 22 l--;
18 » if (l>253 || buflen<n || op>15u || class>255u || type>255u) 23 n = 17 + l + !!l;
19 » » return -1; 24 if (l > 253 || buflen < n || op > 15u || class > 255u || type > 255u)
25 return -1;
20 26
21 » /* Construct query template - ID will be filled later */ 27 /* Construct query template - ID will be filled later */
22 » memset(q, 0, n); 28 memset(q, 0, n);
23 » q[2] = op*8 + 1; 29 q[2] = op * 8 + 1;
24 » q[5] = 1; 30 q[5] = 1;
25 » memcpy((char *)q+13, dname, l); 31 memcpy((char*)q + 13, dname, l);
26 » for (i=13; q[i]; i=j+1) { 32 for (i = 13; q[i]; i = j + 1) {
27 » » for (j=i; q[j] && q[j] != '.'; j++); 33 for (j = i; q[j] && q[j] != '.'; j++)
28 » » if (j-i-1u > 62u) return -1; 34 ;
29 » » q[i-1] = j-i; 35 if (j - i - 1u > 62u)
30 » } 36 return -1;
31 » q[i+1] = type; 37 q[i - 1] = j - i;
32 » q[i+3] = class; 38 }
39 q[i + 1] = type;
40 q[i + 3] = class;
33 41
34 » /* Make a reasonably unpredictable id */ 42 /* Make a reasonably unpredictable id */
35 » clock_gettime(CLOCK_REALTIME, &ts); 43 clock_gettime(CLOCK_REALTIME, &ts);
36 » id = ts.tv_nsec + ts.tv_nsec/65536UL & 0xffff; 44 id = ts.tv_nsec + ts.tv_nsec / 65536UL & 0xffff;
37 » q[0] = id/256; 45 q[0] = id / 256;
38 » q[1] = id; 46 q[1] = id;
39 47
40 » memcpy(buf, q, n); 48 memcpy(buf, q, n);
41 » return n; 49 return n;
42 } 50 }
43 51
44 weak_alias(__res_mkquery, res_mkquery); 52 weak_alias(__res_mkquery, res_mkquery);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698