2015-03-17 00:01:00 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifndef __MINGW32__
|
2006-05-18 06:02:43 +00:00
|
|
|
#include <unistd.h>
|
2015-03-17 00:01:00 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
2001-02-02 17:54:47 +00:00
|
|
|
#include "socket.h"
|
2006-05-18 06:02:43 +00:00
|
|
|
#include "ndelay.h"
|
2015-03-20 03:34:37 +00:00
|
|
|
#include <errno.h>
|
2001-02-02 17:54:47 +00:00
|
|
|
|
|
|
|
int socket_tcp4(void) {
|
2015-03-20 03:34:37 +00:00
|
|
|
int s;
|
2015-03-17 00:01:00 +00:00
|
|
|
#ifdef SOCK_NONBLOCK
|
2015-03-20 03:50:42 +00:00
|
|
|
if ((s=socket(PF_INET,SOCK_STREAM|SOCK_NONBLOCK,IPPROTO_TCP))>-1 || errno!=EINVAL) return s;
|
2015-03-20 03:34:37 +00:00
|
|
|
#endif
|
|
|
|
s=socket_tcp4b();
|
2008-09-10 09:51:26 +00:00
|
|
|
if (s==-1) return -1;
|
2006-05-18 06:02:43 +00:00
|
|
|
if (ndelay_on(s) == -1) { close(s); return -1; }
|
|
|
|
return s;
|
2001-02-02 17:54:47 +00:00
|
|
|
}
|