Browse Source

fix for NetBSD 3.0 (they broke their sys/types.h)

remove support for ip6.int reverse lookup in DNS routines (the domain is
no longer delegated)
master
Felix von Leitner 14 years ago
parent
commit
56fb0a586d
27 changed files with 268 additions and 107 deletions
  1. +4
    -0
      CHANGES
  2. +2
    -1
      GNUmakefile
  3. +28
    -15
      Makefile
  4. +3
    -1
      TODO
  5. +1
    -3
      dns.h
  6. +3
    -5
      dns/dns_name.c
  7. +1
    -4
      dns/dns_name6.3
  8. +2
    -6
      dns/dns_name6_domain.3
  9. +2
    -5
      dns/dns_nd6.c
  10. +6
    -0
      io/io_fd.c
  11. +4
    -0
      io/io_passfd.c
  12. +4
    -0
      io/io_receivefd.c
  13. +9
    -1
      io/io_tryread.c
  14. +18
    -5
      io/io_trywrite.c
  15. +11
    -1
      io/io_waituntil2.c
  16. +3
    -0
      io/io_wantwrite.c
  17. +35
    -4
      io/iob_send.c
  18. +2
    -0
      socket.h
  19. +1
    -1
      socket/socket_tcp4.3
  20. +1
    -10
      socket/socket_tcp4.c
  21. +26
    -0
      socket/socket_tcp4b.3
  22. +17
    -0
      socket/socket_tcp4b.c
  23. +2
    -45
      socket/socket_tcp6.c
  24. +26
    -0
      socket/socket_tcp6b.3
  25. +51
    -0
      socket/socket_tcp6b.c
  26. +2
    -0
      test/uudecode.c
  27. +4
    -0
      tryalloca.c

+ 4
- 0
CHANGES View File

