2020int hex_get_id ( uint8_t id [], size_t len , const char query [] ) {
2121 size_t query_len = strlen ( query );
2222 if ( str_isHex ( query , query_len ) ) {
23- memset ( id , 0 , len ); // Fill up id with random numbers?
23+ memset ( id , 0 , len );
2424 bytes_from_hex ( id , query , MIN ( 2 * len , query_len ) );
2525 return 1 ;
2626 }
@@ -43,14 +43,9 @@ int is_suffix( const char str[], const char suffix[] ) {
4343 }
4444}
4545
46- void * memdup ( const void * src , size_t size ) {
47- void * out = malloc (size );
48- return memcpy ( out , src , size );
49- }
50-
5146/*
52- * Sanitize query.
53- * Convert to lowercase and removing TLDs if it matches --query-tld.
47+ * Sanitize a query string .
48+ * Convert to lowercase and remove the TLD if it matches --query-tld.
5449*
5550* example.com.p2p => example.com
5651* example.com => example.com
@@ -176,10 +171,10 @@ int id_equal( const uint8_t id1[], const uint8_t id2[] ) {
176171}
177172
178173// Check if string consist of hexdecimal characters
179- int str_isHex ( const char str [], size_t size ) {
174+ int str_isHex ( const char str [], size_t len ) {
180175 size_t i = 0 ;
181176
182- for ( i = 0 ; i < size ; i ++ ) {
177+ for ( i = 0 ; i < len ; i ++ ) {
183178 const char c = str [i ];
184179 if ( (c >= '0' && c <= '9' )
185180 || (c >= 'A' && c <= 'F' )
@@ -190,8 +185,8 @@ int str_isHex( const char str[], size_t size ) {
190185 }
191186 }
192187
193- // Return 1 if size is even
194- return !(size & 1 );
188+ // Return 1 if len is even
189+ return !(len & 1 );
195190}
196191
197192// Matches [0-9a-zA-Z._-]*
@@ -261,8 +256,7 @@ const char *str_addr( const IP *addr ) {
261256 return addrbuf ;
262257}
263258
264- int addr_is_localhost ( const IP * addr )
265- {
259+ int addr_is_localhost ( const IP * addr ) {
266260 // 127.0.0.1
267261 const uint32_t inaddr_loopback = htonl ( INADDR_LOOPBACK );
268262
@@ -276,8 +270,7 @@ int addr_is_localhost( const IP *addr )
276270 }
277271}
278272
279- int addr_is_multicast ( const IP * addr )
280- {
273+ int addr_is_multicast ( const IP * addr ) {
281274 switch ( addr -> ss_family ) {
282275 case AF_INET :
283276 return IN_MULTICAST (ntohl (((IP4 * ) addr )-> sin_addr .s_addr ));
0 commit comments