#include <sys/param.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <ctype.h>
Include dependency graph for announce.c:
Go to the source code of this file.
Defines | |
#define | PORT 2860 |
Functions | |
int | main (int argc, char *argv[]) |
Variables | |
char * | Name |
char | msg [8192] |
size_t | nmsg |
#define PORT 2860 |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 29 of file announce.c.
References msg, Name, nmsg, and PORT.
00030 { 00031 int s; 00032 int ns; 00033 int foo; 00034 static struct sockaddr_in sin = {AF_INET}; 00035 char *host; 00036 char *inet_ntoa(); 00037 long ct; 00038 int ch; 00039 char *p; 00040 int opt; 00041 00042 // Save program name for error messages. 00043 // 00044 Name = argv[0]; 00045 00046 // Assume PORT, but let command-line override. 00047 // 00048 sin.sin_port = htons((u_short) PORT); 00049 argc--; 00050 argv++; 00051 if (argc > 0) 00052 { 00053 // unless specified on command-line. 00054 // 00055 sin.sin_port = atoi(*argv); 00056 sin.sin_port = htons((u_short) sin.sin_port); 00057 } 00058 00059 // Read in message and translate CRLF/NL to something reasonable. 00060 // 00061 p = msg; 00062 while ( (ch = getchar()) != EOF 00063 && p + 2 < msg + sizeof(msg)) 00064 { 00065 if (ch != '\r') 00066 { 00067 if (ch == '\n') 00068 { 00069 *p++ = '\r'; 00070 } 00071 *p++ = ch; 00072 } 00073 } 00074 *p = '\0'; 00075 nmsg = p - msg; 00076 00077 signal(SIGHUP, SIG_IGN); 00078 s = socket(AF_INET, SOCK_STREAM, 0); 00079 if (s < 0) 00080 { 00081 perror("announce: socket"); 00082 exit(1); 00083 } 00084 opt = 1; 00085 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt)) < 0) 00086 { 00087 perror("setsockopt"); 00088 } 00089 if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) 00090 { 00091 perror("bind"); 00092 exit(1); 00093 } 00094 if ((foo = fork()) != 0) 00095 { 00096 fprintf(stderr, "announce: pid %d running on port %d\n", foo, 00097 ntohs((u_short) sin.sin_port)); 00098 _exit(0); 00099 } 00100 else 00101 { 00102 setpriority(PRIO_PROCESS, getpid(), 10); 00103 } 00104 if (listen(s, 1) < 0) 00105 { 00106 // start listening on port. 00107 // 00108 perror("announce: listen"); 00109 _exit(1); 00110 } 00111 foo = sizeof sin; 00112 for (;;) 00113 { 00114 // loop forever, accepting requests & printing msg. 00115 // 00116 ns = accept(s, (struct sockaddr *)&sin, &foo); 00117 if (ns < 0) 00118 { 00119 perror("announce: accept"); 00120 _exit(1); 00121 } 00122 host = inet_ntoa(sin.sin_addr); 00123 ct = time(0L); 00124 fprintf(stderr, "CONNECTION made from %s at %s", 00125 host, ctime(&ct)); 00126 write(ns, msg, nmsg); 00127 sleep(5); 00128 close(ns); 00129 } 00130 }
char msg[8192] |
Definition at line 26 of file announce.c.
Referenced by do_chopen(), do_comwho_line(), do_edit_msg(), do_prog(), and main().
char* Name |
Definition at line 25 of file announce.c.
Referenced by announce_connect(), announce_disconnect(), check_dead_refs(), check_floating(), CGuests::Create(), create_obj(), db_write_object(), debug_examine(), destroy_obj(), destroy_player(), dflt_from_msg(), did_it(), do_boot(), do_chown(), do_clone(), do_create(), do_decomp(), do_drop(), do_entrances(), do_examine(), do_fixdb(), do_get(), do_icmd(), do_inventory(), do_kill(), do_link(), do_mail_debug(), do_mail_fwd(), do_mail_list(), do_mail_nuke(), do_mail_proof(), do_mail_read(), do_mail_reply(), do_mail_review(), do_mail_stats(), do_malias_adminlist(), do_malias_list(), do_malias_list_all(), do_move(), do_name(), do_newpassword(), do_restart(), do_shutdown(), do_toad(), do_use(), dump_users(), find_connected_name(), FUNCTION(), give_money(), give_thing(), handle_ears(), CGuests::ListAll(), load_player_names(), log_name(), log_type_and_name(), look_contents(), look_exits(), main(), make_namelist(), mem_usage(), Moniker(), mux_exec(), notify_check(), process_command(), process_enter_loc(), process_leave_loc(), send_mail(), show_quota(), shutdownsock(), sweep_check(), tcache_finish(), unparse_boolexp1(), and unparse_object_numonly().
size_t nmsg |