diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 13:02:45 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 13:02:45 +0200 |
commit | 96cf8dffe4f7b0b910f790066ae622dc429eb522 (patch) | |
tree | cc1343a0ac92bb4836cae2dd63a97fa045765e7f /socket_udp.c |
initial commit of version 23fehQlibs-23
Diffstat (limited to 'socket_udp.c')
-rw-r--r-- | socket_udp.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/socket_udp.c b/socket_udp.c new file mode 100644 index 0000000..743cdf1 --- /dev/null +++ b/socket_udp.c @@ -0,0 +1,57 @@ +#include <sys/types.h> +#include <sys/param.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> +#include "close.h" /* better use unistd.h ? */ +#include "ndelay.h" +#include "socket_if.h" +#include "error.h" + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT EINVAL +#endif + +/** + @file socket_udp.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief setup a UDP message socket +*/ + +int socket_udp6(void) +{ + int s; + + s = socket(AF_INET6,SOCK_DGRAM,0); + if (s != -1) + if (ndelay_on(s) == -1) { close(s); return -1; } + + return s; +} + +int socket_udp4(void) +{ + int s; + + s = socket(AF_INET,SOCK_DGRAM,0); + if (s != -1) + if (ndelay_on(s) == -1) { close(s); return -1; } + + return s; +} + +int socket_udp(void) +{ + int s; + + s = socket(AF_INET6,SOCK_DGRAM,0); + if (s == -1) + if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPROTO || errno == EPROTONOSUPPORT) + s = socket(AF_INET,SOCK_DGRAM,0); + + if (s != -1) + if (ndelay_on(s) == -1) { close(s); return -1; } + + return s; +} |