@@ -14,6 +14,10 @@
add io_block
make socket_(tc|ud)p[46] actually return non-blocking sockets as
documented (Richard Lyons)
fix for NetBSD 3.0 (Their /sys/types.h actually does not define u_char
unless you #define _NETBSD_SOURCE, and then their CMSG_* macros use
it. This is horrible even by OpenBSD standards)
remove support for ip6.int (it's no longer delegated)

0.24:
fix scan_to_sa (Tim Lorenz)


+ 2
- 1
GNUmakefile View File

@@ -244,7 +244,8 @@ havesigio.h: trysigio.c
havealloca.h: tryalloca.c
-rm -f $@
echo "#include <stdlib.h>" > $@
if $(DIET) $(CC) $(CFLAGS) -c tryalloca.c >/dev/null 2>&1; then echo "#include <alloca.h>"; fi >> $@
if $(DIET) $(CC) $(CFLAGS) -c tryalloca.c -DA >/dev/null 2>&1; then echo "#include <alloca.h>"; fi >> $@
if $(DIET) $(CC) $(CFLAGS) -c tryalloca.c -DB >/dev/null 2>&1; then echo "#include <malloc.h>"; fi >> $@
-rm -f tryalloca.o

iopause.h: iopause.h1 iopause.h2 trypoll.c


+ 28
- 15
Makefile View File

@@ -117,10 +117,10 @@ case_diffs.o: case/case_diffs.c case.h
case_lowerb.o: case/case_lowerb.c case.h
case_lowers.o: case/case_lowers.c case.h
case_starts.o: case/case_starts.c case.h
cdb.o: cdb/cdb.c byte.h cdb.h uint32.h
cdb_hash.o: cdb/cdb_hash.c cdb.h uint32.h
cdb_make.o: cdb/cdb_make.c cdb.h uint32.h cdb_make.h buffer.h
cdb_traverse.o: cdb/cdb_traverse.c cdb.h uint32.h
cdb.o: cdb/cdb.c byte.h cdb.h uint32.h uint64.h
cdb_hash.o: cdb/cdb_hash.c cdb.h uint32.h uint64.h
cdb_make.o: cdb/cdb_make.c cdb.h uint32.h uint64.h cdb_make.h buffer.h
cdb_traverse.o: cdb/cdb_traverse.c cdb.h uint32.h uint64.h
dns_dfd.o: dns/dns_dfd.c byte.h dns.h stralloc.h iopause.h taia.h tai.h \
uint64.h
dns_domain.o: dns/dns_domain.c case.h byte.h dns.h stralloc.h iopause.h \
@@ -187,6 +187,8 @@ fmt_xlong.o: fmt/fmt_xlong.c fmt.h haveinline.h
fmt_xlonglong.o: fmt/fmt_xlonglong.c fmt.h
io_appendfile.o: io/io_appendfile.c io_internal.h io.h uint64.h taia.h \
tai.h array.h haveepoll.h havekqueue.h havedevpoll.h havesigio.h
io_block.o: io/io_block.c io_internal.h io.h uint64.h taia.h tai.h \
array.h haveepoll.h havekqueue.h havedevpoll.h havesigio.h
io_canread.o: io/io_canread.c io_internal.h io.h uint64.h taia.h tai.h \
array.h haveepoll.h havekqueue.h havedevpoll.h havesigio.h
io_canwrite.o: io/io_canwrite.c io_internal.h io.h uint64.h taia.h tai.h \
@@ -284,16 +286,22 @@ iob_prefetch.o: io/iob_prefetch.c iob_internal.h iob.h io.h uint64.h \
taia.h tai.h array.h
iob_reset.o: io/iob_reset.c byte.h iob_internal.h iob.h io.h uint64.h \
taia.h tai.h array.h
iob_send.o: io/iob_send.c havebsdsf.h havealloca.h iob_internal.h iob.h \
io.h uint64.h taia.h tai.h array.h
iob_send.o: io/iob_send.c havebsdsf.h iob_internal.h iob.h io.h uint64.h \
taia.h tai.h array.h
iob_write.o: io/iob_write.c iob_internal.h iob.h io.h uint64.h taia.h \
tai.h array.h
mmap_private.o: mmap/mmap_private.c open.h mmap.h
mmap_read.o: mmap/mmap_read.c open.h mmap.h
mmap_shared.o: mmap/mmap_shared.c open.h mmap.h
mmap_unmap.o: mmap/mmap_unmap.c open.h mmap.h
imult16.o: mult/imult16.c safemult.h uint16.h uint32.h uint64.h
imult32.o: mult/imult32.c safemult.h uint16.h uint32.h uint64.h
imult64.o: mult/imult64.c safemult.h uint16.h uint32.h uint64.h
range_arrayinbuf.o: mult/range_arrayinbuf.c rangecheck.h safemult.h \
uint16.h uint32.h uint64.h
range_str2inbuf.o: mult/range_str2inbuf.c rangecheck.h
range_str4inbuf.o: mult/range_str4inbuf.c rangecheck.h
range_strinbuf.o: mult/range_strinbuf.c rangecheck.h
umult16.o: mult/umult16.c safemult.h uint16.h uint32.h uint64.h
umult32.o: mult/umult32.c safemult.h uint16.h uint32.h uint64.h
umult64.o: mult/umult64.c safemult.h uint16.h uint32.h uint64.h
@@ -342,7 +350,7 @@ scan_ip4.o: socket/scan_ip4.c scan.h ip4.h
scan_ip6.o: socket/scan_ip6.c scan.h ip4.h ip6.h byte.h uint32.h
scan_ip6_flat.o: socket/scan_ip6_flat.c scan.h
scan_ip6if.o: socket/scan_ip6if.c ip6.h byte.h uint32.h byte.h socket.h \
uint16.h havealloca.h
uint16.h
socket_accept4.o: socket/socket_accept4.c windoze.h socket.h uint16.h \
uint32.h havesl.h
socket_accept6.o: socket/socket_accept6.c windoze.h byte.h socket.h \
@@ -403,14 +411,16 @@ socket_send4.o: socket/socket_send4.c windoze.h byte.h socket.h uint16.h \
uint32.h
socket_send6.o: socket/socket_send6.c windoze.h byte.h socket.h uint16.h \
uint32.h ip6.h byte.h haveip6.h ip4.h havescope.h
socket_tcp4.o: socket/socket_tcp4.c windoze.h socket.h uint16.h uint32.h
socket_tcp4.o: socket/socket_tcp4.c windoze.h socket.h uint16.h uint32.h \
ndelay.h
socket_tcp6.o: socket/socket_tcp6.c windoze.h haveip6.h socket.h uint16.h \
uint32.h
uint32.h ndelay.h
socket_tryreservein.o: socket/socket_tryreservein.c windoze.h socket.h \
uint16.h uint32.h
socket_udp4.o: socket/socket_udp4.c windoze.h socket.h uint16.h uint32.h
socket_udp4.o: socket/socket_udp4.c windoze.h socket.h uint16.h uint32.h \
ndelay.h
socket_udp6.o: socket/socket_udp6.c windoze.h haveip6.h socket.h uint16.h \
uint32.h
uint32.h ndelay.h
socket_v4mappedprefix.o: socket/socket_v4mappedprefix.c
socket_v6any.o: socket/socket_v6any.c
socket_v6loopback.o: socket/socket_v6loopback.c
@@ -466,6 +476,8 @@ fmt_foldwhitespace.o: textcode/fmt_foldwhitespace.c fmt.h textcode.h \
str.h haveinline.h
fmt_hexdump.o: textcode/fmt_hexdump.c fmt.h textcode.h str.h haveinline.h
fmt_html.o: textcode/fmt_html.c fmt.h textcode.h str.h haveinline.h
fmt_ldapescape.o: textcode/fmt_ldapescape.c fmt.h textcode.h haveinline.h \
str.h
fmt_quotedprintable.o: textcode/fmt_quotedprintable.c fmt.h textcode.h \
haveinline.h str.h
fmt_to_array.o: textcode/fmt_to_array.c array.h uint64.h textcode.h
@@ -480,6 +492,7 @@ scan_base64.o: textcode/scan_base64.c textcode.h haveinline.h
scan_cescape.o: textcode/scan_cescape.c fmt.h textcode.h scan.h
scan_hexdump.o: textcode/scan_hexdump.c fmt.h textcode.h scan.h
scan_html.o: textcode/scan_html.c fmt.h textcode.h haveinline.h case.h
scan_ldapescape.o: textcode/scan_ldapescape.c fmt.h textcode.h scan.h
scan_quotedprintable.o: textcode/scan_quotedprintable.c fmt.h textcode.h \
scan.h
scan_to_array.o: textcode/scan_to_array.c str.h array.h uint64.h \
@@ -519,15 +532,15 @@ STRALLOC_OBJS=stralloc_append.o stralloc_cat.o stralloc_catb.o stralloc_catlong0
UNIX_OBJS=iopause.o ndelay_off.o ndelay_on.o winsock2errno.o
SOCKET_OBJS=fmt_ip4.o fmt_ip6.o fmt_ip6_flat.o fmt_ip6c.o fmt_ip6if.o fmt_ip6ifc.o init.o scan_ip4.o scan_ip6.o scan_ip6_flat.o scan_ip6if.o socket_accept4.o socket_accept6.o socket_bind4.o socket_bind4_reuse.o socket_bind6.o socket_bind6_reuse.o socket_broadcast.o socket_connect4.o socket_connect6.o socket_connected.o socket_getifidx.o socket_getifname.o socket_ip4loopback.o socket_listen.o socket_local4.o socket_local6.o socket_mchopcount6.o socket_mcjoin4.o socket_mcjoin6.o socket_mcleave4.o socket_mcleave6.o socket_mcloop4.o socket_mcloop6.o socket_mcttl4.o socket_noipv6.o socket_recv4.o socket_recv6.o socket_remote4.o socket_remote6.o socket_send4.o socket_send6.o socket_tcp4.o socket_tcp6.o socket_tryreservein.o socket_udp4.o socket_udp6.o socket_v4mappedprefix.o socket_v6any.o socket_v6loopback.o
BUFFER_OBJS=buffer_0.o buffer_0small.o buffer_1.o buffer_1small.o buffer_2.o buffer_close.o buffer_feed.o buffer_flush.o buffer_fromsa.o buffer_get.o buffer_get_new_token_sa.o buffer_get_new_token_sa_pred.o buffer_get_token.o buffer_get_token_pred.o buffer_get_token_sa.o buffer_get_token_sa_pred.o buffer_getc.o buffer_getline.o buffer_getline_sa.o buffer_getn.o buffer_getnewline_sa.o buffer_init.o buffer_init_free.o buffer_mmapread.o buffer_peek.o buffer_put.o buffer_put8long.o buffer_putalign.o buffer_puterror.o buffer_puterror2.o buffer_putflush.o buffer_putlong.o buffer_putlonglong.o buffer_putm_internal.o buffer_putm_internal_flush.o buffer_putnlflush.o buffer_puts.o buffer_putsa.o buffer_putsaflush.o buffer_putsalign.o buffer_putsflush.o buffer_putspace.o buffer_putulong.o buffer_putulonglong.o buffer_putxlong.o buffer_seek.o buffer_stubborn.o buffer_stubborn2.o errmsg_iam.o errmsg_info.o errmsg_infosys.o errmsg_puts.o errmsg_warn.o errmsg_warnsys.o errmsg_write.o
MMAP_OBJS=mmap_private.o mmap_read.o mmap_shared.o
MMAP_OBJS=mmap_private.o mmap_read.o mmap_shared.o mmap_unmap.o
TAIA_OBJS=taia_add.o taia_addsec.o taia_approx.o taia_frac.o taia_half.o taia_less.o taia_now.o taia_pack.o taia_sub.o taia_tai.o taia_uint.o taia_unpack.o
TAI_OBJS=tai_add.o tai_now.o tai_pack.o tai_sub.o tai_uint.o tai_unpack.o
DNS_OBJS=dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ip6.o dns_ipq.o dns_ipq6.o dns_mx.o dns_name.o dns_nd.o dns_nd6.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o dns_resolve.o dns_sortip.o dns_sortip6.o dns_transmit.o dns_txt.o
CASE_OBJS=case_diffb.o case_diffs.o case_lowerb.o case_lowers.o case_starts.o
MULT_OBJS=imult16.o imult32.o imult64.o umult16.o umult32.o umult64.o
MULT_OBJS=imult16.o imult32.o imult64.o range_arrayinbuf.o range_str2inbuf.o range_str4inbuf.o range_strinbuf.o umult16.o umult32.o umult64.o
ARRAY_OBJS=array_allocate.o array_bytes.o array_cat.o array_cat0.o array_catb.o array_cate.o array_cats.o array_cats0.o array_equal.o array_fail.o array_get.o array_length.o array_reset.o array_start.o array_trunc.o array_truncate.o
IO_OBJS=io_appendfile.o io_canread.o io_canwrite.o io_check.o io_close.o io_closeonexec.o io_createfile.o io_dontwantread.o io_dontwantwrite.o io_eagain.o io_fd.o io_finishandshutdown.o io_getcookie.o io_mmapwritefile.o io_nonblock.o io_passfd.o io_pipe.o io_readfile.o io_readwritefile.o io_receivefd.o io_sendfile.o io_setcookie.o io_sigpipe.o io_socketpair.o io_timeout.o io_timeouted.o io_tryread.o io_tryreadtimeout.o io_trywrite.o io_trywritetimeout.o io_wait.o io_waitread.o io_waituntil.o io_waituntil2.o io_waitwrite.o io_wantread.o io_wantwrite.o iob_addbuf.o iob_addbuf_free.o iob_addbuf_internal.o iob_addfile.o iob_addfile_close.o iob_adds.o iob_adds_free.o iob_free.o iob_new.o iob_prefetch.o iob_reset.o iob_send.o iob_write.o
TEXTCODE_OBJS=base64.o fmt_base64.o fmt_cescape.o fmt_foldwhitespace.o fmt_hexdump.o fmt_html.o fmt_quotedprintable.o fmt_to_array.o fmt_to_sa.o fmt_tofrom_array.o fmt_urlencoded.o fmt_uuencoded.o fmt_yenc.o scan_base64.o scan_cescape.o scan_hexdump.o scan_html.o scan_quotedprintable.o scan_to_array.o scan_to_sa.o scan_tofrom_array.o scan_urlencoded.o scan_uuencoded.o scan_yenc.o
IO_OBJS=io_appendfile.o io_block.o io_canread.o io_canwrite.o io_check.o io_close.o io_closeonexec.o io_createfile.o io_dontwantread.o io_dontwantwrite.o io_eagain.o io_fd.o io_finishandshutdown.o io_getcookie.o io_mmapwritefile.o io_nonblock.o io_passfd.o io_pipe.o io_readfile.o io_readwritefile.o io_receivefd.o io_sendfile.o io_setcookie.o io_sigpipe.o io_socketpair.o io_timeout.o io_timeouted.o io_tryread.o io_tryreadtimeout.o io_trywrite.o io_trywritetimeout.o io_wait.o io_waitread.o io_waituntil.o io_waituntil2.o io_waitwrite.o io_wantread.o io_wantwrite.o iob_addbuf.o iob_addbuf_free.o iob_addbuf_internal.o iob_addfile.o iob_addfile_close.o iob_adds.o iob_adds_free.o iob_free.o iob_new.o iob_prefetch.o iob_reset.o iob_send.o iob_write.o
TEXTCODE_OBJS=base64.o fmt_base64.o fmt_cescape.o fmt_foldwhitespace.o fmt_hexdump.o fmt_html.o fmt_ldapescape.o fmt_quotedprintable.o fmt_to_array.o fmt_to_sa.o fmt_tofrom_array.o fmt_urlencoded.o fmt_uuencoded.o fmt_yenc.o scan_base64.o scan_cescape.o scan_hexdump.o scan_html.o scan_ldapescape.o scan_quotedprintable.o scan_to_array.o scan_to_sa.o scan_tofrom_array.o scan_urlencoded.o scan_uuencoded.o scan_yenc.o
CDB_OBJS=cdb.o cdb_hash.o cdb_make.o cdb_traverse.o

byte.a: $(BYTE_OBJS)


+ 3
- 1
TODO View File

@@ -10,7 +10,9 @@ http://www.sysinternals.com/ntw2k/info/comport.shtml
http://msdn.microsoft.com/msdnmag/issues/1000/winsock/default.aspx


Solaris 9: http://docs.sun.com/db/doc/816-5218/6mbcj7nrr?q=sendfile&a=view
Solaris 9:
http://docs.sun.com/app/docs/doc/817-0679/6mgfb87mm?q=sendfile&a=view
http://docs.sun.com/app/docs/doc/817-0679/6mgfb87mn?q=sendfile&a=view

HP-UX: http://docs.hp.com/hpux/onlinedocs/B9106-90009/00/01/168-con.html



+ 1
- 3
dns.h View File

@@ -87,9 +87,7 @@ int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);

