aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/examples
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-01-15 21:53:17 -0900
committerDavid M. Syzdek <david@syzdek.net>2022-01-15 21:53:17 -0900
commite8d522a9fb61100d01ecaee11c1a61b8cc469eb3 (patch)
treefe998112c645fd0b5581ea7f47a6d2ec6a426533 /examples
parent9949e9a0f24596b5b816ae13ce99418b339a13d4 (diff)
downloadtinyrad-e8d522a9fb61100d01ecaee11c1a61b8cc469eb3.tar.gz
tinyrad-e8d522a9fb61100d01ecaee11c1a61b8cc469eb3.tar.bz2
tinyrad-e8d522a9fb61100d01ecaee11c1a61b8cc469eb3.tar.xz
tinyrad-e8d522a9fb61100d01ecaee11c1a61b8cc469eb3.zip
examples: resolving warnings in socket-example
Diffstat (limited to 'examples')
-rw-r--r--examples/socket-example.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/socket-example.c b/examples/socket-example.c
index 2aaa9cc..09e1d11 100644
--- a/examples/socket-example.c
+++ b/examples/socket-example.c
@@ -314,7 +314,6 @@ int main(int argc, char * argv[])
314int my_client( int s, unsigned opts, struct sockaddr_storage * sap ) 314int my_client( int s, unsigned opts, struct sockaddr_storage * sap )
315{ 315{
316 struct pollfd fds[2]; 316 struct pollfd fds[2];
317 int rc;
318 struct sockaddr_storage sa; 317 struct sockaddr_storage sa;
319 socklen_t sa_len; 318 socklen_t sa_len;
320 char buff[4096]; 319 char buff[4096];
@@ -350,7 +349,7 @@ int my_client( int s, unsigned opts, struct sockaddr_storage * sap )
350 while (!(should_exit)) 349 while (!(should_exit))
351 { 350 {
352 // check for network data 351 // check for network data
353 if ((rc = poll(fds, 2, 1000)) == -1) 352 if (poll(fds, 2, 1000) == -1)
354 { 353 {
355 if (errno == EINTR) 354 if (errno == EINTR)
356 continue; 355 continue;
@@ -401,7 +400,7 @@ int my_client( int s, unsigned opts, struct sockaddr_storage * sap )
401 }; 400 };
402 buff[len] = '\0'; 401 buff[len] = '\0';
403 my_verbose(opts, "STDIN: read %i bytes", len); 402 my_verbose(opts, "STDIN: read %i bytes", len);
404 if ((len = send(s, buff, strlen(buff), 0)) == -1) 403 if (send(s, buff, strlen(buff), 0) == -1)
405 { 404 {
406 my_error("send(): %s", strerror(errno)); 405 my_error("send(): %s", strerror(errno));
407 close(s); 406 close(s);
@@ -451,15 +450,22 @@ char * my_ntop(const struct sockaddr_storage * sa, char * buff, size_t len)
451{ 450{
452 char addrstr[INET6_ADDRSTRLEN]; 451 char addrstr[INET6_ADDRSTRLEN];
453 int port; 452 int port;
454 if (sa->ss_family == AF_INET) 453 switch(sa->ss_family)
455 { 454 {
455 case AF_INET:
456 inet_ntop(AF_INET, &((const struct sockaddr_in *)sa)->sin_addr, addrstr, sizeof(addrstr)); 456 inet_ntop(AF_INET, &((const struct sockaddr_in *)sa)->sin_addr, addrstr, sizeof(addrstr));
457 port = ntohs(((const struct sockaddr_in *)sa)->sin_port); 457 port = ntohs(((const struct sockaddr_in *)sa)->sin_port);
458 snprintf(buff, len, "%s:%i", addrstr, port); 458 snprintf(buff, len, "%s:%i", addrstr, port);
459 } else { 459 break;
460
461 case AF_INET6:
460 inet_ntop(AF_INET6, &((const struct sockaddr_in6 *)sa)->sin6_addr, addrstr, sizeof(addrstr)); 462 inet_ntop(AF_INET6, &((const struct sockaddr_in6 *)sa)->sin6_addr, addrstr, sizeof(addrstr));
461 port = ntohs(((const struct sockaddr_in6 *)sa)->sin6_port); 463 port = ntohs(((const struct sockaddr_in6 *)sa)->sin6_port);
462 snprintf(buff, len, "[%s]:%i", addrstr, port); 464 snprintf(buff, len, "[%s]:%i", addrstr, port);
465 break;
466
467 default:
468 return(NULL);
463 }; 469 };
464 buff[len-1] = '\0'; 470 buff[len-1] = '\0';
465 return(buff); 471 return(buff);