1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
libextreme
Mike Machado <mike@innercite.com>
libextreme is a set of functions I have made along the way and have decided to share with the world. Make sure libextreme.a is in your LD_LIBRARY_PATH or that you add the -L flag to your linker flags and link to -lextreme.
#include "extreme.h"
char **strparse(char *string, const char *dilim, int *numsections);
Argument 1 is pointer to the string being parsed
Argument 2 is a constant string in which to seperate string by
Argument 3 is the address if an int to put the number of sections string was split into
Returns the address of a two dimensional array of the split parts
Example usage:
char **parts;
int sections;
int idx;
char string[] = "splitJ7othisJ7oup";
parts = newstrparse(string, "J7o", §ions);
for (idx = 0; idx < sections; idx++)
printf("found part %s\n", parts[idx]);
int esock_new(char *hostname, int port);
Argument 1 is string containing the hostname to open a new connection
Argument 2 is the port to connect to hostname on in integer format
Returns a file descriptor to the open socket connection, -1 on error
Example Usage:
int sockfd;
sockfd = esock_new("www.slashdot.org", 80);
char *esock_read(int sockfd);
Argument 1 is the file descriptor of an open socket connection in which to read data from
Returns a pointer to a null terminated string read from the socket
Errors:
ENOMEM: esock_read is unable to allocate memory to hold data from the socket
Example Usage:
char *buffer;
int sockfd;
sockfd = esock_new("www.slashdot.org", 80);
if (sockfd != -1)
buffer = esock_read(sockfd);
int esock_write(int sockfd, char *data);
Argument 1 is the file descriptor of an open socket conection in which to write data to
Returns the number of charactors succesfully written to the socket
Example Usage:
char sendstr[] = "SEND THIS DATA\n";
int sent;
sockfd = esock_new("pop3.mailserver.com", 110);
if (sockfd != -1)
sent = esock_write(sockfd, sendstr);
|