#define DNS_IP6_INT 0
#define DNS_IP6_ARPA 1
void dns_name6_domain(char *,const char *,int);
void dns_name6_domain(char *,const char *);
#define DNS_NAME6_DOMAIN (4*16+11)
int dns_name6(stralloc *,const char *);



+ 3
- 5
dns/dns_name.c View File

@@ -48,11 +48,11 @@ int dns_name4(stralloc *out,const char ip[4])
return 0;
}

static int dns_name6_inner(stralloc *out,const char ip[16],int t)
static int dns_name6_inner(stralloc *out,const char ip[16])
{
char name[DNS_NAME6_DOMAIN];

dns_name6_domain(name,ip,t);
dns_name6_domain(name,ip);
if (dns_resolve(name,DNS_T_PTR) == -1) return -1;
if (dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1;
dns_transmit_free(&dns_resolve_tx);
@@ -64,7 +64,5 @@ int dns_name6(stralloc *out,const char ip[16])
{
if (ip6_isv4mapped(ip))
return dns_name4(out,ip+12);
if (dns_name6_inner(out,ip,DNS_IP6_ARPA)) return -1;
if (!out->len) return dns_name6_inner(out,ip,DNS_IP6_INT);
return 0;
return dns_name6_inner(out,ip);
}

+ 1
- 4
dns/dns_name6.3 View File

@@ -8,12 +8,9 @@ int \fBdns_name6\fP(stralloc* \fIout\fR,const char* \fIip\fR[16]);
.SH DESCRIPTION
dns_name6 looks up the domain name for the 16-byte IPv6 address in \fIip\fR. It
puts the (first) domain name into \fIout\fR and returns 0. If the relevant
ip6.int domain does not exist in DNS, or has no PTR records, \fIout\fR
ip6.arpa domain does not exist in DNS, or has no PTR records, \fIout\fR
will be empty.

dns_name6 will try both the new "ip6.arpa" reverse lookup domain and the
old (deprecated) "ip6.int" one.

If dns_name6 has trouble with the DNS lookup or runs out of memory, it returns
-1, setting errno appropriately. It may or may not change \fIout\fR.
.SH "SEE ALSO"


+ 2
- 6
dns/dns_name6_domain.3 View File

@@ -5,17 +5,13 @@ dns_name6_domain \- construct host name for reverse lookup
.B #include <dns.h>

void \fBdns_name6_domain\fP(char \fIq\fR[DNS_NAME6_DOMAIN],
const char* \fIip\fR[16],int \fItype\fR);
const char* \fIip\fR[16]);
.SH DESCRIPTION
dns_name6_domain is a low-level component of dns_name6. It converts an
IP address such as 4321:0:1:2:3:4:567:89ab into a domain name such as
b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT
b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.ARPA
and places the packet-encoded domain name into \fIq\fR.

\fItype\fR can be DNS_IP6_INT or DNS_IP6_ARPA. The "ip6.int" domain for
IPv6 reverse lookups is now deprecated and "ip6.arpa" is the standard
way.

q is zero terminated.

q must have space for DNS_NAME6_DOMAIN bytes.


+ 2
- 5
dns/dns_nd6.c View File

@@ -14,7 +14,7 @@ static char tohex(char c) {
return c>=10?c-10+'a':c+'0';
}

void dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16],int t)
void dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16])
{
unsigned int j;

@@ -24,9 +24,6 @@ void dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16],int t)
name[j*4+2]=1;
name[j*4+3]=tohex((unsigned char)ip[15-j] >> 4);
}
if (t==DNS_IP6_INT)
byte_copy(name + 4*16,9,"\3ip6\3int\0");
else if (t==DNS_IP6_ARPA)
byte_copy(name + 4*16,10,"\3ip6\4arpa\0");
byte_copy(name + 4*16,10,"\3ip6\4arpa\0");
}


