11/*
22 *PostgreSQL type definitions for MAC addresses.
33 *
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 $
55 */
66
77#include <stdio.h>
@@ -156,7 +156,6 @@ macaddr_in(char *str)
156156
157157if (strlen (str )> 0 )
158158{
159-
160159count = sscanf (str ,"%x:%x:%x:%x:%x:%x" ,& a ,& b ,& c ,& d ,& e ,& f );
161160if (count != 6 )
162161count = sscanf (str ,"%x-%x-%x-%x-%x-%x" ,& a ,& b ,& c ,& d ,& e ,& f );
@@ -168,18 +167,12 @@ macaddr_in(char *str)
168167count = sscanf (str ,"%2x%2x.%2x%2x.%2x%2x" ,& a ,& b ,& c ,& d ,& e ,& f );
169168
170169if (count != 6 )
171- {
172170elog (ERROR ,"macaddr_in: error in parsing \"%s\"" ,str );
173- return (NULL );
174- }
175171
176172if ((a < 0 )|| (a > 255 )|| (b < 0 )|| (b > 255 )||
177173(c < 0 )|| (c > 255 )|| (d < 0 )|| (d > 255 )||
178174(e < 0 )|| (e > 255 )|| (f < 0 )|| (f > 255 ))
179- {
180175elog (ERROR ,"macaddr_in: illegal address \"%s\"" ,str );
181- return (NULL );
182- }
183176}
184177else
185178{
@@ -232,40 +225,52 @@ macaddr_out(macaddr *addr)
232225bool
233226macaddr_lt (macaddr * a1 ,macaddr * a2 )
234227{
228+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
229+ return FALSE;
235230return ((hibits (a1 )< hibits (a2 ))||
236231((hibits (a1 )== hibits (a2 ))&& lobits (a1 )< lobits (a2 )));
237232}
238233
239234bool
240235macaddr_le (macaddr * a1 ,macaddr * a2 )
241236{
237+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
238+ return FALSE;
242239return ((hibits (a1 )< hibits (a2 ))||
243240((hibits (a1 )== hibits (a2 ))&& lobits (a1 ) <=lobits (a2 )));
244241}
245242
246243bool
247244macaddr_eq (macaddr * a1 ,macaddr * a2 )
248245{
246+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
247+ return FALSE;
249248return ((hibits (a1 )== hibits (a2 ))&& (lobits (a1 )== lobits (a2 )));
250249}
251250
252251bool
253252macaddr_ge (macaddr * a1 ,macaddr * a2 )
254253{
254+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
255+ return FALSE;
255256return ((hibits (a1 )> hibits (a2 ))||
256257((hibits (a1 )== hibits (a2 ))&& lobits (a1 ) >=lobits (a2 )));
257258}
258259
259260bool
260261macaddr_gt (macaddr * a1 ,macaddr * a2 )
261262{
263+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
264+ return FALSE;
262265return ((hibits (a1 )> hibits (a2 ))||
263266((hibits (a1 )== hibits (a2 ))&& lobits (a1 )> lobits (a2 )));
264267}
265268
266269bool
267270macaddr_ne (macaddr * a1 ,macaddr * a2 )
268271{
272+ if (!PointerIsValid (a1 )|| !PointerIsValid (a2 ))
273+ return FALSE;
269274return ((hibits (a1 )!= hibits (a2 ))|| (lobits (a1 )!= lobits (a2 )));
270275}
271276
@@ -299,6 +304,9 @@ macaddr_manuf(macaddr *addr)
299304int length ;
300305text * result ;
301306
307+ if (!PointerIsValid (addr ))
308+ return NULL ;
309+
302310for (manuf = manufacturers ;manuf -> name != NULL ;manuf ++ )
303311{
304312if ((manuf -> a == addr -> a )&&