94 #include <sys/types.h> 131 typedef struct _udpc {
161 msg->wdp_datagram.source_address,
162 msg->wdp_datagram.source_port,
163 msg->wdp_datagram.destination_address,
164 msg->wdp_datagram.destination_port);
165 dgram->
u.T_DUnitdata_Ind.user_data =
192 error(0,
"dgram is null");
207 debug(
"wap.proxy",0,
"datagram contains %ld events", n);
219 debug(
"",0,
"datagram is for WTP responder");
222 debug(
"",0,
"datagram is for WTP initiator");
287 Octstr *datagram, *cliaddr;
309 error(errno,
"Failed to receive an UDP");
320 msg->wdp_datagram.user_data = datagram;
322 info(0,
"datagram received <%s:%d> -> <%s:%d>",
358 msg->wdp_datagram.destination_port);
361 error(0,
"could not send UDP datagram");
378 info(0,
"sending datagram <%s:%ld> -> <%s:%ld>",
380 msg->wdp_datagram.source_port,
382 msg->wdp_datagram.destination_port);
410 udpc = gw_malloc(
sizeof(
Udpc));
418 if (udpc->
addr == NULL) {
425 fl = fcntl(udpc->
fd, F_GETFL);
426 fcntl(udpc->
fd, F_SETFL, fl | O_NONBLOCK);
429 debug(
"wap.proxy",0,
"bound to UDP <%s:%d>",
474 error(0,
"Failed to start UDP receiver/sender thread");
490 debug(
"wap.proxy", 0,
"starting UDP sender/receiver module");
543 msg->wdp_datagram.source_address =
545 msg->wdp_datagram.source_port =
msg->wdp_datagram.destination_port;
549 panic(0,
"Could not find UDP mapping, internal error");
565 panic(0,
"Could not find main inbound UDP socket, internal error");
600 info(0,
"Creating UDP mapping <%s:%ld> <-> <%s:%ld>",
602 msg->wdp_datagram.source_port,
604 msg->wdp_datagram.source_port*2);
607 msg->wdp_datagram.source_port);
612 panic(0,
"Could not find UDP mapping, internal error");
638 debug(
"bb.thread", 0,
"udp_shutdown: Starting avalanche");
653 debug(
"bb.udp", 0,
"udp_die: removing producers from udp-lists");
719 info(0,
"Usage: wapproxy [options] host ...");
720 info(0,
"where host is the real wap gw to forward to and options are:");
721 info(0,
"-v number");
722 info(0,
" set log level for stderr logging");
723 info(0,
"-i interface");
724 info(0,
" bind to the given interface for UDP server port (default: 0.0.0.0)");
726 info(0,
" bind to the given port for UDP server port (default: 9201)");
728 info(0,
" dump WDP/UDP packets, msg_dump()");
730 info(0,
" dump WAP event packets, wap_event_dump()");
732 info(0,
" dump WTP PDUs, wtp_pdu_dump()");
736 int main(
int argc,
char **argv)
745 while ((opt =
getopt(argc, argv,
"v:meti:p:")) != EOF) {
778 error(0,
"Invalid option %c", opt);
780 panic(0,
"Stopping.");
811 debug(
"bb", 0,
"starting WDP routers");
813 panic(0,
"Failed to start a new thread for inbound WDP routing");
815 panic(0,
"Failed to start a new thread for outbound WDP routing");
void msg_dump(Msg *msg, int level)
void error(int err, const char *fmt,...)
List * wtp_unpack_wdp_datagram(WAPEvent *datagram)
void info(int err, const char *fmt,...)
static Udpc * udpc_find_mapping(Msg *msg, int inbound)
static int udp_start(Cfg *cfg)
static void wtp_event_dump(Msg *msg)
gw_assert(wtls_machine->packet_to_send !=NULL)
void counter_destroy(Counter *counter)
void gwlist_append(List *list, void *item)
static void wdp_event_dump(Msg *msg)
static void dump(Msg *msg)
void gwlist_produce(List *list, void *item)
void gwthread_join(long thread)
static int udp_addwdp_from_server(Msg *msg)
long gwlist_len(List *list)
int udp_get_port(Octstr *addr)
void * gwlist_get(List *list, long pos)
int main(int argc, char **argv)
#define octstr_get_cstr(ostr)
void wap_event_dump(WAPEvent *event)
unsigned long counter_increase(Counter *counter)
void gwlist_unlock(List *list)
int getopt(int argc, char **argv, char *opts)
static void udpc_destroy(Udpc *udpc)
static int udp_shutdown(void)
int udp_bind(int port, const char *source_addr)
Counter * counter_create(void)
static int udp_addwdp_from_client(Msg *msg)
void * gwlist_extract_first(List *list)
void log_set_output_level(enum output_level level)
void gwlist_remove_producer(List *list)
int wtp_event_is_for_responder(WAPEvent *event)
static volatile sig_atomic_t udp_running
#define octstr_duplicate(ostr)
const char * wap_event_name(WAPEventName type)
void msg_destroy(Msg *msg)
#define wap_event_create(type)
static void udp_receiver(void *arg)
void octstr_destroy(Octstr *ostr)
#define gwthread_create(func, arg)
#define octstr_create(cstr)
void gwthread_sleep(double seconds)
static WAPEvent * wdp_msg2event(Msg *msg)
void gwlist_lock(List *list)
void report_versions(const char *boxname)
void * gwlist_consume(List *list)
int read_available(int fd, long wait_usec)
Counter * outgoing_wdp_counter
static int send_udp(int fd, Msg *msg)
static void wdp_router(void *arg)
void debug(const char *place, int err, const char *fmt,...)
void gwthread_wakeup(long thread)
WAPAddrTuple * wap_addr_tuple_create(Octstr *rmt_addr, long rmt_port, Octstr *lcl_addr, long lcl_port)
void gwlib_shutdown(void)
static void udp_sender(void *arg)
int udp_sendto(int s, Octstr *datagram, Octstr *addr)
Counter * incoming_wdp_counter
static Octstr * interface_name
static void service_router(void *arg)
void gwlist_add_producer(List *list)
static Udpc * udpc_create(int port, char *interface_name, Octstr *map_addr)
static XMLRPCDocument * msg
static int add_service(int port, char *interface_name, Octstr *map_addr)
int udp_recvfrom(int s, Octstr **datagram, Octstr **addr)
void wap_event_destroy(WAPEvent *event)
Octstr * udp_create_address(Octstr *host_or_ip, int port)
Octstr * udp_get_ip(Octstr *addr)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)