summaryrefslogtreecommitdiff
path: root/src/net/tcp.c
diff options
context:
space:
mode:
authorDusan Durech <dusan@debian.debian>2009-03-01 18:09:11 +0100
committerDusan Durech <dusan@debian.debian>2009-03-01 18:09:11 +0100
commitb21832e8d922351169ab4d06e7993ed401fe0924 (patch)
tree882f8d3deb61ea8a4586a06c9c5cb5f2e8206054 /src/net/tcp.c
parent0fe84801e04022b1c92de363ec907fa6dd63bfd2 (diff)
API to UDP and TCP has been modified so that they can be used independet from protocols IPv4 and IPv6
Diffstat (limited to 'src/net/tcp.c')
-rw-r--r--src/net/tcp.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/net/tcp.c b/src/net/tcp.c
index d8a40d8..c52e467 100644
--- a/src/net/tcp.c
+++ b/src/net/tcp.c
@@ -21,13 +21,12 @@
#include "tcp.h"
-sock_tcp_t *newSockTcp(int proto)
+sock_tcp_t *newSockTcp(void)
{
sock_tcp_t *new;
new = malloc(sizeof(sock_tcp_t));
memset(new, 0, sizeof(sock_tcp_t));
- new->proto = proto;
return new;
}
@@ -38,7 +37,16 @@ void destroySockTcp(sock_tcp_t * p)
free(p);
}
-sock_tcp_t *bindTcpSocket(char *address, int port, int proto)
+static int getProto(char *str)
+{
+ if( strstr(str, ".") != NULL )return PROTO_TCPv4;
+ if( strstr(str, ":") != NULL )return PROTO_TCPv6;
+
+ assert( ! "Protocol not detected !" );
+ return -1;
+}
+
+sock_tcp_t *bindTcpSocket(char *address, int port)
{
sock_tcp_t *new;
unsigned long param_setsock = 1;
@@ -47,7 +55,8 @@ sock_tcp_t *bindTcpSocket(char *address, int port, int proto)
assert(port > 0 && port < 65535);
- new = newSockTcp(proto);
+ new = newSockTcp();
+ new->proto = getProto(address);
ret = -1; // no Warnings
assert(new != NULL);
@@ -110,7 +119,8 @@ sock_tcp_t *getTcpNewClient(sock_tcp_t * p)
assert(p != NULL);
assert(p->sock >= 0);
- new = newSockTcp(p->proto);
+ new = newSockTcp();
+ new->proto = p->proto;
if (new->proto == PROTO_TCPv4) {
client_len = sizeof(new->sockAddr);
@@ -170,7 +180,7 @@ int getSockTcpPort(sock_tcp_t * p)
return -1;
}
-sock_tcp_t *connectTcpSocket(char *ip, int port, int proto)
+sock_tcp_t *connectTcpSocket(char *ip, int port)
{
sock_tcp_t *new;
int len;
@@ -179,7 +189,8 @@ sock_tcp_t *connectTcpSocket(char *ip, int port, int proto)
assert(ip != NULL);
assert(port > 0 && port < 65535);
- new = newSockTcp(proto);
+ new = newSockTcp();
+ new->proto = getProto(ip);
ret = -1; // no Warnnings
if (new->proto == PROTO_TCPv4) {