support IPv6 configuration
[oweals/umbim.git] / cli.c
diff --git a/cli.c b/cli.c
index e6b34d77bde03c231eb177b04110b2dcd65909a9..d1f3e88dc5ccbdadd6b46035113f605c2991503c 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -152,7 +152,7 @@ mbim_subscriber_response(void *buffer, int len)
        if (le32toh(state->readyinfo) & MBIM_READY_INFO_FLAG_PROTECT_UNIQUE_ID)
                printf("  dont display subscriberID: 1\n");
        for (nr = 0; nr < le32toh(state->telephonenumberscount); nr++) {
-               struct mbim_string *str = buffer + le32toh(state->telephonenumbers) + (nr * sizeof(struct mbim_string));
+               struct mbim_string *str = (void *)&state->telephonenumbers + (nr * sizeof(struct mbim_string));
                char *number = mbim_get_string(str, buffer);
                printf("  number: %s\n", number);
        }
@@ -216,8 +216,9 @@ static int
 mbim_config_response(void *buffer, int len)
 {
        struct mbim_basic_connect_ip_configuration_r *ip = (struct mbim_basic_connect_ip_configuration_r *) buffer;
-       char ipv4[16];
+       char out[40];
        int i;
+       uint32_t offset;
 
        if (len < sizeof(struct mbim_basic_connect_ip_configuration_r)) {
                fprintf(stderr, "message not long enough\n");
@@ -226,22 +227,39 @@ mbim_config_response(void *buffer, int len)
 
        if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
                for (i = 0; i < le32toh(ip->ipv4addresscount); i++) {
-                       mbim_get_ipv4(buffer, ipv4, ip->ipv4address + (i * 4));
-                       printf("  ipv4address: %s\n", ipv4);
+                       offset = le32toh(ip->ipv4address) + (i * 4);
+                       mbim_get_ipv4(buffer, out, 4 + offset);
+                       printf("  ipv4address: %s/%d\n", out, mbim_get_int(buffer, offset));
                }
        if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
-               mbim_get_ipv4(buffer, ipv4, ip->ipv4gateway);
-               printf("  ipv4gateway: %s\n", ipv4);
+               mbim_get_ipv4(buffer, out, le32toh(ip->ipv4gateway));
+               printf("  ipv4gateway: %s\n", out);
        }
        if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
                printf("  ipv4mtu: %d\n", le32toh(ip->ipv4mtu));
        if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
                for (i = 0; i < le32toh(ip->ipv4dnsservercount); i++) {
-                       mbim_get_ipv4(buffer, ipv4, ip->ipv4dnsserver + (i * 4));
-                       printf("  ipv4dnsserver: %s\n", ipv4);
+                       mbim_get_ipv4(buffer, out, le32toh(ip->ipv4dnsserver) + (i * 4));
+                       printf("  ipv4dnsserver: %s\n", out);
                }
 
-       printf("  ipv6configurationavailable: %04X\n", le32toh(ip->ipv6configurationavailable));
+       if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
+               for (i = 0; i < le32toh(ip->ipv6addresscount); i++) {
+                       offset = le32toh(ip->ipv6address) + (i * 16);
+                       mbim_get_ipv6(buffer, out, 4 + offset);
+                       printf("  ipv6address: %s/%d\n", out, mbim_get_int(buffer, offset));
+               }
+       if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
+               mbim_get_ipv6(buffer, out, le32toh(ip->ipv6gateway));
+               printf("  ipv6gateway: %s\n", out);
+       }
+       if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
+               printf("  ipv6mtu: %d\n", le32toh(ip->ipv6mtu));
+       if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
+               for (i = 0; i < le32toh(ip->ipv6dnsservercount); i++) {
+                       mbim_get_ipv6(buffer, out, le32toh(ip->ipv6dnsserver) + (i * 16));
+                       printf("  ipv6dnsserver: %s\n", out);
+               }
 
        return 0;
 }