00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __NSNET_H
00027 #define __NSNET_H
00028 #include <nsutil.h>
00029
00030 #define CHUNKSIZE 256
00031
00032 #define DEFAULTPORT 8336
00033 #define DEFAULTHOST "localhost"
00034 #define MAXCLIENTS 16
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <sys/types.h>
00046 #include <errno.h>
00047 #include <sys/socket.h>
00048 #include <netinet/in.h>
00049 #include <netdb.h>
00050 #include <arpa/inet.h>
00051 typedef struct hostent *hostent_t;
00052 #define sock_t int
00053 #define rsockaddr_t struct sockaddr_in
00054
00055
00056 struct InputBuffer {
00057 int read_cnt;
00058 int isEOF;
00059 char *read_ptr;
00060 char read_buf[MAXLEN];
00061 };
00062
00063 struct OutputBuffer {
00064 int write_cnt;
00065 char write_buf[MAXLEN];
00066 };
00067
00068 sock_t rsocket(void);
00069 int readline(sock_t fd, char *vptr, size_t maxlen, struct InputBuffer *ib);
00070 const char *stringifyErrorCode(int code);
00071 int rbindAll(sock_t sock_fd);
00072 int writeBytes(sock_t con, const char *buf, int size, struct OutputBuffer *ob);
00073 int writeString(sock_t con, const char *buf, struct OutputBuffer *ob);
00074 int rconnectName(sock_t sock_fd, const char *hostname, unsigned short portno);
00075 int rinitNetworking(void);
00076 sock_t raccept(sock_t sock_fd);
00077 void setblocking(sock_t sock_fd);
00078 void setnonblocking(sock_t sock_fd);
00079 void rshutdown(sock_t fd);
00081 int getResponseCode(sock_t sock_fd, struct InputBuffer *);
00082 int getOK(sock_t sock_fd, struct InputBuffer *);
00083 int rrecv(sock_t fd, char *read_buf, size_t count);
00084 void initInputBuffer(struct InputBuffer *ib);
00085 void initOutputBuffer(struct OutputBuffer *ob);
00086 int isEOF(sock_t con, const struct InputBuffer *ib);
00087 int inputBufferEmpty(const struct InputBuffer *ib);
00088 int my_read(sock_t fd, char *ptr, size_t maxlen, struct InputBuffer *);
00089 size_t readlinebuf(void **vptrptr, struct InputBuffer *);
00090 size_t writen(sock_t fd, const void *vptr, size_t len, struct OutputBuffer *ob);
00091 size_t readn(sock_t fd, void *vptr, size_t len, struct InputBuffer *ib);
00092 int rselect(sock_t max_fd, fd_set *read, fd_set *write, fd_set *err);
00093 int rselect_timed(sock_t max_fd, fd_set *toread, fd_set *towrite,
00094 fd_set *toerr, struct timeval *tv);
00096 int findFdIndex(sock_t fd);
00097 #endif