Subversion Repositories SvarDOS

Rev

Rev 329 | Rev 616 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*
2
 * This file is part of the pkgnet package - the SvarDOS package manager.
3
 * Copyright (C) Mateusz Viste 2013-2021
4
 */
5
 
6
 
7
#ifndef libtcp_hdr
8
#define libtcp_hdr
9
 
333 mateuszvis 10
struct net_tcpsocket; /* opaque struct, exact implementation in net.c */
207 mateuszvis 11
 
12
/* resolves name and fills resovled addr into ip. returns 0 on success. */
13
int net_dnsresolve(char *ip, const char *name);
14
 
15
/* must be called before using libtcp. returns 0 on success, or non-zero if network subsystem is not available. */
16
int net_init(void);
17
 
18
/* initiates a connection to an IP host and returns a socket pointer (or NULL
19
 * on error) - note that connection is NOT established at this point!
20
 * use net_isconnected() to know when the connection is connected. */
21
struct net_tcpsocket *net_connect(const char *ip, unsigned short port);
22
 
23
/* checks whether or not a socket is connected. returns:
24
 *  0 = not connected,
25
 *  1 = connected
329 mateuszvis 26
 * -1 = error */
27
int net_isconnected(struct net_tcpsocket *s);
207 mateuszvis 28
 
29
/* Sends data on socket 'socket'.
30
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(). */
329 mateuszvis 31
int net_send(struct net_tcpsocket *socket, const void *line, long len);
207 mateuszvis 32
 
33
/* 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.
34
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(). */
329 mateuszvis 35
int net_recv(struct net_tcpsocket *socket, void *buff, long maxlen);
207 mateuszvis 36
 
37
/* Close the 'sock' socket. */
38
void net_close(struct net_tcpsocket *socket);
39
 
40
/* Returns an info string about the networking engine being used */
41
const char *net_engine(void);
42
 
43
#endif