1
1
/*
2
2
*PostgreSQL type definitions for MAC addresses.
3
3
*
4
- *$Id: mac.c,v 1.6 1998/10/26 01:01:36 tgl Exp $
4
+ *$Id: mac.c,v 1.7 1999/03/22 05:00:57 momjian Exp $
5
5
*/
6
6
7
7
#include <stdio.h>
@@ -156,7 +156,6 @@ macaddr_in(char *str)
156
156
157
157
if (strlen (str )> 0 )
158
158
{
159
-
160
159
count = sscanf (str ,"%x:%x:%x:%x:%x:%x" ,& a ,& b ,& c ,& d ,& e ,& f );
161
160
if (count != 6 )
162
161
count = sscanf (str ,"%x-%x-%x-%x-%x-%x" ,& a ,& b ,& c ,& d ,& e ,& f );
@@ -168,18 +167,12 @@ macaddr_in(char *str)
168
167
count = sscanf (str ,"%2x%2x.%2x%2x.%2x%2x" ,& a ,& b ,& c ,& d ,& e ,& f );
169
168
170
169
if (count != 6 )
171
- {
172
170
elog (ERROR ,"macaddr_in: error in parsing \"%s\"" ,str );
173
- return (NULL );
174
- }
175
171
176
172
if ((a < 0 )|| (a > 255 )|| (b < 0 )|| (b > 255 )||
177
173
(c < 0 )|| (c > 255 )|| (d < 0 )|| (d > 255 )||
178
174
(e < 0 )|| (e > 255 )|| (f < 0 )|| (f > 255 ))
179
- {
180
175
elog (ERROR ,"macaddr_in: illegal address \"%s\"" ,str );
181
- return (NULL );
182
- }
183
176
}
184
177
else
185
178
{
@@ -232,40 +225,52 @@ macaddr_out(macaddr *addr)
232
225
bool
233
226
macaddr_lt (macaddr * a1 ,macaddr * a2 )
234
227
{
228
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
229
+ return FALSE;
235
230
return ((hibits (a1 )< hibits (a2 ))||
236
231
((hibits (a1 )== hibits (a2 ))&& lobits (a1 )< lobits (a2 )));
237
232
}
238
233
239
234
bool
240
235
macaddr_le (macaddr * a1 ,macaddr * a2 )
241
236
{
237
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
238
+ return FALSE;
242
239
return ((hibits (a1 )< hibits (a2 ))||
243
240
((hibits (a1 )== hibits (a2 ))&& lobits (a1 ) <=lobits (a2 )));
244
241
}
245
242
246
243
bool
247
244
macaddr_eq (macaddr * a1 ,macaddr * a2 )
248
245
{
246
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
247
+ return FALSE;
249
248
return ((hibits (a1 )== hibits (a2 ))&& (lobits (a1 )== lobits (a2 )));
250
249
}
251
250
252
251
bool
253
252
macaddr_ge (macaddr * a1 ,macaddr * a2 )
254
253
{
254
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
255
+ return FALSE;
255
256
return ((hibits (a1 )> hibits (a2 ))||
256
257
((hibits (a1 )== hibits (a2 ))&& lobits (a1 ) >=lobits (a2 )));
257
258
}
258
259
259
260
bool
260
261
macaddr_gt (macaddr * a1 ,macaddr * a2 )
261
262
{
263
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
264
+ return FALSE;
262
265
return ((hibits (a1 )> hibits (a2 ))||
263
266
((hibits (a1 )== hibits (a2 ))&& lobits (a1 )> lobits (a2 )));
264
267
}
265
268
266
269
bool
267
270
macaddr_ne (macaddr * a1 ,macaddr * a2 )
268
271
{
272
+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
273
+ return FALSE;
269
274
return ((hibits (a1 )!= hibits (a2 ))|| (lobits (a1 )!= lobits (a2 )));
270
275
}
271
276
@@ -299,6 +304,9 @@ macaddr_manuf(macaddr *addr)
299
304
int length ;
300
305
text * result ;
301
306
307
+ if (!PointerIsValid (addr ))
308
+ return NULL ;
309
+
302
310
for (manuf = manufacturers ;manuf -> name != NULL ;manuf ++ )
303
311
{
304
312
if ((manuf -> a == addr -> a )&&