Split code and renamed socket.h to p2pnet.h

yamux
Jose Marcial Vieira Bisneto 2016-11-10 19:36:42 -03:00
parent b75dda23d7
commit 7a053b3b69
3 changed files with 21 additions and 16 deletions

View File

@ -1,11 +1,12 @@
#ifndef SOCKET_H
#define SOCKET_H
#ifndef P2PNET_H
#define P2PNET_H
int socket_tcp4(void);
int socket_bind4(int s, uint32_t ip, uint16_t port);
int socket_bind4_reuse(int s, uint32_t ip, uint16_t port);
int socket_accept4(int s, uint32_t *ip, uint16_t *port);
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);
#endif
int socket_tcp4(void);
#endif // P2PNET_H

View File

@ -4,18 +4,7 @@
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
#include "socket.h"
/* Create a TCP socket.
*/
int socket_tcp4(void)
{
int s;
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) return -1;
return s;
}
#include "p2pnet.h"
/* associate an IP address with an port to a socket.
* first param is the socket file description

15
net/tcp.c Normal file
View File

@ -0,0 +1,15 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "p2pnet.h"
/* Create a TCP socket.
*/
int socket_tcp4(void)
{
int s;
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) return -1;
return s;
}