Home
       basic namedpipe functionality + ip-string handling - hbb - hyperbitblock
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 743068f503c8de4b0e0cea3111bed6c59d9a1133
   DIR parent 618ac6d80f4d327dd64731131e7bf030d42b8acd
  HTML Author: kroovy <me@kroovy.de>
       Date:   Wed, 16 Apr 2025 23:23:11 +0200
       
       basic namedpipe functionality + ip-string handling
       
       Diffstat:
         M hyperbitblock.c                     |      89 +++++++++++++++++++------------
       
       1 file changed, 56 insertions(+), 33 deletions(-)
       ---
   DIR diff --git a/hyperbitblock.c b/hyperbitblock.c
       @@ -3,48 +3,71 @@
        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/mman.h>
       +#include <sys/types.h>
       +#include <sys/uio.h>
        #include <unistd.h>
        
       -int
       -is_bit_set(unsigned value, unsigned bitindex) {
       +#include <ctype.h>
       +#include <fcntl.h>
       +
       +int is_bit_set(unsigned value, unsigned bitindex) {
            return (value & (1 << bitindex)) != 0;
        }
        
       -int
       -main
       -(void)
       -{
       -
       -    uint8_t v4[] =
       -    {
       -          0b00000000   /*  18 */
       -        , 0b00010000   /* 119 */
       -        , 0b01001000   /*   9 */
       -        , 0b10101011   /* 193 */
       -    };
       +int str_to_ip(char *s, uint8_t *v4) {
       +    uint8_t oct=0;
       +    
       +    int i,j;
        
       -    //uint8_t v4[] =
       -    //{
       -    //      0b00001010   /* 10 */
       -    //    , 0b00000000   /*  0 */
       -    //    , 0b00000000   /*  0 */
       -    //    , 0b00010110   /* 22 */
       -    //};
       +    j=0;
       +    for (i=0 ;s[i] != '\0'; i++) {
       +        if (s[i] == '.') {
       +            v4[j] = oct;
       +            oct = 0;
       +            j++;
        
       -    uint32_t i32 = (v4[0] << 24) | (v4[1] << 16) | (v4[2] << 8) | v4[3];
       +        } else {
       +            oct *= 10;
       +            oct += (int)s[i] - '0';
       +        }
       +    }
       +    v4[j] = oct;
       +    
       +    return 0;
       +}
        
       +//    uint8_t v4[] = {
       +//
       +//          0b00000000   /*  18 */
       +//        , 0b00010000   /* 119 */
       +//        , 0b01001000   /*   9 */
       +//        , 0b10101011   /* 193 */
       +//    };
        
       -    //uint8_t v = 0b0000011;
       -    //uint8_t i = 0;
       -    
       -    printf("My IP is: %u.%u.%u.%u\n",v4[0],v4[1],v4[2],v4[3]);
       -    printf("That calculates to: %u\n",i32);
       +int main(void) {
       +    int fd;
       +    int i, res;
       +    uint8_t v4[4] = {0,0,0,0};
       +    uint32_t i32 = 0;
        
       -    //if (is_bit_set(v, i)) {
       -    //    printf("bit is set at index: %d\n", i);
       -    //} else {
       -    //    printf("bit is not set at index: %d\n", i);
       -    //}
       +    char c;
       +    char line[64];
        
       -    return 0;
       +nextline:
       +    fd = open("mynamedpipe", O_RDONLY);
       +    for (i=0; (res = read(fd, &c, 1)) > 0; i++) { //consider readline/getline
       +        line[i] = c;
       +        if (c == '\n') {
       +            line[i] = '\0';
       +            break;
       +        }
       +        c = '\0';
       +    }
       +    str_to_ip(line, v4);
       +    i32 = (v4[0] << 24) | (v4[1] << 16) | (v4[2] << 8) | v4[3];
       +    printf("My IP is: %u.%u.%u.%u\n",v4[0],v4[1],v4[2],v4[3]);
       +    printf("That calculates to: %u\n\n",i32);
       +    close(fd);
       +    sleep(1); //fix with fcntl
       +    goto nextline;
        }