parent
b81e8bcd27
commit
82a4ae868d
@ -1,9 +1,12 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_bind4_reuse(int s,const char *ip,uint16 port) {
|
||||
int one=1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||
return socket_bind4(s,ip,port);
|
||||
return winsock2errno(socket_bind4(s,ip,port));
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id) {
|
||||
int one=1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||
return socket_bind6(s,ip,port,scope_id);
|
||||
return winsock2errno(socket_bind6(s,ip,port,scope_id));
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_broadcast(int s)
|
||||
{
|
||||
int opt = 1;
|
||||
return setsockopt(s,SOL_SOCKET,SO_BROADCAST,&opt,sizeof opt);
|
||||
return winsock2errno(setsockopt(s,SOL_SOCKET,SO_BROADCAST,&opt,sizeof opt));
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,23 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include "socket.h"
|
||||
#include "haven2i.h"
|
||||
|
||||
#ifdef HAVE_N2I
|
||||
static char ifname[IFNAMSIZ];
|
||||
|
||||
const char* socket_getifname(uint32 interface) {
|
||||
char *tmp=if_indextoname(interface,ifname);
|
||||
const char* socket_getifname(uint32 _interface) {
|
||||
char *tmp=if_indextoname(_interface,ifname);
|
||||
if (tmp)
|
||||
return tmp;
|
||||
else
|
||||
return "[unknown]";
|
||||
}
|
||||
#else
|
||||
const char* socket_getifname(uint32 interface) {
|
||||
const char* socket_getifname(uint32 _interface) {
|
||||
return "[unknown]";
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_listen(int s,unsigned int backlog) {
|
||||
return listen(s, backlog);
|
||||
return winsock2errno(listen(s, backlog));
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
#include "byte.h"
|
||||
|
||||
int socket_mcjoin4(int s,const char ip[4],const char interface[4])
|
||||
int socket_mcjoin4(int s,const char ip[4],const char _interface[4])
|
||||
{
|
||||
struct ip_mreq opt;
|
||||
byte_copy(&opt.imr_multiaddr.s_addr,4,ip);
|
||||
byte_copy(&opt.imr_interface.s_addr,4,interface);
|
||||
return setsockopt(s,IPPROTO_IP,IP_ADD_MEMBERSHIP,&opt,sizeof opt);
|
||||
byte_copy(&opt.imr_interface.s_addr,4,_interface);
|
||||
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_ADD_MEMBERSHIP,&opt,sizeof opt));
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_mcloop4(int s,char loop)
|
||||
{
|
||||
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop);
|
||||
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop));
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_mcttl4(int s,char TTL)
|
||||
{
|
||||
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_TTL,&TTL,sizeof TTL);
|
||||
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_TTL,&TTL,sizeof TTL));
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_tcp4(void) {
|
||||
return socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
__winsock_init();
|
||||
return winsock2errno(socket(PF_INET,SOCK_STREAM,IPPROTO_TCP));
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
void socket_tryreservein(int s,int size)
|
||||
{
|
||||
while (size >= 1024) {
|
||||
if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size) == 0) return;
|
||||
if (winsock2errno(setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size)) == 0) return;
|
||||
size -= (size >> 5);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
#include <sys/types.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "windoze.h"
|
||||
|
||||
#include "socket.h"
|
||||
|
||||
int socket_udp4(void) {
|
||||
return socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
|
||||
__winsock_init();
|
||||
return winsock2errno(socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP));
|
||||
}
|
||||
|
@ -1,12 +1,29 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include "taia.h"
|
||||
#ifdef __MINGW32__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void taia_now(struct taia *t)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
union {
|
||||
FILETIME f;
|
||||
unsigned long long l;
|
||||
} fnord;
|
||||
GetSystemTimeAsFileTime(&fnord.f);
|
||||
/* 64-bit value representing the number of 100-nanosecond intervals
|
||||
* since January 1, 1601 (UTC) */
|
||||
fnord.l-=((long long)(1970-1601))*365*24*60*60;
|
||||
t->sec.x=fnord.l/10000000;
|
||||
t->nano=((fnord.l+5)/10)%1000000;
|
||||
t->atto=0;
|
||||
#else
|
||||
struct timeval now;
|
||||
gettimeofday(&now,(struct timezone *) 0);
|
||||
tai_unix(&t->sec,now.tv_sec);
|
||||
t->nano = 1000 * now.tv_usec + 500;
|
||||
t->atto = 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <poll.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <strings.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/devpoll.h>
|
||||
|
||||
main() {
|
||||
int fd=open("/dev/poll",O_RDWR);
|
||||
struct pollfd p[100];
|
||||
int i,r;
|
||||
dvpoll_t timeout;
|
||||
p[0].fd=0;
|
||||
p[0].events=POLLIN;
|
||||
write(fd,p,sizeof(struct pollfd));
|
||||
timeout.dp_timeout=100; /* milliseconds? */
|
||||
timeout.dp_nfds=1;
|
||||
timeout.dp_fds=p;
|
||||
r=ioctl(fd,DP_POLL,&timeout);
|
||||
for (i=0; i<r; ++i)
|
||||
printf("event %d on fd #%d\n",p[i].revents,p[i].fd);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
main() {
|
||||
struct sockaddr_in6 sa;
|
||||
sa.sin6_family = PF_INET6;
|
||||
sa.sin6_scope_id = 23;
|
||||
}
|
Loading…
Reference in New Issue