-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutil.c
More file actions
71 lines (60 loc) · 1.36 KB
/
util.c
File metadata and controls
71 lines (60 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<obliv.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include"util.h"
double wallClock()
{
struct timespec t;
clock_gettime(CLOCK_REALTIME,&t);
return t.tv_sec+1e-9*t.tv_nsec;
}
void ocTestUtilTcpOrDie(ProtocolDesc* pd,const char* remote_host,
const char* port)
{
if(!remote_host)
{ if(protocolAcceptTcp2P(pd,port)!=0)
{ fprintf(stderr,"TCP accept failed\n");
exit(1);
}
}
else
if(protocolConnectTcp2P(pd,remote_host,port)!=0)
{ fprintf(stderr,"TCP connect failed\n");
exit(1);
}
}
//hex, int, char conversion functions
int hex_to_int(char c){
int first = c / 16 - 3;
int second = c % 16;
int result = first*10 + second;
if(result > 9) result--;
return result;
}
int hex_to_ascii(char c, char d){
int high = hex_to_int(c) * 16;
int low = hex_to_int(d);
return high+low;
}
void hex_string_to_char_array(const char * hex_string) {
int length = strlen(hex_string);
int i;
char buf = 0;
for(i = 0; i < length; i++){
if(i % 2 != 0){
printf("%i\n", hex_to_ascii(buf, hex_string[i]));
}else{
buf = hex_string[i];
}
}
}
bool compare(uint8_t *x, uint8_t *y, int len) {
for (int i = 0; i < len; i++) {
if (x[i] != y[i]) {
return false;
}
}
return true;
}