~connman-maintainers/connman/head

« back to all changes in this revision

Viewing changes to src/inet.c

  • Committer: Patrik Flykt
  • Author(s): Daniel Wagner
  • Date: 2013-08-07 06:46:54 UTC
  • Revision ID: git-v1:bd99aaa74d1c627d43353ed0ae77b72e1e2bc8e6
core: Do not compare expression against NULL

This patch generate via coccinelle with:

@ disable is_null,isnt_null1 @
expression E;
@@

(
- E == NULL
+ !E
|
- E != NULL
+ E
)

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
                "prefixlen %hhu broadcast %s", cmd, flags, index, family,
99
99
                address, peer, prefixlen, broadcast);
100
100
 
101
 
        if (address == NULL)
 
101
        if (!address)
102
102
                return -EINVAL;
103
103
 
104
104
        if (family != AF_INET && family != AF_INET6)
123
123
                if (inet_pton(AF_INET, address, &ipv4_addr) < 1)
124
124
                        return -1;
125
125
 
126
 
                if (broadcast != NULL)
 
126
                if (broadcast)
127
127
                        inet_pton(AF_INET, broadcast, &ipv4_bcast);
128
128
                else
129
129
                        ipv4_bcast.s_addr = ipv4_addr.s_addr |
130
130
                                htonl(0xfffffffflu >> prefixlen);
131
131
 
