21 static inline void tai_pack(unsigned char *s
, struct tai
*t
)
27 s
[7] = x
& 255; x
>>= 8;
28 s
[6] = x
& 255; x
>>= 8;
29 s
[5] = x
& 255; x
>>= 8;
30 s
[4] = x
& 255; x
>>= 8;
31 s
[3] = x
& 255; x
>>= 8;
32 s
[2] = x
& 255; x
>>= 8;
33 s
[1] = x
& 255; x
>>= 8;
37 static inline void tai_unpack(unsigned char *s
, struct tai
*t
)
41 x
= (unsigned char) s
[0];
42 x
<<= 8; x
+= (unsigned char) s
[1];
43 x
<<= 8; x
+= (unsigned char) s
[2];
44 x
<<= 8; x
+= (unsigned char) s
[3];
45 x
<<= 8; x
+= (unsigned char) s
[4];
46 x
<<= 8; x
+= (unsigned char) s
[5];
47 x
<<= 8; x
+= (unsigned char) s
[6];
48 x
<<= 8; x
+= (unsigned char) s
[7];
53 static inline void taia_pack(unsigned char *s
, struct taia
*t
)
63 s
[7] = x
& 255; x
>>= 8;
64 s
[6] = x
& 255; x
>>= 8;
65 s
[5] = x
& 255; x
>>= 8;
70 s
[3] = x
& 255; x
>>= 8;
71 s
[2] = x
& 255; x
>>= 8;
72 s
[1] = x
& 255; x
>>= 8;
76 static inline void taia_unpack(unsigned char *s
, struct taia
*t
)
80 tai_unpack(s
, &t
->sec
);
84 x
= (unsigned char) s
[4];
85 x
<<= 8; x
+= (unsigned char) s
[5];
86 x
<<= 8; x
+= (unsigned char) s
[6];
87 x
<<= 8; x
+= (unsigned char) s
[7];
91 x
= (unsigned char) s
[0];
92 x
<<= 8; x
+= (unsigned char) s
[1];
93 x
<<= 8; x
+= (unsigned char) s
[2];
94 x
<<= 8; x
+= (unsigned char) s
[3];
99 #define tai_unix(t, u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u)))
101 static inline void taia_now(struct taia
*t
)
105 gettimeofday(&now
, NULL
);
107 tai_unix(&t
->sec
, now
.tv_sec
);
108 t
->nano
= 1000 * now
.tv_usec
+ 500;
112 static inline void taia_sub(struct taia
*res
, const struct taia
*u
,
113 const struct taia
*v
)
115 unsigned long unano
= u
->nano
;
116 unsigned long uatto
= u
->atto
;
118 res
->sec
.x
= u
->sec
.x
- v
->sec
.x
;
119 res
->nano
= unano
- v
->nano
;
120 res
->atto
= uatto
- v
->atto
;
122 if (res
->atto
> uatto
) {
123 res
->atto
+= 1000000000UL;
127 if (res
->nano
> unano
) {
128 res
->nano
+= 1000000000UL;
133 static inline void taia_add(struct taia
*res
, const struct taia
*u
,
134 const struct taia
*v
)
136 res
->sec
.x
= u
->sec
.x
+ v
->sec
.x
;
137 res
->nano
= u
->nano
+ v
->nano
;
138 res
->atto
= u
->atto
+ v
->atto
;
140 if (res
->atto
> 999999999UL) {
141 res
->atto
-= 1000000000UL;
145 if (res
->nano
> 999999999UL) {
146 res
->nano
-= 1000000000UL;
151 static inline int taia_less(const struct taia
*t
, const struct taia
*u
)
153 if (t
->sec
.x
< u
->sec
.x
)
155 if (t
->sec
.x
> u
->sec
.x
)
157 if (t
->nano
< u
->nano
)
159 if (t
->nano
> u
->nano
)
161 return t
->atto
< u
->atto
;
164 extern bool taia_looks_good(struct taia
*arr_taia
, struct taia
*pkt_taia
);