#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netdb.h>
#include <string.h>
#include <pwd.h>
#include <errno.h>
+#include "ipc.h"
-void logoff();
+void logoff(int code);
/*
* If server_is_local is set to nonzero, the client assumes that it is running
int serv_sock;
-u_long inet_addr();
-
-void timeout() {
+void CtdlInternalTCPtimeout(int signum) {
printf("\rConnection timed out.\n");
logoff(3);
}
-int connectsock(host,service,protocol)
-char *host;
-char *service;
-char *protocol; {
+int CtdlInternalTCPConnectSock(char *host, char *service, char *protocol)
+{
struct hostent *phe;
struct servent *pse;
struct protoent *ppe;
}
- signal(SIGALRM,timeout);
+ signal(SIGALRM,CtdlInternalTCPtimeout);
alarm(30);
if (connect(s,(struct sockaddr *)&sin,sizeof(sin))<0) {
* convert service and host entries into a six-byte numeric in the format
* expected by a SOCKS v4 server
*/
-void numericize(buf,host,service,protocol)
-unsigned char buf[];
-char *host;
-char *service;
-char *protocol; {
+void CtdlInternalTCPnumericize(unsigned char *buf, char *host, char *service, char *protocol)
+{
struct hostent *phe;
struct servent *pse;
struct sockaddr_in sin;
/*
* input binary data from socket
*/
-void serv_read(buf,bytes)
-char buf[];
-int bytes; {
+void serv_read(char *buf, int bytes)
+{
int len,rlen;
len = 0;
/*
* send binary to server
*/
-void serv_write(buf, nbytes)
-char buf[];
-int nbytes; {
+void serv_write(char *buf, int nbytes)
+{
int bytes_written = 0;
int retval;
while (bytes_written < nbytes) {
/*
* input string from socket - implemented in terms of serv_read()
*/
-void serv_gets(buf)
-char buf[]; {
+void serv_gets(char *buf)
+{
buf[0] = 0;
do {
buf[strlen(buf) + 1] = 0;
/*
* send line to server - implemented in terms of serv_write()
*/
-void serv_puts(buf)
-char *buf; {
+void serv_puts(char *buf)
+{
/* printf("< %s\n", buf); */
serv_write(buf, strlen(buf));
serv_write("\n", 1);
/*
* attach to server
*/
-void attach_to_server(argc,argv)
-int argc;
-char *argv[]; {
+void attach_to_server(int argc, char **argv)
+{
int a;
char cithost[256]; int host_copied = 0;
char citport[256]; int port_copied = 0;
/* if not using a SOCKS proxy server, make the connection directly */
if (strlen(socks4)==0) {
- serv_sock = connectsock(cithost,citport,"tcp");
+ serv_sock = CtdlInternalTCPConnectSock(cithost,citport,"tcp");
return;
}
/* if using SOCKS, connect first to the proxy... */
- serv_sock = connectsock(socks4,"1080","tcp");
+ serv_sock = CtdlInternalTCPConnectSock(socks4,"1080","tcp");
printf("Connected to SOCKS proxy at %s.\n",socks4);
printf("Attaching to server...\r");
fflush(stdout);
1); /* method = connect */
serv_write(buf,2);
- numericize(buf,cithost,citport,"tcp");
+ CtdlInternalTCPnumericize(buf,cithost,citport,"tcp");
serv_write(buf,6); /* port and address */
p = (struct passwd *) getpwuid(getuid());
/*
* return the file descriptor of the server socket so we can select() on it.
*/
-int getsockfd() {
+int getsockfd(void) {
return serv_sock;
}
/*
* return one character
*/
-char serv_getc() {
+char serv_getc(void) {
char buf[2];
char ch;