Changeset 7784


Ignore:
Timestamp:
02/12/19 22:42:07 (6 months ago)
Author:
baker
Message:

fix IP address parsing and other misc. routines in src/libsrc/{libdali,util}

Location:
trunk/src/libsrc
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libsrc/libdali/network.c

    r7611 r7784  
    4949  int isIPv6 = 0; 
    5050  char *ptr, *tail; 
    51   int err = 0; 
    5251 
    5352  if (dlp_sockstartup ()) 
     
    105104    } 
    106105 
     106    /* This makes no sense! Not to mention that nport is uninitialized. */ 
     107    /* See similar code in slink2ew/libslink/network.c. */ 
     108    /* Commented out 2/12/2019 LMB */ 
     109#if 0 
    107110    if(nport == 0) { 
    108111      strncpy(nodeport, "16000", strlen("16000") + 1); 
    109112    } 
     113#endif 
    110114 
    111115    /* Sanity test the port number */ 
  • trunk/src/libsrc/libdali/parse_ip_address.c

    r7775 r7784  
    126126#include <ctype.h>                      /* isalnum() */ 
    127127#include <stdint.h>                     /* uint8_t */ 
     128#include <stdio.h>                      /* sscanf() */ 
    128129#include <stdlib.h>                     /* NULL */ 
    129 #include <stdio.h> 
    130 #include <string.h> 
     130#include <string.h>                     /* strchr() */ 
    131131 
    132132#ifndef _WINNT 
     
    781781    struct in6_addr addr2; 
    782782    struct sockaddr_in6 lookupAddr; 
     783#ifdef _WINNT 
    783784    int lookupLength = sizeof(struct sockaddr_in6); 
     785#endif 
     786 
     787 
    784788    lookupAddr.sin6_family = AF_INET6; 
    785789 
    786790    //First, determine whether we are dealing with IPv6 or IPv4: 
    787     if(parse_ip_address_string(&ip1, hostStr, portStr, &isIPv6) <= 0) { 
     791    if(parse_ip_address_string(ip1, hostStr, portStr, &isIPv6) <= 0) { 
    788792      //this is an error! probably should warn but for now just return 0: 
    789793      return 0; 
     
    799803      return 0; /*false*/ 
    800804   } else { 
    801       //In IPv6, the first 48 bits are used for the routing prefix and the next  
    802       //16 bits are used for the subnet ID. Because of this, the first 64 bits  
     805      //In IPv6, the first 48 bits are used for the routing prefix and the next 
     806      //16 bits are used for the subnet ID. Because of this, the first 64 bits 
    803807      //(or four 16-bit blocks) must be the same for two addresses to be on the same subnet 
    804  
    805808      //call inet_pton() to get string addresses into structs: 
    806809#ifdef _WINNT 
     
    843846    */ 
    844847   int addrLen; 
    845    struct sockaddr_in ipv4Addr; 
     848   struct sockaddr_in  ipv4Addr; 
    846849   struct sockaddr_in6 ipv6Addr; 
    847850   if(isIPv6) { 
    848       memset(&ipv6Addr, 0, sizeof(struct sockaddr_in6)); 
     851      memset(&ipv6Addr, 0, sizeof(ipv6Addr)); 
    849852      ipv6Addr.sin6_family = AF_INET6; 
    850853      memcpy(&(ipv6Addr.sin6_addr), inAddr, sizeof(ipv6Addr.sin6_addr)); 
    851854      memcpy(&(ipv6Addr.sin6_port), inPort, sizeof(ipv6Addr.sin6_port)); 
    852       addrLen = sizeof(struct sockaddr_in6); 
    853       return formatsocketaddress(&ipv6Addr, addrLen, hostString, portString); 
     855      addrLen = sizeof(ipv6Addr); 
     856      return formatsocketaddress( (struct sockaddr *) &ipv6Addr, addrLen, hostString, portString ); 
    854857   } else { 
    855       memset(&ipv4Addr, 0, sizeof(struct sockaddr_in)); 
     858      memset(&ipv4Addr, 0, sizeof(ipv4Addr)); 
    856859      ipv4Addr.sin_family = AF_INET; 
    857860      memcpy(&(ipv4Addr.sin_addr), inAddr, sizeof(ipv4Addr.sin_addr)); 
    858861      memcpy(&(ipv4Addr.sin_port), inPort, sizeof(ipv4Addr.sin_port)); 
    859       addrLen = sizeof(struct sockaddr_in); 
    860       return formatsocketaddress(&ipv4Addr, addrLen, hostString, portString); 
     862      addrLen = sizeof(ipv4Addr); 
     863      return formatsocketaddress( (struct sockaddr *) &ipv4Addr, addrLen, hostString, portString ); 
    861864   } 
    862865} 
    863866 
    864 int formatsocketaddress(const struct sockaddr *address, int addrLen, 
    865                 char hostString[64], char portString[10]) { 
     867int formatsocketaddress( const struct sockaddr *address, int addrLen, 
     868                         char hostString[64], char portString[10] ) { 
    866869  /* formatsocketaddress() accepts a (typically client) connection specified as  
    867870     'address' 
  • trunk/src/libsrc/libdali/parse_ip_address.h

    r7606 r7784  
    1717 
    1818#include <stdint.h>                     /* uint8_t */ 
     19 
     20#ifdef _WINNT 
     21#include <winsock2.h>                   /* struct sockaddr_storage */ 
     22#else 
     23#include <sys/socket.h>                 /* struct sockaddr_storage */ 
     24#endif 
    1925 
    2026enum ip_format { 
     
    4248 
    4349/* parse_ip_address.c */ 
    44 int formatsocketaddress(const struct sockaddr *address, int addrLen, 
    45                 char hostString[64], char portString[10]); 
    46 int numeric_address_to_string(int isIPv6, uint8_t inAddr[16], uint8_t inPort[2], 
    47                               char hostString[64], char portString[10]); 
     50int formatsocketaddress( const struct sockaddr *address, int addrLen, 
     51                         char hostString[64], char portString[10] ); 
     52int numeric_address_to_string( int isIPv6, uint8_t inAddr[16], uint8_t inPort[2], 
     53                               char hostString[64], char portString[10] ); 
    4854 
    4955enum ip_format parse_ip_address_string(const char *, char[64], char[10], int*); 
  • trunk/src/libsrc/util/cosmos0putaway.c

    r7724 r7784  
    234234        52 - 58 Units of the data values(e.g., cm / sec2); 60 - 61 Index code for units 
    235235        */ 
    236         /*sprintf(hour_line, "17770    raw accel.pts, approx  178 secs, units=counts (50),Format=(10I8)\r\n"); /* we want leading spaces */ 
     236        /* sprintf(hour_line, "17770    raw accel.pts, approx  178 secs, units=counts (50),Format=(10I8)\r\n"); */ 
     237        /* we want leading spaces */ 
    237238        if (fwrite("17770    raw accel.pts,   approx 178 secs,  units=counts (50),  Format=(10I8)    \n", 82, 1, COSMOS0fp) != 1) 
    238239        { 
     
    278279        char    day_line[122]; 
    279280        char    fourdigits[5]; 
    280         char    hour_line[82] = "                                                                                    ";  
     281        char    hour_line[82] = "                                                                                 ";  
    281282        char    sample[12]; 
    282         char    sixdigits[7]; 
    283283        char    elevendigits[12]; 
    284284        char   *msg_p;        /* pointer into tracebuf data */ 
  • trunk/src/libsrc/util/parse_ip_address.c

    r7775 r7784  
    124124 ******************************************************************************/ 
    125125 
    126 #include <ctype.h>         /* isalnum() */ 
    127 #include <stdint.h>        /* uint8_t */ 
    128 #include <stdlib.h>        /* NULL */ 
    129 #include <string.h>        /*  strchr() */ 
    130 #include <stdio.h>                 /* sscanf() */ 
     126#include <ctype.h>                      /* isalnum() */ 
     127#include <stdint.h>                     /* uint8_t */ 
     128#include <stdio.h>                      /* sscanf() */ 
     129#include <stdlib.h>                     /* NULL */ 
     130#include <string.h>                     /* strchr() */ 
    131131 
    132132#include <socket_ew.h> 
    133 #include <parse_ip_address.h>    /* enum ip_format */ 
     133#include <parse_ip_address.h>           /* enum ip_format */ 
    134134 
    135135#ifdef _WINNT 
     
    788788    struct in6_addr maskAddr; 
    789789    struct sockaddr_in6 lookupAddr; 
     790#ifdef _WINNT 
    790791    int lookupLength = sizeof(struct sockaddr_in6); 
     792#endif 
     793 
     794 
    791795    lookupAddr.sin6_family = AF_INET6; 
    792796 
    793797    //First, verify protocol families for ip1 and ip2: 
    794     if(parse_ip_address_string(&ip1, hostStr, portStr, &ip1_is_IPv6) <= 0) { 
     798    if(parse_ip_address_string(ip1, hostStr, portStr, &ip1_is_IPv6) <= 0) { 
    795799      //this is an error! probably should warn but for now just return 0: 
    796800      return 0; 
    797801    } 
    798     if(parse_ip_address_string(&ip2, hostStr, portStr, &ip2_is_IPv6) <= 0) { 
     802    if(parse_ip_address_string(ip2, hostStr, portStr, &ip2_is_IPv6) <= 0) { 
    799803        return 0; 
    800804    } 
    801     if(parse_ip_address_string(&netmask, hostStr, portStr, &netmask_is_IPv6) <= 0) { 
     805    if(parse_ip_address_string(netmask, hostStr, portStr, &netmask_is_IPv6) <= 0) { 
    802806        return 0; 
    803807    } 
     
    821825      //  which corresponds to a prefix ("mask") of 
    822826      //  ffff:ffff:ffff:ffff:0000:0000:0000:0000 
    823       //  Thus, only the first 64 bits will be checks as a mask  
     827      //  Thus, only the first 64 bits will be checks as a mask 
    824828#ifdef _WINNT 
    825829      if(WSAStringToAddress(TEXT(ip1), AF_INET6, NULL, (LPSOCKADDR)&lookupAddr, (LPINT)lookupLength) != 0) { 
  • trunk/src/libsrc/util/socket_ew_common.c

    r7764 r7784  
    240240      memcpy(&(ipv6Addr.sin6_port), inPort, sizeof(ipv6Addr.sin6_port)); 
    241241      addrLen = sizeof(struct sockaddr_in6); 
    242       address = &ipv6Addr; 
     242      address = (struct sockaddr *) &ipv6Addr; 
    243243   } else { 
    244244      memset(&ipv4Addr, 0, sizeof(struct sockaddr_in)); 
     
    247247      memcpy(&(ipv4Addr.sin_port), inPort, sizeof(ipv4Addr.sin_port)); 
    248248      addrLen = sizeof(struct sockaddr_in); 
    249       address = &ipv4Addr; 
     249      address = (struct sockaddr *) &ipv4Addr; 
    250250   } 
    251251     
Note: See TracChangeset for help on using the changeset viewer.