fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
socket_udp.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/param.h>
3#include <sys/socket.h>
4#include <netinet/in.h>
5#include <errno.h>
6#include "close.h" /* better use unistd.h ? */
7#include "ndelay.h"
8#include "socket_if.h"
9#include "error.h"
10
11#ifndef EAFNOSUPPORT
12#define EAFNOSUPPORT EINVAL
13#endif
14
22int socket_udp6(void)
23{
24 int s;
25
26 s = socket(AF_INET6,SOCK_DGRAM,0);
27 if (s != -1)
28 if (ndelay_on(s) == -1) { close(s); return -1; }
29
30 return s;
31}
32
33int socket_udp4(void)
34{
35 int s;
36
37 s = socket(AF_INET,SOCK_DGRAM,0);
38 if (s != -1)
39 if (ndelay_on(s) == -1) { close(s); return -1; }
40
41 return s;
42}
43
44int socket_udp(void)
45{
46 int s;
47
48 s = socket(AF_INET6,SOCK_DGRAM,0);
49 if (s == -1)
50 if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPROTO || errno == EPROTONOSUPPORT)
51 s = socket(AF_INET,SOCK_DGRAM,0);
52
53 if (s != -1)
54 if (ndelay_on(s) == -1) { close(s); return -1; }
55
56 return s;
57}
#define EAFNOSUPPORT
Definition: socket_udp.c:12
int socket_udp4(void)
Definition: socket_udp.c:33
int socket_udp6(void)
Definition: socket_udp.c:22
int socket_udp(void)
Definition: socket_udp.c:44
int ndelay_on(int)
Definition: ndelay.c:16
#define EPROTO
Definition: error.h:7
int close(int __fd)