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

Side by Side Diff: fusl/src/network/proto.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 <netdb.h> 1 #include <netdb.h>
2 #include <string.h> 2 #include <string.h>
3 3
4 /* do we really need all these?? */ 4 /* do we really need all these?? */
5 5
6 static int idx; 6 static int idx;
7 static const unsigned char protos[] = { 7 static const unsigned char protos[] = {
8 » "\000ip\0" 8 "\000ip\0"
9 » "\001icmp\0" 9 "\001icmp\0"
10 » "\002igmp\0" 10 "\002igmp\0"
11 » "\003ggp\0" 11 "\003ggp\0"
12 » "\004ipencap\0" 12 "\004ipencap\0"
13 » "\005st\0" 13 "\005st\0"
14 » "\006tcp\0" 14 "\006tcp\0"
15 » "\008egp\0" 15 "\008egp\0"
16 » "\014pup\0" 16 "\014pup\0"
17 » "\021udp\0" 17 "\021udp\0"
18 » "\024hmp\0" 18 "\024hmp\0"
19 » "\026xns-idp\0" 19 "\026xns-idp\0"
20 » "\033rdp\0" 20 "\033rdp\0"
21 » "\035iso-tp4\0" 21 "\035iso-tp4\0"
22 » "\044xtp\0" 22 "\044xtp\0"
23 » "\045ddp\0" 23 "\045ddp\0"
24 » "\046idpr-cmtp\0" 24 "\046idpr-cmtp\0"
25 » "\051ipv6\0" 25 "\051ipv6\0"
26 » "\053ipv6-route\0" 26 "\053ipv6-route\0"
27 » "\054ipv6-frag\0" 27 "\054ipv6-frag\0"
28 » "\055idrp\0" 28 "\055idrp\0"
29 » "\056rsvp\0" 29 "\056rsvp\0"
30 » "\057gre\0" 30 "\057gre\0"
31 » "\062esp\0" 31 "\062esp\0"
32 » "\063ah\0" 32 "\063ah\0"
33 » "\071skip\0" 33 "\071skip\0"
34 » "\072ipv6-icmp\0" 34 "\072ipv6-icmp\0"
35 » "\073ipv6-nonxt\0" 35 "\073ipv6-nonxt\0"
36 » "\074ipv6-opts\0" 36 "\074ipv6-opts\0"
37 » "\111rspf\0" 37 "\111rspf\0"
38 » "\121vmtp\0" 38 "\121vmtp\0"
39 » "\131ospf\0" 39 "\131ospf\0"
40 » "\136ipip\0" 40 "\136ipip\0"
41 » "\142encap\0" 41 "\142encap\0"
42 » "\147pim\0" 42 "\147pim\0"
43 » "\377raw" 43 "\377raw"};
44 };
45 44
46 void endprotoent(void) 45 void endprotoent(void) {
47 { 46 idx = 0;
48 » idx = 0;
49 } 47 }
50 48
51 void setprotoent(int stayopen) 49 void setprotoent(int stayopen) {
52 { 50 idx = 0;
53 » idx = 0;
54 } 51 }
55 52
56 struct protoent *getprotoent(void) 53 struct protoent* getprotoent(void) {
57 { 54 static struct protoent p;
58 » static struct protoent p; 55 static const char* aliases;
59 » static const char *aliases; 56 if (idx >= sizeof protos)
60 » if (idx >= sizeof protos) return NULL; 57 return NULL;
61 » p.p_proto = protos[idx]; 58 p.p_proto = protos[idx];
62 » p.p_name = (char *)&protos[idx+1]; 59 p.p_name = (char*)&protos[idx + 1];
63 » p.p_aliases = (char **)&aliases; 60 p.p_aliases = (char**)&aliases;
64 » idx += strlen(p.p_name) + 2; 61 idx += strlen(p.p_name) + 2;
65 » return &p; 62 return &p;
66 } 63 }
67 64
68 struct protoent *getprotobyname(const char *name) 65 struct protoent* getprotobyname(const char* name) {
69 { 66 struct protoent* p;
70 » struct protoent *p; 67 endprotoent();
71 » endprotoent(); 68 do
72 » do p = getprotoent(); 69 p = getprotoent();
73 » while (p && strcmp(name, p->p_name)); 70 while (p && strcmp(name, p->p_name));
74 » return p; 71 return p;
75 } 72 }
76 73
77 struct protoent *getprotobynumber(int num) 74 struct protoent* getprotobynumber(int num) {
78 { 75 struct protoent* p;
79 » struct protoent *p; 76 endprotoent();
80 » endprotoent(); 77 do
81 » do p = getprotoent(); 78 p = getprotoent();
82 » while (p && p->p_proto != num); 79 while (p && p->p_proto != num);
83 » return p; 80 return p;
84 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698