@@ -2,7 +2,9 @@ package oui
2
2
3
3
import (
4
4
"database/sql"
5
+ "errors"
5
6
"fmt"
7
+ "log"
6
8
"strconv"
7
9
"strings"
8
10
@@ -177,38 +179,48 @@ func (ouidb *OUIDB) Count() (count int64, err error) {
177
179
return
178
180
}
179
181
180
- func (ouidb * OUIDB ) Find (search string ) (matches []* VendorDef , err error ) {
182
+ func (ouidb * OUIDB ) Find (search string ) ([]* VendorDef , error ) {
181
183
mac , err := macaddr .ParseMACAddress (search )
182
184
if err != nil {
183
- return matches , err
185
+ return nil , err
184
186
}
185
187
q := fmt .Sprintf ("SELECT prefix,length,org,registry FROM %s WHERE prefix LIKE '%s%%'" , ouidb .Version , mac .OUI ())
188
+ log .Println (q )
186
189
rows , err := ouidb .Connection .Query (q )
187
190
if err != nil {
188
- return matches , err
191
+ return nil , err
189
192
}
190
193
191
194
defer rows .Close ()
192
195
196
+ errs := make ([]error , 0 )
197
+ matches := make ([]* VendorDef , 0 )
198
+
193
199
for rows .Next () {
194
200
var prefix string
195
201
var length int
196
202
var org string
197
203
var reg string
198
204
err = rows .Scan (& prefix , & length , & org , & reg )
199
205
if err != nil {
200
- return matches , err
206
+ errs = append (errs , err )
207
+ continue
201
208
}
202
209
def := & VendorDef {Prefix : prefix , Length : length , Org : org , Registry : reg }
203
210
_ , mp , err := macaddr .ParseMACPrefix (def .PrefixString ())
204
211
if err != nil {
205
- return matches , err
212
+ errs = append (errs , err )
213
+ continue
206
214
}
207
215
_ , failure := mp .Match (search )
208
216
if failure == nil {
209
217
matches = append (matches , def )
210
218
}
211
219
}
220
+ err = errors .Join (errs ... )
221
+ if err != nil {
222
+ return nil , err
223
+ }
212
224
return matches , nil
213
225
}
214
226
0 commit comments