47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51 #include <sys/ioctl.h>
54 #if defined( HAVE_STRINGS_H )
77 int actual = recv(
c, (
char *)buf, (
int)bufsize, 0);
85 *bytesread = (size_t)actual;
108 int actual = send(
c, (
char *)buf, (
int)bufsize, 0);
116 *byteswritten = (size_t)actual;
138 return write(buf, bufsize, byteswritten);
147 size_t bufferSize = bufsize + buf2size;
155 if (!
write(buf, bufsize, byteswritten))
159 size_t buf2written = 0;
160 if (!
write(buf2, buf2size, &buf2written))
164 *byteswritten += buf2written;
169 memcpy(buffer, buf, bufsize);
170 memcpy(buffer + bufsize, buf2, buf2size);
172 int actual = send(
c, buffer, (
int)bufferSize, 0);
182 *byteswritten = (size_t)actual;
199 char *buffer = (
char *)malloc(size);
297 char *hostname = strdup(name);
299 char *portstr = strstr(hostname,
":");
309 int port = atoi(portstr);
317 bool result =
open(hostname, port);
344 phe = gethostbyname(host);
347 bcopy(phe->h_addr, (
char *) &addr.sin_addr,
sizeof(addr.sin_addr));
351 addr.sin_addr.s_addr = inet_addr(host);
353 if (addr.sin_addr.s_addr == INADDR_NONE)
361 addr.sin_port = htons(port);
362 if (connect(
c, (
struct sockaddr *) &addr,
sizeof(addr)) == -1)
468 hostname = strdup(name);
469 portstr = strstr(hostname,
":");
478 port = atoi(portstr);
499 int so_reuseaddr =
false;
509 setsockopt(
s, SOL_SOCKET, SO_REUSEADDR, (
char *)&so_reuseaddr,
510 sizeof(so_reuseaddr));
512 memset(&addr, 0,
sizeof (addr));
514 addr.sin_port = htons(port);
519 addr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
520 if (bind(
s, (
struct sockaddr *) &addr,
sizeof(addr)) == -1)
545 socklen_t sz =
sizeof(addr);
552 int c = accept(
s, (
struct sockaddr *) &addr, &sz);
622 nameLen =
sizeof(addr);
623 rc = getpeername(
c,(
struct sockaddr *)&addr,&nameLen);
628 if (strcmp(
"127.0.0.1", inet_ntoa(addr.sin_addr)) != 0)
SysServerConnection(SysServerStream *s, int socket)
SysServerConnection * connect()
void returnMessageBuffer(void *)
char * getMessageBuffer(size_t size)
bool write(void *buf, size_t bufsize, size_t *byteswritten)
bool read(void *buf, size_t bufsize, size_t *bytesread)
struct sockaddr_in sockaddr_in