Implemented SCTP stream socket.
This commit is contained in:
parent
7a053b3b69
commit
648982793c
3 changed files with 35 additions and 0 deletions
|
@ -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
|
||||
|
|
15
net/sctp.c
Normal file
15
net/sctp.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#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;
|
||||
}
|
16
net/socket.c
16
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue