now that gcc 11's static analyzer looks at array bounds in arguments
like "char ip[4]", let's be more strict about that
This commit is contained in:
parent
07c3f0bf3d
commit
1217583e2b
16
dns.h
16
dns.h
@ -45,7 +45,7 @@ struct dns_transmit {
|
|||||||
char qtype[2];
|
char qtype[2];
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
void dns_random_init(const char *);
|
void dns_random_init(const char data[128]);
|
||||||
unsigned int dns_random(unsigned int);
|
unsigned int dns_random(unsigned int);
|
||||||
|
|
||||||
void dns_sortip(char *,unsigned int);
|
void dns_sortip(char *,unsigned int);
|
||||||
@ -64,13 +64,13 @@ unsigned int dns_packet_copy(const char *,unsigned int,unsigned int,char *,unsig
|
|||||||
unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
|
unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
|
||||||
unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
|
unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
|
||||||
|
|
||||||
int dns_transmit_start(struct dns_transmit *,const char *,int,const char *,const char *,const char *);
|
int dns_transmit_start(struct dns_transmit *,const char servers[256],int,const char *q,const char qtype[2],const char localip[16]);
|
||||||
void dns_transmit_free(struct dns_transmit *);
|
void dns_transmit_free(struct dns_transmit *);
|
||||||
void dns_transmit_io(struct dns_transmit *,iopause_fd *,struct taia *);
|
void dns_transmit_io(struct dns_transmit *,iopause_fd *,struct taia *);
|
||||||
int dns_transmit_get(struct dns_transmit *,const iopause_fd *,const struct taia *);
|
int dns_transmit_get(struct dns_transmit *,const iopause_fd *,const struct taia *);
|
||||||
|
|
||||||
int dns_resolvconfip(char *);
|
int dns_resolvconfip(char servers[256]);
|
||||||
int dns_resolve(const char *,const char *);
|
int dns_resolve(const char *q,const char qtype[2]);
|
||||||
extern struct dns_transmit dns_resolve_tx;
|
extern struct dns_transmit dns_resolve_tx;
|
||||||
|
|
||||||
int dns_ip4_packet(stralloc *,const char *,unsigned int);
|
int dns_ip4_packet(stralloc *,const char *,unsigned int);
|
||||||
@ -78,9 +78,9 @@ int dns_ip4(stralloc *,const stralloc *);
|
|||||||
int dns_ip6_packet(stralloc *,const char *,unsigned int);
|
int dns_ip6_packet(stralloc *,const char *,unsigned int);
|
||||||
int dns_ip6(stralloc *,stralloc *);
|
int dns_ip6(stralloc *,stralloc *);
|
||||||
int dns_name_packet(stralloc *,const char *,unsigned int);
|
int dns_name_packet(stralloc *,const char *,unsigned int);
|
||||||
void dns_name4_domain(char *,const char *);
|
|
||||||
#define DNS_NAME4_DOMAIN 31
|
#define DNS_NAME4_DOMAIN 31
|
||||||
int dns_name4(stralloc *,const char *);
|
void dns_name4_domain(char name[DNS_NAME4_DOMAIN],const char ip[4]);
|
||||||
|
int dns_name4(stralloc *,const char ip[4]);
|
||||||
int dns_txt_packet(stralloc *,const char *,unsigned int);
|
int dns_txt_packet(stralloc *,const char *,unsigned int);
|
||||||
int dns_txt(stralloc *,const stralloc *);
|
int dns_txt(stralloc *,const stralloc *);
|
||||||
int dns_mx_packet(stralloc *,const char *,unsigned int);
|
int dns_mx_packet(stralloc *,const char *,unsigned int);
|
||||||
@ -92,9 +92,9 @@ int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
|
|||||||
int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
|
int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
|
||||||
int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
|
int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
|
||||||
|
|
||||||
void dns_name6_domain(char *,const char *);
|
|
||||||
#define DNS_NAME6_DOMAIN (4*16+11)
|
#define DNS_NAME6_DOMAIN (4*16+11)
|
||||||
int dns_name6(stralloc *,const char *);
|
void dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16]);
|
||||||
|
int dns_name6(stralloc *,const char ip[16]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
4
ip4.h
4
ip4.h
@ -6,8 +6,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t scan_ip4(const char *src,char *ip);
|
size_t scan_ip4(const char *src,char ip[4]);
|
||||||
size_t fmt_ip4(char *dest,const char *ip);
|
size_t fmt_ip4(char *dest,const char ip[4]);
|
||||||
|
|
||||||
/* for djb backwards compatibility */
|
/* for djb backwards compatibility */
|
||||||
#define ip4_scan scan_ip4
|
#define ip4_scan scan_ip4
|
||||||
|
16
ip6.h
16
ip6.h
@ -9,16 +9,16 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t scan_ip6(const char* src,char* ip);
|
size_t scan_ip6(const char* src,char ip[16]);
|
||||||
size_t fmt_ip6(char* dest,const char* ip);
|
size_t fmt_ip6(char* dest,const char ip[16]);
|
||||||
size_t fmt_ip6c(char* dest,const char* ip);
|
size_t fmt_ip6c(char* dest,const char ip[16]);
|
||||||
|
|
||||||
size_t scan_ip6if(const char* src,char* ip,uint32* scope_id);
|
size_t scan_ip6if(const char* src,char ip[16],uint32* scope_id);
|
||||||
size_t fmt_ip6if(char* dest,const char* ip,uint32 scope_id);
|
size_t fmt_ip6if(char* dest,const char ip[16],uint32 scope_id);
|
||||||
size_t fmt_ip6ifc(char* dest,const char* ip,uint32 scope_id);
|
size_t fmt_ip6ifc(char* dest,const char ip[16],uint32 scope_id);
|
||||||
|
|
||||||
size_t scan_ip6_flat(const char *src,char *);
|
size_t scan_ip6_flat(const char *src,char ip[16]);
|
||||||
size_t fmt_ip6_flat(char *dest,const char *);
|
size_t fmt_ip6_flat(char *dest,const char ip[16]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ip6 address syntax: (h = hex digit), no leading '0' required
|
ip6 address syntax: (h = hex digit), no leading '0' required
|
||||||
|
66
socket.h
66
socket.h
@ -29,22 +29,22 @@ int socket_sctp6b(void);
|
|||||||
#define socket_tcp() socket_tcp4()
|
#define socket_tcp() socket_tcp4()
|
||||||
#define socket_udp() socket_udp4()
|
#define socket_udp() socket_udp4()
|
||||||
|
|
||||||
int socket_connect4(int s,const char* ip,uint16 port);
|
int socket_connect4(int s,const char ip[4],uint16 port);
|
||||||
int socket_connect6(int s,const char* ip,uint16 port,uint32 scope_id);
|
int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id);
|
||||||
int socket_connected(int s);
|
int socket_connected(int s);
|
||||||
int socket_bind4(int s,const char* ip,uint16 port);
|
int socket_bind4(int s,const char ip[4],uint16 port);
|
||||||
int socket_bind4_reuse(int s,const char* ip,uint16 port);
|
int socket_bind4_reuse(int s,const char ip[4],uint16 port);
|
||||||
int socket_bind6(int s,const char* ip,uint16 port,uint32 scope_id);
|
int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id);
|
||||||
int socket_bind6_reuse(int s,const char* ip,uint16 port,uint32 scope_id);
|
int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id);
|
||||||
int socket_listen(int s,unsigned int backlog);
|
int socket_listen(int s,unsigned int backlog);
|
||||||
int socket_accept4(int s,char* ip,uint16* port);
|
int socket_accept4(int s,char ip[4],uint16* port);
|
||||||
int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_accept6(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
int socket_accept4_makenonblocking(int s,char* ip,uint16* port);
|
int socket_accept4_makenonblocking(int s,char ip[4],uint16* port);
|
||||||
int socket_accept6_makenonblocking(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_accept6_makenonblocking(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
int socket_accept4_setcloseonexec(int s,char* ip,uint16* port);
|
int socket_accept4_setcloseonexec(int s,char ip[4],uint16* port);
|
||||||
int socket_accept6_setcloseonexec(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_accept6_setcloseonexec(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
int socket_accept4_makenonblocking_setcloseonexec(int s,char* ip,uint16* port);
|
int socket_accept4_makenonblocking_setcloseonexec(int s,char ip[4],uint16* port);
|
||||||
int socket_accept6_makenonblocking_setcloseonexec(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_accept6_makenonblocking_setcloseonexec(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
|
|
||||||
/* These are internal wrappers around accept4, not meant for external use.
|
/* These are internal wrappers around accept4, not meant for external use.
|
||||||
* flags can be SOCKET_NONBLOCK or SOCKET_CLOEXEC or both */
|
* flags can be SOCKET_NONBLOCK or SOCKET_CLOEXEC or both */
|
||||||
@ -52,36 +52,36 @@ enum {
|
|||||||
SOCKET_NONBLOCK=1,
|
SOCKET_NONBLOCK=1,
|
||||||
SOCKET_CLOEXEC=2,
|
SOCKET_CLOEXEC=2,
|
||||||
};
|
};
|
||||||
int socket_accept4_flags(int s,char* ip,uint16* port, int flags);
|
int socket_accept4_flags(int s,char ip[4],uint16* port, int flags);
|
||||||
int socket_accept6_flags(int s,char* ip,uint16* port,uint32* scope_id, int flags);
|
int socket_accept6_flags(int s,char ip[16],uint16* port,uint32* scope_id, int flags);
|
||||||
|
|
||||||
att_writen(2,3) att_nonnull(2)
|
att_writen(2,3) att_nonnull(2)
|
||||||
ssize_t socket_recv4(int s,char* buf,size_t len,char* ip,uint16* port);
|
ssize_t socket_recv4(int s,char* buf,size_t len,char ip[4],uint16* port);
|
||||||
att_writen(2,3) att_nonnull(2)
|
att_writen(2,3) att_nonnull(2)
|
||||||
ssize_t socket_recv6(int s,char* buf,size_t len,char* ip,uint16* port,uint32* scope_id);
|
ssize_t socket_recv6(int s,char* buf,size_t len,char ip[16],uint16* port,uint32* scope_id);
|
||||||
|
|
||||||
att_readn(2,3) att_nonnull(2)
|
att_readn(2,3) att_nonnull(2)
|
||||||
ssize_t socket_send4(int s,const char* buf,size_t len,const char* ip,uint16 port);
|
ssize_t socket_send4(int s,const char* buf,size_t len,const char ip[4],uint16 port);
|
||||||
att_readn(2,3) att_nonnull(2)
|
att_readn(2,3) att_nonnull(2)
|
||||||
ssize_t socket_send4_flag(int s,const char* buf,size_t len,const char* ip,uint16 port,int flags);
|
ssize_t socket_send4_flag(int s,const char* buf,size_t len,const char ip[4],uint16 port,int flags);
|
||||||
att_readn(2,3) att_nonnull(2)
|
att_readn(2,3) att_nonnull(2)
|
||||||
ssize_t socket_send6(int s,const char* buf,size_t len,const char* ip,uint16 port,uint32 scope_id);
|
ssize_t socket_send6(int s,const char* buf,size_t len,const char ip[16],uint16 port,uint32 scope_id);
|
||||||
att_readn(2,3) att_nonnull(2)
|
att_readn(2,3) att_nonnull(2)
|
||||||
ssize_t socket_send6_flag(int s,const char* buf,size_t len,const char* ip,uint16 port,uint32 scope_id,int flags);
|
ssize_t socket_send6_flag(int s,const char* buf,size_t len,const char ip[16],uint16 port,uint32 scope_id,int flags);
|
||||||
|
|
||||||
int socket_local4(int s,char* ip,uint16* port);
|
int socket_local4(int s,char ip[4],uint16* port);
|
||||||
int socket_local6(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_local6(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
int socket_remote4(int s,char* ip,uint16* port);
|
int socket_remote4(int s,char ip[4],uint16* port);
|
||||||
int socket_remote6(int s,char* ip,uint16* port,uint32* scope_id);
|
int socket_remote6(int s,char ip[16],uint16* port,uint32* scope_id);
|
||||||
|
|
||||||
/* enable sending udp packets to the broadcast address */
|
/* enable sending udp packets to the broadcast address */
|
||||||
int socket_broadcast(int s);
|
int socket_broadcast(int s);
|
||||||
/* join a multicast group on the given interface */
|
/* join a multicast group on the given interface */
|
||||||
int socket_mcjoin4(int s,const char* groupip,const char* _interface);
|
int socket_mcjoin4(int s,const char groupip[4],const char _interface[4]);
|
||||||
int socket_mcjoin6(int s,const char* groupip,int _interface);
|
int socket_mcjoin6(int s,const char groupip[16],int _interface);
|
||||||
/* leave a multicast group on the given interface */
|
/* leave a multicast group on the given interface */
|
||||||
int socket_mcleave4(int s,const char* groupip);
|
int socket_mcleave4(int s,const char groupip[4]);
|
||||||
int socket_mcleave6(int s,const char* groupip);
|
int socket_mcleave6(int s,const char groupip[16]);
|
||||||
/* set multicast TTL/hop count for outgoing packets */
|
/* set multicast TTL/hop count for outgoing packets */
|
||||||
int socket_mcttl4(int s,char hops);
|
int socket_mcttl4(int s,char hops);
|
||||||
int socket_mchopcount6(int s,char hops);
|
int socket_mchopcount6(int s,char hops);
|
||||||
@ -121,8 +121,10 @@ int socket_quickack(int s,int value);
|
|||||||
|
|
||||||
/* For client-side TCP fast open, connect and sending the first data is
|
/* For client-side TCP fast open, connect and sending the first data is
|
||||||
* just one step, so we need an API to do it in one step */
|
* just one step, so we need an API to do it in one step */
|
||||||
ssize_t socket_fastopen_connect4(int s,const char* ip,uint16 port,const char* buf,size_t len);
|
att_readn(4,5) att_nonnull(4)
|
||||||
ssize_t socket_fastopen_connect6(int s,const char* ip,uint16 port,uint32 scope_id,const char* buf,size_t len);
|
ssize_t socket_fastopen_connect4(int s,const char ip[4],uint16 port,const char* buf,size_t len);
|
||||||
|
att_readn(5,6) att_nonnull(5)
|
||||||
|
ssize_t socket_fastopen_connect6(int s,const char ip[16],uint16 port,uint32 scope_id,const char* buf,size_t len);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
size_t fmt_ip6if(char* dest,const char* ip,uint32 scope_id) {
|
size_t fmt_ip6if(char* dest,const char ip[16],uint32 scope_id) {
|
||||||
size_t i=fmt_ip6(dest,ip);
|
size_t i=fmt_ip6(dest,ip);
|
||||||
if (scope_id) {
|
if (scope_id) {
|
||||||
if (dest) {
|
if (dest) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "havealloca.h"
|
#include "havealloca.h"
|
||||||
|
|
||||||
size_t scan_ip6if(const char* src,char* ip,uint32* scope_id) {
|
size_t scan_ip6if(const char* src,char ip[16],uint32* scope_id) {
|
||||||
size_t i=scan_ip6(src,ip);
|
size_t i=scan_ip6(src,ip);
|
||||||
*scope_id=0;
|
*scope_id=0;
|
||||||
if (src[i]=='%') {
|
if (src[i]=='%') {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "io_internal.h"
|
#include "io_internal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int socket_accept4(int s,char *ip,uint16 *port) {
|
int socket_accept4(int s,char ip[4],uint16 *port) {
|
||||||
struct sockaddr_in si;
|
struct sockaddr_in si;
|
||||||
socklen_t len = sizeof si;
|
socklen_t len = sizeof si;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
#include "iarray.h"
|
||||||
#include "havesl.h"
|
#include "havesl.h"
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
@ -22,13 +23,13 @@
|
|||||||
|
|
||||||
#include "haveaccept4.h"
|
#include "haveaccept4.h"
|
||||||
|
|
||||||
int socket_accept4_flags(int s, char *ip, uint16 *port, int flags) {
|
int socket_accept4_flags(int s, char ip[4], uint16 *port, int flags) {
|
||||||
struct sockaddr_in si;
|
struct sockaddr_in si;
|
||||||
socklen_t len = sizeof si;
|
socklen_t len = sizeof si;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
|
io_entry* e=iarray_get(&io_fds,s);
|
||||||
if (e && e->inuse) {
|
if (e && e->inuse) {
|
||||||
int sa2len;
|
int sa2len;
|
||||||
fd=-1;
|
fd=-1;
|
||||||
@ -42,14 +43,14 @@ incoming:
|
|||||||
{
|
{
|
||||||
struct sockaddr* x,* y;
|
struct sockaddr* x,* y;
|
||||||
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&len);
|
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&len);
|
||||||
if (len>sizeof(si)) len=sizeof(si);
|
if ((size_t)len>sizeof(si)) len=sizeof(si);
|
||||||
memcpy(&si,y,len);
|
memcpy(&si,y,len);
|
||||||
}
|
}
|
||||||
fd=e->next_accept;
|
fd=e->next_accept;
|
||||||
e->next_accept=0;
|
e->next_accept=0;
|
||||||
if (e->nonblock) {
|
if (e->nonblock) {
|
||||||
if (io_fd_canwrite(fd)) {
|
if (io_fd_canwrite(fd)) {
|
||||||
io_entry* f=array_get(&io_fds,sizeof(io_entry),fd);
|
io_entry* f=iarray_get(&io_fds,fd);
|
||||||
if (f) {
|
if (f) {
|
||||||
f->nonblock=1;
|
f->nonblock=1;
|
||||||
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
||||||
@ -61,7 +62,7 @@ incoming:
|
|||||||
/* no accept queued, queue one now. */
|
/* no accept queued, queue one now. */
|
||||||
if (e->next_accept==0) {
|
if (e->next_accept==0) {
|
||||||
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||||
if (e==-1)
|
if (e->next_accept==(SOCKET)-1)
|
||||||
return winsock2errno(-1);
|
return winsock2errno(-1);
|
||||||
}
|
}
|
||||||
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
||||||
@ -98,6 +99,7 @@ incoming:
|
|||||||
/* if we get here, the kernel did not support accept4. */
|
/* if we get here, the kernel did not support accept4. */
|
||||||
if ((fd=accept(s,(void*) &si,&len))==-1)
|
if ((fd=accept(s,(void*) &si,&len))==-1)
|
||||||
return -1;
|
return -1;
|
||||||
|
#ifndef __MINGW32__
|
||||||
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
||||||
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
||||||
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
||||||
@ -114,6 +116,7 @@ incoming:
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef HAVE_ACCEPT4
|
#ifdef HAVE_ACCEPT4
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||||
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK);
|
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||||
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||||
return socket_accept4_flags(s,ip,port,SOCKET_CLOEXEC);
|
return socket_accept4_flags(s,ip,port,SOCKET_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "io_internal.h"
|
#include "io_internal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id)
|
int socket_accept6(int s,char ip[16],uint16* port,uint32* scope_id)
|
||||||
{
|
{
|
||||||
#ifdef LIBC_HAS_IP6
|
#ifdef LIBC_HAS_IP6
|
||||||
struct sockaddr_in6 sa;
|
struct sockaddr_in6 sa;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include <winsock2.h>
|
||||||
|
#endif
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -9,6 +12,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "iarray.h"
|
||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "byte.h"
|
#include "byte.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
@ -27,7 +31,7 @@
|
|||||||
|
|
||||||
#include "haveaccept4.h"
|
#include "haveaccept4.h"
|
||||||
|
|
||||||
int socket_accept6_flags(int s, char* ip, uint16* port, uint32* scope_id, int flags)
|
int socket_accept6_flags(int s, char ip[16], uint16* port, uint32* scope_id, int flags)
|
||||||
{
|
{
|
||||||
#ifdef LIBC_HAS_IP6
|
#ifdef LIBC_HAS_IP6
|
||||||
struct sockaddr_in6 sa;
|
struct sockaddr_in6 sa;
|
||||||
@ -39,7 +43,7 @@ int socket_accept6_flags(int s, char* ip, uint16* port, uint32* scope_id, int fl
|
|||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
// Windows uses overlapped I/O instead of non-blocking I/O
|
// Windows uses overlapped I/O instead of non-blocking I/O
|
||||||
io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
|
io_entry* e=iarray_get(&io_fds,s);
|
||||||
if (e && e->inuse) {
|
if (e && e->inuse) {
|
||||||
int sa2len;
|
int sa2len;
|
||||||
fd=-1;
|
fd=-1;
|
||||||
@ -53,14 +57,14 @@ incoming:
|
|||||||
{
|
{
|
||||||
struct sockaddr* x,* y;
|
struct sockaddr* x,* y;
|
||||||
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&dummy);
|
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&dummy);
|
||||||
if (dummy>sizeof(sa)) dummy=sizeof(sa);
|
if ((size_t)dummy>sizeof(sa)) dummy=sizeof(sa);
|
||||||
memcpy(&sa,y,dummy);
|
memcpy(&sa,y,dummy);
|
||||||
}
|
}
|
||||||
fd=e->next_accept;
|
fd=e->next_accept;
|
||||||
e->next_accept=0;
|
e->next_accept=0;
|
||||||
if (e->nonblock) {
|
if (e->nonblock) {
|
||||||
if (io_fd(fd)) {
|
if (io_fd(fd)) {
|
||||||
io_entry* f=array_get(&io_fds,sizeof(io_entry),fd);
|
io_entry* f=iarray_get(&io_fds,fd);
|
||||||
if (f) {
|
if (f) {
|
||||||
f->nonblock=1;
|
f->nonblock=1;
|
||||||
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
||||||
@ -72,7 +76,7 @@ incoming:
|
|||||||
/* no accept queued, queue one now. */
|
/* no accept queued, queue one now. */
|
||||||
if (e->next_accept==0) {
|
if (e->next_accept==0) {
|
||||||
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||||
if (e==-1)
|
if (e->next_accept==(SOCKET)-1)
|
||||||
return winsock2errno(-1);
|
return winsock2errno(-1);
|
||||||
}
|
}
|
||||||
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
||||||
@ -108,6 +112,7 @@ incoming:
|
|||||||
fd = accept(s, (struct sockaddr *) &sa, &dummy);
|
fd = accept(s, (struct sockaddr *) &sa, &dummy);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
#ifndef __MINGW32__
|
||||||
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
||||||
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
||||||
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
||||||
@ -124,6 +129,7 @@ incoming:
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef HAVE_ACCEPT4
|
#ifdef HAVE_ACCEPT4
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK);
|
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_CLOEXEC);
|
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "uint32.h"
|
#include "uint32.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
int socket_bind4(int s,const char *ip,uint16 port) {
|
int socket_bind4(int s,const char ip[4],uint16 port) {
|
||||||
struct sockaddr_in si;
|
struct sockaddr_in si;
|
||||||
byte_zero(&si,sizeof si);
|
byte_zero(&si,sizeof si);
|
||||||
si.sin_family = AF_INET;
|
si.sin_family = AF_INET;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
|
|
||||||
int socket_bind4_reuse(int s,const char *ip,uint16 port) {
|
int socket_bind4_reuse(int s,const char ip[4],uint16 port) {
|
||||||
int one=1;
|
int one=1;
|
||||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||||
#ifdef SO_REUSEPORT
|
#ifdef SO_REUSEPORT
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "windoze.h"
|
#include "windoze.h"
|
||||||
|
|
||||||
int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id) {
|
int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id) {
|
||||||
int one=1;
|
int one=1;
|
||||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||||
#ifdef SO_REUSEPORT
|
#ifdef SO_REUSEPORT
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "uint16.h"
|
#include "uint16.h"
|
||||||
#include "uint32.h"
|
#include "uint32.h"
|
||||||
|
|
||||||
int socket_connect4(int s,const char *ip,uint16 port) {
|
int socket_connect4(int s,const char ip[4],uint16 port) {
|
||||||
struct sockaddr_in si;
|
struct sockaddr_in si;
|
||||||
byte_zero(&si,sizeof(si));
|
byte_zero(&si,sizeof(si));
|
||||||
si.sin_family=AF_INET;
|
si.sin_family=AF_INET;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
ssize_t socket_fastopen_connect4(int s,const char* ip,uint16 port,const char* buf,size_t len) {
|
ssize_t socket_fastopen_connect4(int s,const char ip[4],uint16 port,const char* buf,size_t len) {
|
||||||
int r;
|
int r;
|
||||||
#ifndef MSG_FASTOPEN
|
#ifndef MSG_FASTOPEN
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
ssize_t socket_fastopen_connect6(int s,const char* ip,uint16 port,uint32_t scope_id,const char* buf,size_t len) {
|
ssize_t socket_fastopen_connect6(int s,const char ip[16],uint16 port,uint32_t scope_id,const char* buf,size_t len) {
|
||||||
#ifndef MSG_FASTOPEN
|
#ifndef MSG_FASTOPEN
|
||||||
int r;
|
int r;
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user