libextreme
Mike Machado
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);