diff --git a/net/p2pnet.h b/net/p2pnet.h index 5f88635..1de67b5 100644 --- a/net/p2pnet.h +++ b/net/p2pnet.h @@ -7,6 +7,10 @@ int socket_local4(int s, uint32_t *ip, uint16_t *port); int socket_connect4(int s, uint32_t ip, uint16_t port); int socket_listen(int s, uint32_t *localip, uint16_t *localport); + ssize_t socket_read(int s, char *buf, size_t len, int flags); + ssize_t socket_write(int s, char *buf, size_t len, int flags); int socket_tcp4(void); + + int socket_stream_sctp4(void); #endif // P2PNET_H diff --git a/net/sctp.c b/net/sctp.c new file mode 100644 index 0000000..0ebbe7a --- /dev/null +++ b/net/sctp.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include "p2pnet.h" + +/* Create a SCTP socket. + */ +int socket_stream_sctp4(void) +{ + int s; + + s = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (s == -1) return -1; + return s; +} diff --git a/net/socket.c b/net/socket.c index 3c1867f..7c7f476 100644 --- a/net/socket.c +++ b/net/socket.c @@ -96,3 +96,19 @@ int socket_listen(int s, uint32_t *localip, uint16_t *localport) } return s; } + +/* Reads data from a socket, used instead of recv so if a protocol needs + * to use something else before or after it can be done here instead of + * outside the lib. + */ +ssize_t socket_read(int s, char *buf, size_t len, int flags) +{ + return recv(s, buf, len, flags); +} + +/* Same reason as socket_read, but to send data instead of receive. + */ +ssize_t socket_write(int s, char *buf, size_t len, int flags) +{ + return send(s, buf, len, flags); +}