Revision 306304a2
Added by Hamish Coleman over 16 years ago
- ID 306304a2643096d2d198838309ea77acb53aede6
wconsd.c | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
|
||
#define VERSION "0.2.3"
|
||
#define VERSION "0.2.4"
|
||
|
||
/* Size of buffers for send and receive */
|
||
#define BUFSIZE 1024
|
||
... | ... | |
return 8;
|
||
}
|
||
|
||
if (gethostname((char *)hostname,sizeof(hostname))==SOCKET_ERROR) {
|
||
*specificError=WSAGetLastError();
|
||
return 1;
|
||
}
|
||
dprintf(1,"wconsd: Hostname is %s\n",hostname);
|
||
|
||
host_entry=gethostbyname((char *)hostname);
|
||
if (host_entry->h_addrtype==AF_INET) {
|
||
dprintf(1,"wconsd: IP Address is %s\n",inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list));
|
||
/* FIXME - enumerate all the IP addresses from the list */
|
||
} else {
|
||
host_entry=0;
|
||
return 0;
|
||
}
|
||
|
||
/* Create a socket to listen for connections. */
|
||
memset(&sin,0,sizeof(sin));
|
||
sin.sin_family=AF_INET;
|
||
... | ... | |
*specificError=WSAGetLastError();
|
||
return 11;
|
||
}
|
||
dprintf(1,"wconsd: listening on port %i\n",default_tcpport);
|
||
|
||
|
||
/* Mark the socket as non-blocking */
|
||
if (WSAEventSelect(ls,listenSocketEvent,FD_ACCEPT)==SOCKET_ERROR) {
|
||
... | ... | |
return 12;
|
||
}
|
||
|
||
if (gethostname((char *)hostname,sizeof(hostname))==SOCKET_ERROR) {
|
||
*specificError=WSAGetLastError();
|
||
return 1;
|
||
}
|
||
dprintf(1,"wconsd: Hostname is %s\n",hostname);
|
||
|
||
host_entry=gethostbyname((char *)hostname);
|
||
if (host_entry->h_addrtype!=AF_INET) {
|
||
host_entry=0;
|
||
return 0;
|
||
}
|
||
|
||
dprintf(1,"wconsd: IP Address is %s\n",inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list));
|
||
/* FIXME - enumerate all the IP addresses from the list */
|
||
|
||
return 0;
|
||
}
|
||
|
||
... | ... | |
tv.tv_sec = 2;
|
||
tv.tv_usec = 0;
|
||
select(0,&s,NULL,NULL,&tv);
|
||
/* TODO - examine the retval for the select */
|
||
size=recv(conn->net,(void*)&buf,BUFSIZE,0);
|
||
if (size==0) {
|
||
closesocket(conn->net);
|
||
... | ... | |
continue;
|
||
}
|
||
if (size==SOCKET_ERROR) {
|
||
/* General paranoia about blocking sockets */
|
||
ioctlsocket(conn->net,FIONBIO,&zero);
|
||
int err = WSAGetLastError();
|
||
switch (err) {
|
||
case WSAEWOULDBLOCK:
|
||
/* ignore */
|
||
continue;
|
||
default:
|
||
dprintf(1,"wconsd[%i]: net_to_com socket error (%i)\n",conn->id,err);
|
||
/* General paranoia about blocking sockets */
|
||
ioctlsocket(conn->net,FIONBIO,&zero);
|
||
}
|
||
continue;
|
||
}
|
||
conn->net_bytes_rx+=size;
|
||
... | ... | |
|
||
unsigned long zero=0;
|
||
fd_set set_read;
|
||
struct timeval tv;
|
||
|
||
/* IAC WILL ECHO */
|
||
/* IAC WILL suppress go ahead */
|
||
... | ... | |
FD_ZERO(&set_read);
|
||
while (conn->menuactive && conn->netconnected) {
|
||
FD_SET(conn->net,&set_read);
|
||
select(conn->net+1,&set_read,NULL,NULL,NULL);
|
||
tv.tv_sec = 2;
|
||
tv.tv_usec = 0;
|
||
select(conn->net+1,&set_read,NULL,NULL,&tv);
|
||
/* TODO - examine the retval for the select */
|
||
size=recv(conn->net,(void*)&buf,BUFSIZE,0);
|
||
|
||
if (size==0) {
|
||
... | ... | |
return;
|
||
}
|
||
if (size==SOCKET_ERROR) {
|
||
dprintf(1,"wconsd[%i]: socket error\n",conn->id);
|
||
/* General paranoia about blocking sockets */
|
||
ioctlsocket(conn->net,FIONBIO,&zero);
|
||
int err = WSAGetLastError();
|
||
switch (err) {
|
||
case WSAEWOULDBLOCK:
|
||
/* ignore */
|
||
continue;
|
||
default:
|
||
dprintf(1,"wconsd[%i]: run_menu socket error (%i)\n",conn->id,WSAGetLastError());
|
||
/* General paranoia about blocking sockets */
|
||
ioctlsocket(conn->net,FIONBIO,&zero);
|
||
}
|
||
continue;
|
||
}
|
||
conn->net_bytes_rx+=size;
|
||
... | ... | |
// We are running in debug mode (or any other command-line mode)
|
||
debug_mode=1;
|
||
|
||
dprintf(1,"\nwconsd: Serial Console server (version %s)\n",VERSION);
|
||
dprintf(1," (see http://wob.zot.org/2/wiki/wconsd for more info)\n\n");
|
||
dprintf(1,"\n"
|
||
"wconsd: Serial Console server (version %s)\n",VERSION);
|
||
dprintf(1,
|
||
" (see http://wob.zot.org/2/wiki/wconsd for more info)\n\n");
|
||
|
||
if (argc>1) {
|
||
if (strcmp(argv[1],"-i")==0) {
|
||
... | ... | |
}
|
||
}
|
||
|
||
dprintf(1,"wconsd: listening on port %i\n",default_tcpport);
|
||
|
||
// if we have decided to run as a console app..
|
||
if (console_application) {
|
||
int r;
|
Also available in: Unified diff
Update run_menu to get it to detect a closed network connection. Also message beautification