+ 6
- 0
io/io_fd.c View File

@@ -26,6 +26,7 @@
#endif

#ifdef __MINGW32__
#include <stdio.h>
extern HANDLE io_comport;
#endif
array io_fds;
@@ -94,7 +95,9 @@ int io_fd(int64 d) {
io_comport=CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0);
if (io_comport) {
io_waitmode=COMPLETIONPORT;
fprintf(stderr,"Initialized completion port: %p\n",io_comport);
} else {
fprintf(stderr,"ARGH! Could not init completion port!\n");
errno=EINVAL;
return 0;
}
@@ -112,10 +115,13 @@ int io_fd(int64 d) {
#endif
#ifdef __MINGW32__
if (io_comport) {
fprintf(stderr,"Queueing %p at completion port %p...",d,io_comport);
if (CreateIoCompletionPort((HANDLE)d,io_comport,(ULONG_PTR)d,0)==0) {
fprintf(stderr," failed!\n");
errno=EBADF;
return 0;
}
fprintf(stderr," OK!\n");
}
#endif
return 1;


+ 4
- 0
io/io_passfd.c View File

@@ -7,6 +7,10 @@ int io_passfd(int64 sock,int64 fd) {
}
#else

#ifdef __NetBSD__
#define _NETBSD_SOURCE
#endif

#ifdef __OpenBSD__
#warning This is a HORRIBLE kludge around yet another thing OpenBSD broke
#warning If they make it possible to do file descriptor passing with


+ 4
- 0
io/io_receivefd.c View File

@@ -7,6 +7,10 @@ int64 io_receivefd(int64 sock) {
}
#else

#ifdef __NetBSD__
#define _NETBSD_SOURCE
#endif

#ifdef __OpenBSD__
#warning This is a HORRIBLE kludge around yet another thing OpenBSD broke
#warning If they make it possible to do file descriptor passing with


+ 9
- 1
io/io_tryread.c View File

@@ -41,15 +41,19 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
if (len>x) {
/* queue next read */
if (len>sizeof(e->inbuf)) len=sizeof(e->inbuf);
fprintf(stderr,"Queueing ReadFile on handle %p...",d);
if (ReadFile((HANDLE)d,e->inbuf,len,0,&e->or)) {
fprintf(stderr," got immediate answer\n");
e->canread=1;
e->readqueued=2;
e->next_write=first_writeable;
first_writeable=d;
} else if ((e->errorcode=GetLastError())==ERROR_IO_PENDING) {
fprintf(stderr," OK\n");
e->readqueued=1;
e->errorcode=0;
} else {
fprintf(stderr," error!\n");
e->canread=1;
e->readqueued=2;
e->next_write=first_writeable;
@@ -60,9 +64,13 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
return x;
}
if (!e->readqueued) {
fprintf(stderr,"!e->readqueued\n");
if (len>sizeof(e->inbuf)) len=sizeof(e->inbuf);
if (ReadFile((HANDLE)d,e->inbuf,len,0,&e->or))
if (ReadFile((HANDLE)d,e->inbuf,len,0,&e->or)) {
e->readqueued=1;
fprintf(stderr,"ReadFile returned nonzero\n");
} else
fprintf(stderr,"ReadFile returned zero\n");
}
errno=EAGAIN;
return -1;


+ 18
- 5
io/io_trywrite.c View File

@@ -9,6 +9,8 @@
#include "io_internal.h"

#ifdef __MINGW32__
#include <stdio.h>

/* All the Unix trickery is unsupported on Windows. Instead, one is
* supposed to do the whole write in overlapping mode and then get
* notified via an I/O completion port when it's done. */
@@ -22,12 +24,17 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
if (!e) { errno=EBADF; return -3; }
if (!e->nonblock) {
DWORD written;
if (WriteFile((HANDLE)d,buf,len,&written,0))
fprintf(stderr,"Socket is in blocking mode, just calling WriteFile...");
if (WriteFile((HANDLE)d,buf,len,&written,0)) {
fprintf(stderr," OK, got %u bytes.\n",written);
return written;
else
} else {
fprintf(stderr," failed.\n",written);
return winsock2errno(-3);
}
} else {
if (e->writequeued) {
if (e->writequeued && !e->canwrite) {
fprintf(stderr,"io_trywrite: write already queued, returning EAGAIN\n");
errno=EAGAIN;
return -1;
}
@@ -35,19 +42,25 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
e->canwrite=0;
e->next_write=-1;
if (e->errorcode) {
fprintf(stderr,"io_trywrite: e->canwrite was set, returning error %d\n",e->errorcode);
errno=winsock2errno(e->errorcode);
return -3;
}
fprintf(stderr,"io_trywrite: e->canwrite was set, had written %u bytes\n",e->bytes_written);
return e->bytes_written;
} else {
if (WriteFile((HANDLE)d,buf,len,&e->errorcode,&e->ow))
fprintf(stderr,"io_trywrite: queueing write...");
if (WriteFile((HANDLE)d,buf,len,&e->errorcode,&e->ow)) {
fprintf(stderr," worked unexpectedly, error %d\n",e->errorcode);
return e->errorcode; /* should not happen */
else if (GetLastError()==ERROR_IO_PENDING) {
} else if (GetLastError()==ERROR_IO_PENDING) {
fprintf(stderr," pending.\n");
e->writequeued=1;
errno=EAGAIN;
e->errorcode=0;
return -1;
} else {
fprintf(stderr," failed, error %d\n",e->errorcode);
winsock2errno(-1);
e->errorcode=errno;
return -3;


+ 11
- 1
io/io_waituntil2.c View File

@@ -10,6 +10,7 @@
#include <sys/time.h>
#ifdef __MINGW32__
#include <windows.h>
#include <stdio.h>
#else
#include <poll.h>
#endif
@@ -205,11 +206,19 @@ dopoll:
DWORD numberofbytes;
ULONG_PTR x;
LPOVERLAPPED o;
if (first_readable!=-1 || first_writeable!=-1) return;
if (first_readable!=-1 || first_writeable!=-1) {
fprintf(stderr,"io_waituntil2() returning immediately because first_readable(%p) or first_writeable(%p) are set\n",first_readable,first_writeable);
return;
}
fprintf(stderr,"Calling GetQueuedCompletionStatus %p...",io_comport);
if (GetQueuedCompletionStatus(io_comport,&numberofbytes,&x,&o,milliseconds==-1?milliseconds:INFINITE)) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),x);
fprintf(stderr," OK. Got %x, e=%p\n",x,e);
if (!e) return 0;
e->errorcode=0;
fprintf(stderr,"o=%p, e->or=%p, e->ow=%p, e->os=%p\n",o,&e->or,&e->ow,&e->os);
fprintf(stderr,"e->readqueued=%d, e->writequeued=%d, e->acceptqueued=%d, e->connectqueued=%d, e->sendfilequeued=%d\n",
e->readqueued,e->writequeued,e->acceptqueued,e->connectqueued,e->sendfilequeued);
if (o==&e->or && e->readqueued==1) {
e->readqueued=2;
e->canread=1;
@@ -245,6 +254,7 @@ dopoll:
/* either the overlapped I/O request failed or we timed out */
DWORD err;
io_entry* e;
fprintf(stderr," failure, o=%p.\n",o);
if (!o) return 0; /* timeout */
/* we got a completion packet for a failed I/O operation */
err=GetLastError();


+ 3
- 0
io/io_wantwrite.c View File

@@ -71,9 +71,12 @@ void io_wantwrite(int64 d) {
}
#endif
#ifdef __MINGW32__
printf("e->wantwrite == %d\n",e->wantwrite);
if (!e->wantwrite) {
e->next_write=first_writeable;
e->canwrite=1;
first_writeable=d;
printf("queueing write, setting first_writeable to %lld\n",d);
}
#endif
e->wantwrite=1;


+ 35
- 4
io/iob_send.c View File

@@ -5,6 +5,7 @@
#include <errno.h>
#include "io_internal.h"
#include "iob_internal.h"
#include <stdio.h>

int64 iob_send(int64 s,io_batch* b) {
/* Windows has a sendfile called TransmitFile, which can send one
@@ -22,7 +23,9 @@ int64 iob_send(int64 s,io_batch* b) {
return -3; /* can't happen error */
last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b));

fprintf(stderr,"iob_send() called!\n");
if (e->canwrite || e->sendfilequeued==1) {
fprintf(stderr,"...reaping finished WriteFile/TransmitFile.\n");
/* An overlapping write finished. Reap the result. */
if (e->bytes_written==-1) return -3;
if (e->bytes_written<x->n) {
@@ -43,26 +46,54 @@ int64 iob_send(int64 s,io_batch* b) {
if (x[i].n) break;

if (x[i].type==FROMBUF || x[i].type==FROMBUF_FREE) {
fprintf(stderr,"found non-sent buffer batch entry at %d\n",i);
if (x+i+1 < last &&
(x[i+1].type==FROMFILE || x[i+1].type==FROMFILE_CLOSE)) {
fprintf(stderr,"Next is a file, can use TransmitFile\n",i);
TRANSMIT_FILE_BUFFERS tfb;
e->sendfilequeued=1;
memset(&tfb,0,sizeof(tfb));
memset(&e[i].os,0,sizeof(e[i].os));
e[i].os.Offset=x[i].offset;
e[i].os.OffsetHigh=(x[i].offset>>32);
fprintf(stderr,"Calling TransmitFile on %p...",s);
if (!TransmitFile(s,(HANDLE)x[i].fd,
x[i].n+tfb.HeadLength>0xffff?0xffff:x[i].n,
0,&e[i].os,&tfb,TF_USE_KERNEL_APC))
return -3;
0,&e[i].os,&tfb,TF_USE_KERNEL_APC)) {
if (GetLastError()==ERROR_IO_PENDING) {
fprintf(stderr," pending.!\n");
e->writequeued=1;
errno=EAGAIN;
e->errorcode=0;
return -1;
} else {
fprintf(stderr," failed!\n");
e->errorcode=errno;
return -3;
}
}
fprintf(stderr," OK!\n");
return sent;
} else {
e->writequeued=1;
if (!WriteFile(s,x[i].buf+x[i].offset,x[i].n,0,&e->ow))
return -3;
fprintf(stderr,"Queueing WriteFile on %p...",s);
if (!WriteFile(s,x[i].buf+x[i].offset,x[i].n,0,&e->ow)) {
if (GetLastError()==ERROR_IO_PENDING) {
fprintf(stderr," pending.\n");
e->writequeued=1;
errno=EAGAIN;
e->errorcode=0;
return -1;
} else {
fprintf(stderr," failed.\n");
e->errorcode=errno;
return -3;
}
}
return sent;
}
} else {
fprintf(stderr,"Calling TransmitFile...\n");
e->sendfilequeued=1;
memset(&e[i].os,0,sizeof(e[i].os));
e[i].os.Offset=x[i].offset;


+ 2
- 0
socket.h View File

@@ -5,8 +5,10 @@
#include "uint32.h"

int socket_tcp4(void);
int socket_tcp4b(void);
int socket_udp4(void);
int socket_tcp6(void);
int socket_tcp6b(void);
int socket_udp6(void);

#define socket_tcp() socket_tcp4()


+ 1
- 1
socket/socket_tcp4.3 View File

@@ -23,4 +23,4 @@ any resources.
socket_connect4(s,ip,p);

.SH "SEE ALSO"
socket_bind4(3), socket_bind6(3)
socket_tcp4b(3), socket_bind4(3), socket_bind6(3)

+ 1
- 10
socket/socket_tcp4.c View File

@@ -1,18 +1,9 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "ndelay.h"

int socket_tcp4(void) {
int s;
__winsock_init();
s = winsock2errno(socket(PF_INET,SOCK_STREAM,IPPROTO_TCP));
if (s == -1) return -1;
int s=socket_tcp4b();
if (ndelay_on(s) == -1) { close(s); return -1; }
return s;
}

+ 26
- 0
socket/socket_tcp4b.3 View File

@@ -0,0 +1,26 @@
.TH socket_tcp4b 3
.SH NAME
socket_tcp4b \- create a blocking TCP/IP stream socket
.SH SYNTAX
.B #include <socket.h>

int \fBsocket_tcp4b\fP();
.SH DESCRIPTION
socket_tcp4b creates a blocking TCP/IP stream socket and returns a
file descriptor pointing to that socket. If something goes wrong,
socket_tcp4b returns -1, setting errno appropriately, without allocating
any resources.

.SH EXAMPLE
#include <socket.h>

int \fIs\fR;
char \fIip\fR[4];
uint16 \fIp\fR;

\fIs\fR = socket_tcp4b();
socket_bind4(s,ip,p);
socket_connect4(s,ip,p);

.SH "SEE ALSO"
socket_tcp4(3), socket_bind4(3), socket_bind6(3)

+ 17
- 0
socket/socket_tcp4b.c View File

@@ -0,0 +1,17 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "ndelay.h"

int socket_tcp4b(void) {
int s;
__winsock_init();
s = winsock2errno(socket(PF_INET,SOCK_STREAM,IPPROTO_TCP));
if (s == -1) return -1;
return s;
}

+ 2
- 45
socket/socket_tcp6.c View File

@@ -1,52 +1,9 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "haveip6.h"
#include "socket.h"
#include "ndelay.h"

#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT EINVAL
#endif
#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT EAFNOSUPPORT
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT EAFNOSUPPORT
#endif

int socket_tcp6(void)
{
#ifdef LIBC_HAS_IP6
int s;

__winsock_init();
if (noipv6) goto compat;
s = winsock2errno(socket(PF_INET6,SOCK_STREAM,0));
if (s == -1) {
if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPFNOSUPPORT || errno == EPROTONOSUPPORT) {
compat:
s=winsock2errno(socket(AF_INET,SOCK_STREAM,0));
noipv6=1;
if (s==-1) return -1;
} else
return -1;
}
#ifdef IPV6_V6ONLY
{
int zero=0;
winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
}
#endif
int socket_tcp6(void) {
int s=socket_tcp6b();
if (ndelay_on(s) == -1) { close(s); return -1; }
return s;
#else
return socket_tcp4();
#endif
}


+ 26
- 0
socket/socket_tcp6b.3 View File

@@ -0,0 +1,26 @@
.TH socket_tcp6b 3
.SH NAME
socket_tcp6b \- create a blocking IPv6 TCP/IP stream socket
.SH SYNTAX
.B #include <socket.h>

int \fBsocket_tcp6b\fP();
.SH DESCRIPTION
socket_tcp6b creates a blocking IPv6 TCP/IP stream socket and returns a
file descriptor pointing to that socket. If something goes wrong,
socket_tcp6b returns -1, setting errno appropriately, without allocating
any resources.

.SH EXAMPLE
#include <socket.h>

int \fIs\fR;
char \fIip\fR[16];
uint16 \fIp\fR;

\fIs\fR = socket_tcp6b();
socket_bind6(s,ip,p);
socket_connect6(s,ip,p,0);

.SH "SEE ALSO"
socket_tcp6(3), socket_bind4(3), socket_bind6(3)

+ 51
- 0
socket/socket_tcp6b.c View File

@@ -0,0 +1,51 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "haveip6.h"
#include "socket.h"
#include "ndelay.h"

#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT EINVAL
#endif
#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT EAFNOSUPPORT
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT EAFNOSUPPORT
#endif

int socket_tcp6b(void)
{
#ifdef LIBC_HAS_IP6
int s;

__winsock_init();
if (noipv6) goto compat;
s = winsock2errno(socket(PF_INET6,SOCK_STREAM,0));
if (s == -1) {
if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPFNOSUPPORT || errno == EPROTONOSUPPORT) {
compat:
s=winsock2errno(socket(AF_INET,SOCK_STREAM,0));
noipv6=1;
if (s==-1) return -1;
} else
return -1;
}
#ifdef IPV6_V6ONLY
{
int zero=0;
winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
}
#endif
return s;
#else
return socket_tcp4b();
#endif
}


+ 2
- 0
test/uudecode.c View File

@@ -256,6 +256,8 @@ foundfilename:
}
if (state==AFTERBEGIN)
state=SKIPHEADER;
else if (state==SKIPHEADER)
state=AFTERBEGIN;
} else if (str_start(line,"=ybegin ")) {
char* filename=strstr(line," name=");
if (!filename) {


+ 4
- 0
tryalloca.c View File

@@ -1,5 +1,9 @@
#include <stdlib.h>
#ifdef A
#include <alloca.h>
#else
#include <malloc.h>
#endif

main() {
char* c=alloca(23);


Loading…
Cancel
Save