Subversion Repositories SvarDOS

Rev

Rev 885 | Rev 1133 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 885 Rev 1132
1
/*
1
/*
2
 * This file is part of the pkgnet package - the SvarDOS package manager.
2
 * This file is part of the pkgnet package - the SvarDOS package manager.
3
 * Copyright (C) Mateusz Viste 2013-2021
3
 * Copyright (C) Mateusz Viste 2013-2021
4
 */
4
 */
5
 
5
 
6
 
6
 
7
#ifndef libtcp_hdr
7
#ifndef libtcp_hdr
8
#define libtcp_hdr
8
#define libtcp_hdr
9
 
9
 
10
struct net_tcpsocket; /* opaque struct, exact implementation in net.c */
10
struct net_tcpsocket; /* opaque struct, exact implementation in net.c */
11
 
11
 
12
/* resolves name and fills resovled addr into ip. on failure it retries r times
12
/* resolves name and fills resovled addr into ip. on failure it retries r times
13
 * (r=0 means "try only once"). returns 0 on success. */
13
 * (r=0 means "try only once"). returns 0 on success. */
14
int net_dnsresolve(char *ip, const char *name, int r);
14
int net_dnsresolve(char *ip, const char *name, int r);
15
 
15
 
16
/* must be called before using libtcp. returns 0 on success, or non-zero if network subsystem is not available. */
16
/* must be called before using libtcp. returns 0 on success, or non-zero if network subsystem is not available. */
17
int net_init(void);
17
int net_init(void);
18
 
18
 
19
/* initiates a connection to an IP host and returns a socket pointer (or NULL
19
/* initiates a connection to an IP host and returns a socket pointer (or NULL
20
 * on error) - note that connection is NOT established at this point!
20
 * on error) - note that connection is NOT established at this point!
21
 * use net_isconnected() to know when the connection is connected. */
21
 * use net_isconnected() to know when the connection is connected.
-
 
22
 * buffsz is the size of the TCP buffer that will be allocated by net_connect. */
22
struct net_tcpsocket *net_connect(const char *ip, unsigned short port);
23
struct net_tcpsocket *net_connect(const char *ip, unsigned short port, unsigned short buffsz);
23
 
24
 
24
/* checks whether or not a socket is connected. returns:
25
/* checks whether or not a socket is connected. returns:
25
 *  0 = not connected,
26
 *  0 = not connected,
26
 *  1 = connected
27
 *  1 = connected
27
 * -1 = error */
28
 * -1 = error */
28
int net_isconnected(struct net_tcpsocket *s);
29
int net_isconnected(struct net_tcpsocket *s);
29
 
30
 
30
/* Sends data on socket 'socket'.
31
/* Sends data on socket 'socket'.
31
Returns the number of bytes sent on success, and <0 otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
32
Returns the number of bytes sent on success, and <0 otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
32
int net_send(struct net_tcpsocket *socket, const void *line, long len);
33
int net_send(struct net_tcpsocket *socket, const void *line, long len);
33
 
34
 
34
/* Reads data from socket 'sock' and write it into buffer 'buff', until end of connection. Will fall into error if the amount of data is bigger than 'maxlen' bytes.
35
/* Reads data from socket 'sock' and write it into buffer 'buff', until end of connection. Will fall into error if the amount of data is bigger than 'maxlen' bytes.
35
Returns the amount of data read (in bytes) on success, or a negative value otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
36
Returns the amount of data read (in bytes) on success, or a negative value otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
36
int net_recv(struct net_tcpsocket *socket, void *buff, long maxlen);
37
int net_recv(struct net_tcpsocket *socket, void *buff, long maxlen);
37
 
38
 
38
/* Close the 'sock' socket. */
39
/* Close the 'sock' socket. */
39
void net_close(struct net_tcpsocket *socket);
40
void net_close(struct net_tcpsocket *socket);
40
 
41
 
41
/* Returns an info string about the networking engine being used */
42
/* Returns an info string about the networking engine being used */
42
const char *net_engine(void);
43
const char *net_engine(void);
43
 
44
 
44
#endif
45
#endif
45
 
46