LCOV - code coverage report
Current view: top level - util/net - fd_ip4.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 21 21 100.0 %
Date: 2024-11-13 11:58:15 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "fd_ip4.h"
       2             : #include "../fd_util.h"
       3             : 
       4             : #include <stdlib.h>
       5             : 
       6             : 
       7             : /* FIXME add bounds checks to fd_util version */
       8             : static int
       9          96 : __fd_cstr_to_uchar( char const * cstr ) {
      10          96 :   char const * endptr = NULL;
      11          96 :   ulong value = strtoul( cstr, (char **)&endptr, 10 );
      12          96 :   if( FD_UNLIKELY( cstr==endptr || endptr[0] || value>UCHAR_MAX ) ) return -1;
      13          84 :   return (int)value;
      14          96 : }
      15             : 
      16             : 
      17             : int
      18             : fd_cstr_to_ip4_addr( char const * s,
      19          39 :                      uint *       out ) {
      20             : 
      21          39 :   char _s[ 16 ];
      22          39 :   strncpy( _s, s, 15 );
      23          39 :   _s[ 15 ] = '\0';
      24             : 
      25          39 :   char *tok[ 5 ];
      26          39 :   if( FD_UNLIKELY( fd_cstr_tokenize( tok, 5UL, _s, '.' )!=4UL ) )
      27          15 :     return 0;
      28             : 
      29          24 :   int v0 = __fd_cstr_to_uchar( tok[ 0 ] );
      30          24 :   int v1 = __fd_cstr_to_uchar( tok[ 1 ] );
      31          24 :   int v2 = __fd_cstr_to_uchar( tok[ 2 ] );
      32          24 :   int v3 = __fd_cstr_to_uchar( tok[ 3 ] );
      33          24 :   if( FD_UNLIKELY( (v0<0)|(v1<0)|(v2<0)|(v3<0) ) ) return 0;
      34          12 :   *out = FD_IP4_ADDR( v0, v1, v2, v3 );
      35          12 :   return 1;
      36          24 : }

Generated by: LCOV version 1.14