From 5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Tue, 9 Jul 2024 14:41:53 +0200 Subject: initial clang-format --- src/socket_setup.c | 73 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'src/socket_setup.c') diff --git a/src/socket_setup.c b/src/socket_setup.c index fb65fa2..39fc3dd 100644 --- a/src/socket_setup.c +++ b/src/socket_setup.c @@ -1,10 +1,11 @@ -#include +#include #include #include -#include +#include + #include "byte.h" -#include "socket_if.h" #include "ip.h" +#include "socket_if.h" /** @file socket_setup.c @@ -13,57 +14,57 @@ @brief setup listening socket */ -int socket_accept(int s,char ip[16],uint16 *port,uint32 *scope_id) +int socket_accept(int s, char ip[16], uint16 *port, uint32 *scope_id) { struct sockaddr_in6 sa; unsigned int dummy = sizeof(sa); int fd; - fd = accept(s,(struct sockaddr *)&sa,&dummy); + fd = accept(s, (struct sockaddr *)&sa, &dummy); if (fd == -1) return -1; if (sa.sin6_family == AF_INET) { - struct sockaddr_in *sa4 = (struct sockaddr_in*)&sa; - byte_copy(ip,12,V4mappedprefix); - byte_copy(ip+12,4,(char *)&sa4->sin_addr); - uint16_unpack_big((char *)&sa4->sin_port,port); + struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa; + byte_copy(ip, 12, V4mappedprefix); + byte_copy(ip + 12, 4, (char *)&sa4->sin_addr); + uint16_unpack_big((char *)&sa4->sin_port, port); if (scope_id) *scope_id = 0; } else { - byte_copy(ip,16,(char *)&sa.sin6_addr); - uint16_unpack_big((char *)&sa.sin6_port,port); + byte_copy(ip, 16, (char *)&sa.sin6_addr); + uint16_unpack_big((char *)&sa.sin6_port, port); if (scope_id) *scope_id = sa.sin6_scope_id; - } + } return fd; } -int socket_accept4(int s,char ip[4],uint16 *port) +int socket_accept4(int s, char ip[4], uint16 *port) { - struct sockaddr_in sa; - unsigned int dummy = sizeof(sa); - int fd; + struct sockaddr_in sa; + unsigned int dummy = sizeof(sa); + int fd; - fd = accept(s,(struct sockaddr *) &sa,&dummy); - if (fd == -1) return -1; + fd = accept(s, (struct sockaddr *)&sa, &dummy); + if (fd == -1) return -1; - byte_copy(ip,4,(char *) &sa.sin_addr); - uint16_unpack_big((char *) &sa.sin_port,port); + byte_copy(ip, 4, (char *)&sa.sin_addr); + uint16_unpack_big((char *)&sa.sin_port, port); - return fd; + return fd; } -int socket_listen(int s,int backlog) +int socket_listen(int s, int backlog) { - return listen(s,backlog); + return listen(s, backlog); } int socket_ipoptionskill(int s) { int r; - r = setsockopt(s,IPPROTO_IP,1,(char *) 0,0); /* 1 == IP_OPTIONS */ - r = setsockopt(s,IPPROTO_IPV6,1,(char *) 0,0); - + r = setsockopt(s, IPPROTO_IP, 1, (char *)0, 0); /* 1 == IP_OPTIONS */ + r = setsockopt(s, IPPROTO_IPV6, 1, (char *)0, 0); + return r; } @@ -73,27 +74,27 @@ int socket_ip6anycast(int s) int r; #ifdef GEN_IP_PKTINFO /* Linux */ - r = setsockopt(s,IPPROTO_IP,GEN_IP_PKTINFO,&opt,sizeof(opt)); -#elif IP_PKTINFO /* Solaris */ - r = setsockopt(s,IPPROTO_IP,IP_PKTINFO,&opt,sizeof(opt)); -#elif IP_RECVDSTADDR /* BSD */ - r = setsockopt(s,IPPROTO_IP,IP_RECVDSTADDR,&opt,sizeof(opt)); + r = setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &opt, sizeof(opt)); +#elif IP_PKTINFO /* Solaris */ + r = setsockopt(s, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)); +#elif IP_RECVDSTADDR /* BSD */ + r = setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt)); #elif IPV6_RECVDSTADDR - r = setsockopt(s,IPPROTO_IPV6,IP_RECVDSTADDR,&opt,sizeof(opt)); + r = setsockopt(s, IPPROTO_IPV6, IP_RECVDSTADDR, &opt, sizeof(opt)); #endif - return r; -} + return r; +} int socket_dualstack(int s) { int opt = 0; - return setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,&opt,sizeof(opt)); + return setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)); } int socket_nodualstack(int s) { int opt = 1; - return setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,&opt,sizeof(opt)); + return setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)); } -- cgit v1.2.3