summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-28 21:30:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-30 23:35:50 +0000
commit92ffad1a72bc8c422426d52ac408bd71242dd047 (patch)
treef592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxcore/network.c
parent623e9ac331df7323660e21c8a2226523a5ee713b (diff)
Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 56f9aea0..63784475 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -82,8 +82,8 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
82 82
83 DWORD len = bufsize; 83 DWORD len = bufsize;
84 84
85 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) { 85 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
86 return NULL; 86 return nullptr;
87 } 87 }
88 88
89 return buf; 89 return buf;
@@ -96,14 +96,14 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
96 96
97 DWORD len = bufsize; 97 DWORD len = bufsize;
98 98
99 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) { 99 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
100 return NULL; 100 return nullptr;
101 } 101 }
102 102
103 return buf; 103 return buf;
104 } 104 }
105 105
106 return NULL; 106 return nullptr;
107} 107}
108 108
109static int inet_pton(Family family, const char *addrString, void *addrbuf) 109static int inet_pton(Family family, const char *addrString, void *addrbuf)
@@ -114,7 +114,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
114 114
115 INT len = sizeof(saddr); 115 INT len = sizeof(saddr);
116 116
117 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len)) { 117 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, nullptr, (LPSOCKADDR)&saddr, &len)) {
118 return 0; 118 return 0;
119 } 119 }
120 120
@@ -127,7 +127,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
127 127
128 INT len = sizeof(saddr); 128 INT len = sizeof(saddr);
129 129
130 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len)) { 130 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, nullptr, (LPSOCKADDR)&saddr, &len)) {
131 return 0; 131 return 0;
132 } 132 }
133 133
@@ -306,7 +306,7 @@ static uint64_t current_time_actual(void)
306 return time / 10; 306 return time / 10;
307#else 307#else
308 struct timeval a; 308 struct timeval a;
309 gettimeofday(&a, NULL); 309 gettimeofday(&a, nullptr);
310 time = 1000000ULL * a.tv_sec + a.tv_usec; 310 time = 1000000ULL * a.tv_sec + a.tv_usec;
311 return time; 311 return time;
312#endif 312#endif
@@ -624,7 +624,7 @@ static void at_shutdown(void)
624 */ 624 */
625Networking_Core *new_networking(Logger *log, IP ip, uint16_t port) 625Networking_Core *new_networking(Logger *log, IP ip, uint16_t port)
626{ 626{
627 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), 0); 627 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
628} 628}
629 629
630/* Initialize networking. 630/* Initialize networking.
@@ -663,17 +663,17 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
663 /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ 663 /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */
664 if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) { 664 if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) {
665 LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family); 665 LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family);
666 return NULL; 666 return nullptr;
667 } 667 }
668 668
669 if (networking_at_startup() != 0) { 669 if (networking_at_startup() != 0) {
670 return NULL; 670 return nullptr;
671 } 671 }
672 672
673 Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core)); 673 Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core));
674 674
675 if (temp == NULL) { 675 if (temp == nullptr) {
676 return NULL; 676 return nullptr;
677 } 677 }
678 678
679 temp->log = log; 679 temp->log = log;
@@ -693,7 +693,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
693 *error = 1; 693 *error = 1;
694 } 694 }
695 695
696 return NULL; 696 return nullptr;
697 } 697 }
698 698
699 /* Functions to increase the size of the send and receive UDP buffers. 699 /* Functions to increase the size of the send and receive UDP buffers.
@@ -714,7 +714,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
714 *error = 1; 714 *error = 1;
715 } 715 }
716 716
717 return NULL; 717 return nullptr;
718 } 718 }
719 719
720 /* Set socket nonblocking. */ 720 /* Set socket nonblocking. */
@@ -725,11 +725,11 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
725 *error = 1; 725 *error = 1;
726 } 726 }
727 727
728 return NULL; 728 return nullptr;
729 } 729 }
730 730
731 /* Bind our socket to port PORT and the given IP address (usually 0.0.0.0 or ::) */ 731 /* Bind our socket to port PORT and the given IP address (usually 0.0.0.0 or ::) */
732 uint16_t *portptr = NULL; 732 uint16_t *portptr = nullptr;
733 struct sockaddr_storage addr; 733 struct sockaddr_storage addr;
734 size_t addrsize; 734 size_t addrsize;
735 735
@@ -758,7 +758,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
758 portptr = &addr6->sin6_port; 758 portptr = &addr6->sin6_port;
759 } else { 759 } else {
760 free(temp); 760 free(temp);
761 return NULL; 761 return nullptr;
762 } 762 }
763 763
764 if (ip.family == TOX_AF_INET6) { 764 if (ip.family == TOX_AF_INET6) {
@@ -841,7 +841,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
841 *error = 1; 841 *error = 1;
842 } 842 }
843 843
844 return NULL; 844 return nullptr;
845} 845}
846 846
847Networking_Core *new_networking_no_udp(Logger *log) 847Networking_Core *new_networking_no_udp(Logger *log)
@@ -849,8 +849,8 @@ Networking_Core *new_networking_no_udp(Logger *log)
849 /* this is the easiest way to completely disable UDP without changing too much code. */ 849 /* this is the easiest way to completely disable UDP without changing too much code. */
850 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); 850 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core));
851 851
852 if (net == NULL) { 852 if (net == nullptr) {
853 return NULL; 853 return nullptr;
854 } 854 }
855 855
856 net->log = log; 856 net->log = log;
@@ -1076,12 +1076,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length)
1076 1076
1077 if (ip->family == TOX_AF_INET) { 1077 if (ip->family == TOX_AF_INET) {
1078 const struct in_addr *addr = (const struct in_addr *)&ip->ip4; 1078 const struct in_addr *addr = (const struct in_addr *)&ip->ip4;
1079 return inet_ntop(ip->family, addr, address, length) != NULL; 1079 return inet_ntop(ip->family, addr, address, length) != nullptr;
1080 } 1080 }
1081 1081
1082 if (ip->family == TOX_AF_INET6) { 1082 if (ip->family == TOX_AF_INET6) {
1083 const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; 1083 const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6;
1084 return inet_ntop(ip->family, addr, address, length) != NULL; 1084 return inet_ntop(ip->family, addr, address, length) != nullptr;
1085 } 1085 }
1086 1086
1087 return 0; 1087 return 0;
@@ -1151,8 +1151,8 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1151 Family tox_family = to->family; 1151 Family tox_family = to->family;
1152 Family family = make_family(tox_family); 1152 Family family = make_family(tox_family);
1153 1153
1154 struct addrinfo *server = NULL; 1154 struct addrinfo *server = nullptr;
1155 struct addrinfo *walker = NULL; 1155 struct addrinfo *walker = nullptr;
1156 struct addrinfo hints; 1156 struct addrinfo hints;
1157 int rc; 1157 int rc;
1158 int result = 0; 1158 int result = 0;
@@ -1166,7 +1166,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1166 return 0; 1166 return 0;
1167 } 1167 }
1168 1168
1169 rc = getaddrinfo(address, NULL, &hints, &server); 1169 rc = getaddrinfo(address, nullptr, &hints, &server);
1170 1170
1171 // Lookup failed. 1171 // Lookup failed.
1172 if (rc != 0) { 1172 if (rc != 0) {
@@ -1178,7 +1178,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1178 IP ip6; 1178 IP ip6;
1179 ip_init(&ip6, 1); // ipv6enabled = 1 1179 ip_init(&ip6, 1); // ipv6enabled = 1
1180 1180
1181 for (walker = server; (walker != NULL) && !done; walker = walker->ai_next) { 1181 for (walker = server; (walker != nullptr) && !done; walker = walker->ai_next) {
1182 switch (walker->ai_family) { 1182 switch (walker->ai_family) {
1183 case AF_INET: 1183 case AF_INET:
1184 if (walker->ai_family == family) { /* AF_INET requested, done */ 1184 if (walker->ai_family == family) { /* AF_INET requested, done */
@@ -1218,7 +1218,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1218 if (result & TOX_ADDR_RESOLVE_INET6) { 1218 if (result & TOX_ADDR_RESOLVE_INET6) {
1219 ip_copy(to, &ip6); 1219 ip_copy(to, &ip6);
1220 1220
1221 if ((result & TOX_ADDR_RESOLVE_INET) && (extra != NULL)) { 1221 if ((result & TOX_ADDR_RESOLVE_INET) && (extra != nullptr)) {
1222 ip_copy(extra, &ip4); 1222 ip_copy(extra, &ip4);
1223 } 1223 }
1224 } else if (result & TOX_ADDR_RESOLVE_INET) { 1224 } else if (result & TOX_ADDR_RESOLVE_INET) {
@@ -1287,8 +1287,8 @@ int net_connect(Socket sock, IP_Port ip_port)
1287int32_t net_getipport(const char *node, IP_Port **res, int tox_type) 1287int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1288{ 1288{
1289 struct addrinfo *infos; 1289 struct addrinfo *infos;
1290 int ret = getaddrinfo(node, NULL, NULL, &infos); 1290 int ret = getaddrinfo(node, nullptr, nullptr, &infos);
1291 *res = NULL; 1291 *res = nullptr;
1292 1292
1293 if (ret != 0) { 1293 if (ret != 0) {
1294 return -1; 1294 return -1;
@@ -1300,7 +1300,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1300 struct addrinfo *cur; 1300 struct addrinfo *cur;
1301 int32_t count = 0; 1301 int32_t count = 0;
1302 1302
1303 for (cur = infos; count < MAX_COUNT && cur != NULL; cur = cur->ai_next) { 1303 for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) {
1304 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { 1304 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
1305 continue; 1305 continue;
1306 } 1306 }
@@ -1321,14 +1321,14 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1321 1321
1322 *res = (IP_Port *)malloc(sizeof(IP_Port) * count); 1322 *res = (IP_Port *)malloc(sizeof(IP_Port) * count);
1323 1323
1324 if (*res == NULL) { 1324 if (*res == nullptr) {
1325 freeaddrinfo(infos); 1325 freeaddrinfo(infos);
1326 return -1; 1326 return -1;
1327 } 1327 }
1328 1328
1329 IP_Port *ip_port = *res; 1329 IP_Port *ip_port = *res;
1330 1330
1331 for (cur = infos; cur != NULL; cur = cur->ai_next) { 1331 for (cur = infos; cur != nullptr; cur = cur->ai_next) {
1332 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { 1332 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
1333 continue; 1333 continue;
1334 } 1334 }