132
 
                if (peer != NULL) {
 
132
                if (peer) {
133
133
                        if (inet_pton(AF_INET, peer, &ipv4_dest) < 1)
134
134
                                return -1;
135
135
 
195
195
        struct ifreq ifr;
196
196
        int sk, err;
197
197
 
198
 
        if (name == NULL)
 
198
        if (!name)
199
199
                return -1;
200
200
 
201
201
        sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
403
403
        unsigned char prefix_len;
404
404
        const char *address;
405
405
 
406
 
        if (ipaddress->local == NULL)
 
406
        if (!ipaddress->local)
407
407
                return 0;
408
408
 
409
409
        prefix_len = ipaddress->prefixlen;
428
428
        unsigned char prefix_len;
429
429
        const char *address, *broadcast, *peer;
430
430
 
431
 
        if (ipaddress->local == NULL)
 
431
        if (!ipaddress->local)
432
432
                return -1;
433
433
 
434
434
        prefix_len = ipaddress->prefixlen;
456
456
 
457
457
        DBG("index %d address %s prefix_len %d", index, address, prefix_len);
458
458
 
459
 
        if (address == NULL)
 
459
        if (!address)
460
460
                return -EINVAL;
461
461
 
462
462
        err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET6,
482
482
 
483
483
        DBG("index %d address %s prefix_len %d", index, address, prefix_len);
484
484
 
485
 
        if (address == NULL)
 
485
        if (!address)
486
486
                return -EINVAL;
487
487
 
488
488
        err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET,
537
537
 
538
538
        memset(&rt, 0, sizeof(rt));
539
539
        rt.rt_flags = RTF_UP;
540
 
        if (gateway != NULL)
 
540
        if (gateway)
541
541
                rt.rt_flags |= RTF_GATEWAY;
542
 
        if (netmask == NULL)
 
542
        if (!netmask)
543
543
                rt.rt_flags |= RTF_HOST;
544
544
 
545
545
        memset(&addr, 0, sizeof(addr));
549
549
 
550
550
        memset(&addr, 0, sizeof(addr));
551
551
        addr.sin_family = AF_INET;
552
 
        if (gateway != NULL)
 
552
        if (gateway)
553
553
                addr.sin_addr.s_addr = inet_addr(gateway);
554
554
        else
555
555
                addr.sin_addr.s_addr = INADDR_ANY;
558
558
        memset(&addr, 0, sizeof(addr));
559
559
        addr.sin_family = AF_INET;
560
560
        addr.sin_addr.s_addr = INADDR_ANY;
561
 
        if (netmask != NULL)
 
561
        if (netmask)
562
562
                addr.sin_addr.s_addr = inet_addr(netmask);
563
563
        else
564
564
                addr.sin_addr.s_addr = INADDR_ANY;
636
636
 
637
637
        DBG("index %d host %s", index, host);
638
638
 
639
 
        if (host == NULL)
 
639
        if (!host)
640
640
                return -EINVAL;
641
641
 
642
642
        memset(&rt, 0, sizeof(rt));
686
686
 
687
687
        DBG("index %d host %s gateway %s", index, host, gateway);
688
688
 
689
 
        if (host == NULL)
 
689
        if (!host)
690
690
                return -EINVAL;
691
691
 
692
692
        memset(&rt, 0, sizeof(rt));
700
700
 
701
701
        rt.rtmsg_flags = RTF_UP | RTF_HOST;
702
702
 
703
 
        if (gateway != NULL) {
 
703
        if (gateway) {
704
704
                rt.rtmsg_flags |= RTF_GATEWAY;
705
705
                inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway);
706
706
        }
740
740
 
741
741
        DBG("index %d gateway %s", index, gateway);
742
742
 
743
 
        if (gateway == NULL)
 
743
        if (!gateway)
744
744
                return -EINVAL;
745
745
 
746
746
        memset(&rt, 0, sizeof(rt));
1051
1051
 
1052
1052
        DBG("host %s", host);
1053
1053
 
1054
 
        if (host == NULL)
 
1054
        if (!host)
1055
1055
                return false;
1056
1056
 
1057
1057
        if (inet_aton(host, &_host_addr) == 0)
1096
1096
        struct ifreq ifr;
1097
1097
        int sk, err = 0;
1098
1098
 
1099
 
        if (bridge == NULL)
 
1099
        if (!bridge)
1100
1100
                return -EINVAL;
1101
1101
 
1102
1102
        sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
1127
1127
        struct ifreq ifr;
1128
1128
        int sk, err = 0;
1129
1129
 
1130
 
        if (bridge == NULL)
 
1130
        if (!bridge)
1131
1131
                return -EINVAL;
1132
1132
 
1133
1133
        sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
1182
1182
        __u32 mask;
1183
1183
        __u32 flags;
1184
1184
 
1185
 
        if (tunnel == NULL)
 
1185
        if (!tunnel)
1186
1186
                return -EINVAL;
1187
1187
 
1188
1188
        sk = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1273
1273
 
1274
1274
static void rs_cleanup(struct rs_cb_data *data)
1275
1275
{
1276
 
        if (data->channel != NULL) {
 
1276
        if (data->channel) {
1277
1277
                g_io_channel_shutdown(data->channel, TRUE, NULL);
1278
1278
                g_io_channel_unref(data->channel);
1279
1279
                data->channel = NULL;
1294
1294
 
1295
1295
        DBG("user data %p", user_data);
1296
1296
 
1297
 
        if (data == NULL)
 
1297
        if (!data)
1298
1298
                return FALSE;
1299
1299
 
1300
 
        if (data->callback != NULL)
 
1300
        if (data->callback)
1301
1301
                ((__connman_inet_rs_cb_t)(data->callback))(NULL, 0,
1302
1302
                                                        data->user_data);
1303
1303
 
1389
1389
                count -= 2;
1390
1390
        }
1391
1391
 
1392
 
        if (extra_data != NULL) {
 
1392
        if (extra_data) {
1393
1393
                count = extra_datalen;
1394
1394
                addr = (uint16_t *)extra_data;
1395
1395
 
1454
1454
 
1455
1455
        dst.sin6_addr = *dest;
1456
1456
 
1457
 
        if (source != NULL)
 
1457
        if (source)
1458
1458
                src.sin6_addr = *source;
1459
1459
        else
1460
1460
                src.sin6_addr = in6addr_any;
1482
1482
        iov[0].iov_base = &frame;
1483
1483
        iov[0].iov_len = sizeof(frame.ip) + datalen;
1484
1484
 
1485
 
        if (buf != NULL) {
 
1485
        if (buf) {
1486
1486
                iov[1].iov_base = buf;
1487
1487
                iov[1].iov_len = len;
1488
1488
                iovlen = 2;
1572
1572
                return -EINVAL;
1573
1573
 
1574
1574
        data = g_try_malloc0(sizeof(struct rs_cb_data));
1575
 
        if (data == NULL)
 
1575
        if (!data)
1576
1576
                return -ENOMEM;
1577
1577
 
1578
1578
        data->callback = callback;
1640
1640
        int sk, err = 0;
1641
1641
        int len, count = 0;
1642
1642
 
1643
 
        if (prefixes == NULL)
 
1643
        if (!prefixes)
1644
1644
                return -EINVAL;
1645
1645
 
1646
1646
        sk = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
1647
1647
        if (sk < 0)
1648
1648
                return -errno;
1649
1649
 
1650
 
        if (src_addr == NULL) {
 
1650
        if (!src_addr) {
1651
1651
                __connman_inet_get_interface_ll_address(index, AF_INET6, &src);
1652
1652
                source = &src;
1653
1653
        } else
1709
1709
 
1710
1710
void __connman_inet_ipv6_stop_recv_rs(void *context)
1711
1711
{
1712
 
        if (context == NULL)
 
1712
        if (!context)
1713
1713
                return;
1714
1714
 
1715
1715
        rs_cleanup(context);
1785
1785
        int sk, err;
1786
1786
 
1787
1787
        data = g_try_malloc0(sizeof(struct rs_cb_data));
1788
 
        if (data == NULL)
 
1788
        if (!data)
1789
1789
                return -ENOMEM;
1790
1790
 
1791
1791
        data->callback = callback;
1857
1857
                        pinfo = (struct nd_opt_prefix_info *)pos;
1858
1858
                        prefix = inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1859
1859
                                        prefix_str, INET6_ADDRSTRLEN);
1860
 
                        if (prefix == NULL)
 
1860
                        if (!prefix)
1861
1861
                                break;
1862
1862
 
1863
1863
                        str = g_strdup_printf("%s/%d", prefix,
1930
1930
                return -errno;
1931
1931
        }
1932
1932
 
1933
 
        if (inet_ntop(family, addr, buf, len) == NULL) {
 
1933
        if (!inet_ntop(family, addr, buf, len)) {
1934
1934
                DBG("error %d/%s", errno, strerror(errno));
1935
1935
                return -errno;
1936
1936
        }
2025
2025
{
2026
2026
        struct __connman_inet_rtnl_handle *rth = data->rtnl;
2027
2027
 
2028
 
        if (data->channel != NULL) {
 
2028
        if (data->channel) {
2029
2029
                g_io_channel_shutdown(data->channel, TRUE, NULL);
2030
2030
                g_io_channel_unref(data->channel);
2031
2031
                data->channel = NULL;
2039
2039
        if (data->watch_id > 0)
2040
2040
                g_source_remove(data->watch_id);
2041
2041
 
2042
 
        if (rth != NULL) {
 
2042
        if (rth) {
2043
2043
                __connman_inet_rtnl_close(rth);
2044
2044
                g_free(rth);
2045
2045
        }
2053
2053
 
2054
2054
        DBG("user data %p", user_data);
2055
2055
 
2056
 
        if (data == NULL)
 
2056
        if (!data)
2057
2057
                return FALSE;
2058
2058
 
2059
 
        if (data->callback != NULL)
 
2059
        if (data->callback)
2060
2060
                data->callback(NULL, data->user_data);
2061
2061
 
2062
2062
        data->rtnl_timeout = 0;
2177
2177
 
2178
2178
        n->nlmsg_seq = seq = ++rtnl->seq;
2179
2179
 
2180
 
        if (callback != NULL) {
 
2180
        if (callback) {
2181
2181
                data = g_try_malloc0(sizeof(struct inet_rtnl_cb_data));
2182
 
                if (data == NULL)
 
2182
                if (!data)
2183
2183
                        return -ENOMEM;
2184
2184
 
2185
2185
                data->callback = callback;
2276
2276
 
2277
2277
        DBG("answer %p data %p", answer, user_data);
2278
2278
 
2279
 
        if (answer == NULL)
 
2279
        if (!answer)
2280
2280
                goto out;
2281
2281
 
2282
2282
        len = answer->nlmsg_len;
2297
2297
 
2298
2298
        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
2299
2299
 
2300
 
        if (tb[RTA_OIF] != NULL)
 
2300
        if (tb[RTA_OIF])
2301
2301
                index = *(int *)RTA_DATA(tb[RTA_OIF]);
2302
2302
 
2303
 
        if (tb[RTA_GATEWAY] != NULL)
 
2303
        if (tb[RTA_GATEWAY])
2304
2304
                addr = inet_ntop(r->rtm_family,
2305
2305
                                RTA_DATA(tb[RTA_GATEWAY]),
2306
2306
                                abuf, sizeof(abuf));
2308
2308
        DBG("addr %s index %d user %p", addr, index, data->user_data);
2309
2309
 
2310
2310
out:
2311
 
        if (data != NULL && data->callback != NULL)
 
2311
        if (data && data->callback)
2312
2312
                data->callback(addr, index, data->user_data);
2313
2313
 
2314
2314
        g_free(data);
2329
2329
 
2330
2330
        DBG("dest %s", dest_address);
2331
2331
 
2332
 
        if (dest_address == NULL)
 
2332
        if (!dest_address)
2333
2333
                return -EINVAL;
2334
2334
 
2335
2335
        memset(&hints, 0, sizeof(hints));
2341
2341
                return -EINVAL;
2342
2342
 
2343
2343
        rth = g_try_malloc0(sizeof(struct __connman_inet_rtnl_handle));
2344
 
        if (rth == NULL) {
 
2344
        if (!rth) {
2345
2345
                freeaddrinfo(rp);
2346
2346
                return -ENOMEM;
2347
2347
        }
2368
2368
                goto fail;
2369
2369
 
2370
2370
        data = g_try_malloc(sizeof(struct get_route_cb_data));
2371
 
        if (data == NULL) {
 
2371
        if (!data) {
2372
2372
                err = -ENOMEM;
2373
2373
                goto done;
2374
2374
        }
2481
2481
         * calls.
2482
2482
         */
2483
2483
        ifr = g_try_malloc0(ifc.ifc_len * 2);
2484
 
        if (ifr == NULL)
 
2484
        if (!ifr)
2485
2485
                goto error;
2486
2486
 
2487
2487
        ifc.ifc_req = ifr;
2492
2492
        numif = ifc.ifc_len / sizeof(struct ifreq);
2493
2493
 
2494
2494
        result = g_try_malloc0((numif + 1) * sizeof(char *));
2495
 
        if (result == NULL)
 
2495
        if (!result)
2496
2496
                goto error;
2497
2497
 
2498
2498
        close(sk);
2555
2555
        int err = -ENOENT;
2556
2556
        char name[IF_NAMESIZE];
2557
2557
 
2558
 
        if (if_indextoname(index, name) == NULL)
 
2558
        if (!if_indextoname(index, name))
2559
2559
                return -EINVAL;
2560
2560
 
2561
2561
        DBG("index %d interface %s", index, name);
2566
2566
                return err;
2567
2567
        }
2568
2568
 
2569
 
        for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
2570
 
                if (ifa->ifa_addr == NULL)
 
2569
        for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
 
2570
                if (!ifa->ifa_addr)
2571
2571
                        continue;
2572
2572
 
2573
2573
                if (strncmp(ifa->ifa_name, name, IF_NAMESIZE) == 0 &&
2747
2747
        int err = -ENOENT;
2748
2748
        char name[IF_NAMESIZE];
2749
2749
 
2750
 
        if (if_indextoname(index, name) == NULL)
 
2750
        if (!if_indextoname(index, name))
2751
2751
                return -EINVAL;
2752
2752
 
2753
2753
        DBG("index %d interface %s", index, name);
2758
2758
                return err;
2759
2759
        }
2760
2760
 
2761
 
        for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
2762
 
                if (ifa->ifa_addr == NULL)
 
2761
        for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
 
2762
                if (!ifa->ifa_addr)
2763
2763
                        continue;
2764
2764
 
2765
2765
                if (strncmp(ifa->ifa_name, name, IF_NAMESIZE) == 0 &&