--- sbbs/src/xpdev/sockwrap.c 2018/04/24 16:41:24 1.1 +++ sbbs/src/xpdev/sockwrap.c 2018/04/24 16:45:26 1.1.1.2 @@ -2,13 +2,13 @@ /* Berkley/WinSock socket API wrappers */ -/* $Id: sockwrap.c,v 1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: sockwrap.c,v 1.1.1.2 2018/04/24 16:45:26 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -35,6 +35,7 @@ * Note: If this box doesn't appear square, then you need to fix your tabs. * ****************************************************************************/ +#include /* isdigit */ #include /* alloca/free on FreeBSD */ #include /* bzero (for FD_ZERO) on FreeBSD */ #include /* ENOMEM */ @@ -68,6 +69,9 @@ static socket_option_t socket_options[] #endif { "REUSEADDR", 0, SOL_SOCKET, SO_REUSEADDR }, +#ifdef SO_REUSEPORT /* BSD */ + { "REUSEPORT", 0, SOL_SOCKET, SO_REUSEPORT }, +#endif { "KEEPALIVE", SOCK_STREAM, SOL_SOCKET, SO_KEEPALIVE }, { "DONTROUTE", 0, SOL_SOCKET, SO_DONTROUTE }, { "BROADCAST", SOCK_DGRAM, SOL_SOCKET, SO_BROADCAST }, @@ -160,14 +164,14 @@ socket_option_t* getSocketOptionList(voi return(socket_options); } -int sendfilesocket(int sock, int file, long *offset, long count) +int sendfilesocket(int sock, int file, off_t *offset, off_t count) { - char buf[1024*16]; - long len; - int rd; - int wr=0; - int total=0; - int i; + char buf[1024*16]; + off_t len; + int rd; + int wr=0; + int total=0; + int i; /* sendfile() on Linux may or may not work with non-blocking sockets ToDo */ len=filelength(file); @@ -222,7 +226,7 @@ int sendfilesocket(int sock, int file, l return(total); } -int recvfilesocket(int sock, int file, long *offset, long count) +int recvfilesocket(int sock, int file, off_t *offset, off_t count) { /* Writes a file from a socket - * @@ -248,7 +252,7 @@ int recvfilesocket(int sock, int file, l return(-1); } - if((buf=(char*)alloca(count))==NULL) { + if((buf=(char*)alloca((size_t)count))==NULL) { errno=ENOMEM; return(-1); } @@ -257,7 +261,7 @@ int recvfilesocket(int sock, int file, l if(lseek(file,*offset,SEEK_SET)<0) return(-1); - rd=read(sock,buf,count); + rd=read(sock,buf,(size_t)count); if(rd!=count) return(-1); @@ -333,7 +337,7 @@ BOOL socket_check(SOCKET sock, BOOL* rd_ int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen ,uint retries, uint wait_secs ,const char* prot - ,int (*lprintf)(int level, char *fmt, ...)) + ,int (*lprintf)(int level, const char *fmt, ...)) { char port_str[128]; int result=-1; @@ -347,7 +351,7 @@ int retry_bind(SOCKET s, const struct so if((result=bind(s,addr,addrlen))==0) break; if(lprintf!=NULL) - lprintf(i