Kannel: Open Source WAP and SMS gateway  svn-r5335
test_udp.c File Reference
#include "gwlib/gwlib.h"
#include <string.h>

Go to the source code of this file.

Macros

#define PING   "ping"
 
#define PONG   "pong"
 
#define TIMES   10
 

Functions

static void client (int port)
 
static void server (int port)
 
int main (int argc, char **argv)
 

Variables

static char usage []
 

Macro Definition Documentation

◆ PING

#define PING   "ping"

Definition at line 73 of file test_udp.c.

Referenced by client().

◆ PONG

#define PONG   "pong"

Definition at line 74 of file test_udp.c.

Referenced by server().

◆ TIMES

#define TIMES   10

Definition at line 75 of file test_udp.c.

Referenced by client(), and server().

Function Documentation

◆ client()

static void client ( int  port)
static

Definition at line 77 of file test_udp.c.

References from, info(), octstr_create, octstr_get_cstr, panic, PING, TIMES, udp_client_socket(), udp_create_address(), udp_get_ip(), udp_get_port(), udp_recvfrom(), and udp_sendto().

Referenced by brunet_receive_sms(), clickatell_receive_sms(), client_destroy(), client_done(), client_thread(), delayed_http_reply(), eq_create_http_request(), fake_listener(), generic_receive_sms(), handle_connect_reply(), handle_get_reply(), handle_reply(), http_accept_request(), http_close_client(), http_method(), http_read_thread(), http_request_url(), http_send_reply(), http_thread(), httpadmin_run(), httpd_emu(), httpd_serve(), httpsmsc_receiver(), increment_tid(), kannel_receive_sms(), main(), main_connection_loop(), pap_event_create(), pap_event_unpack(), pap_request_thread(), port_get_request(), port_match(), port_put_request(), port_remove(), receive_request(), record_disconnect(), run_requests(), send_invoke_connect(), send_invoke_disconnect(), send_invoke_get(), send_pdu(), sendsms_thread(), server_thread(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), start_request(), wdp_create(), and xidris_receive_sms().

77  {
78  int i, s;
79  Octstr *ping, *pong, *addr, *from;
80 
81  s = udp_client_socket();
82  ping = octstr_create(PING);
83  addr = udp_create_address(octstr_create("localhost"), port);
84  if (s == -1 || addr == NULL)
85  panic(0, "Couldn't set up client socket.");
86 
87  for (i = 0; i < TIMES; ++i) {
88  if (udp_sendto(s, ping, addr) == -1)
89  panic(0, "Couldn't send ping.");
90  if (udp_recvfrom(s, &pong, &from) == -1)
91  panic(0, "Couldn't receive pong");
92  info(0, "Got <%s> from <%s:%d>", octstr_get_cstr(pong),
95  }
96 }
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: http.c:2014
#define PING
Definition: test_udp.c:73
int udp_get_port(Octstr *addr)
Definition: socket.c:547
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Octstr * from
Definition: mtbatch.c:95
int udp_client_socket(void)
Definition: socket.c:464
#define TIMES
Definition: test_udp.c:75
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
#define panic
Definition: log.h:87
int udp_sendto(int s, Octstr *datagram, Octstr *addr)
Definition: socket.c:567
int udp_recvfrom(int s, Octstr **datagram, Octstr **addr)
Definition: socket.c:582
Octstr * udp_create_address(Octstr *host_or_ip, int port)
Definition: socket.c:517
Octstr * udp_get_ip(Octstr *addr)
Definition: socket.c:557

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 118 of file test_udp.c.

References client(), gwlib_init(), panic, port, server(), and usage.

118  {
119  int port;
120 
121  gwlib_init();
122 
123  if (argc != 3)
124  panic(0, "Bad argument list\n%s", usage);
125 
126  port = atoi(argv[2]);
127 
128  if (strcmp(argv[1], "client") == 0)
129  client(port);
130  else
131  server(port);
132  return 0;
133 }
Definition: http.c:2014
static void client(int port)
Definition: test_udp.c:77
static int port
Definition: fakesmsc.c:121
static char usage[]
Definition: test_udp.c:68
static void server(int port)
Definition: test_udp.c:98
#define panic
Definition: log.h:87
void gwlib_init(void)
Definition: gwlib.c:78

◆ server()

static void server ( int  port)
static

Definition at line 98 of file test_udp.c.

References from, info(), octstr_create, octstr_get_cstr, panic, PONG, TIMES, udp_bind(), udp_get_ip(), udp_get_port(), udp_recvfrom(), and udp_sendto().

Referenced by main().

98  {
99  int i, s;
100  Octstr *ping, *pong, *from;
101 
102  s = udp_bind(port,"0.0.0.0");
103  pong = octstr_create(PONG);
104  if (s == -1)
105  panic(0, "Couldn't set up client socket.");
106 
107  for (i = 0; i < TIMES; ++i) {
108  if (udp_recvfrom(s, &ping, &from) == -1)
109  panic(0, "Couldn't receive ping");
110  info(0, "Got <%s> from <%s:%d>", octstr_get_cstr(ping),
112  udp_get_port(from));
113  if (udp_sendto(s, pong, from) == -1)
114  panic(0, "Couldn't send pong.");
115  }
116 }
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: http.c:2014
int udp_get_port(Octstr *addr)
Definition: socket.c:547
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Octstr * from
Definition: mtbatch.c:95
int udp_bind(int port, const char *source_addr)
Definition: socket.c:478
#define TIMES
Definition: test_udp.c:75
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
#define PONG
Definition: test_udp.c:74
#define panic
Definition: log.h:87
int udp_sendto(int s, Octstr *datagram, Octstr *addr)
Definition: socket.c:567
int udp_recvfrom(int s, Octstr **datagram, Octstr **addr)
Definition: socket.c:582
Octstr * udp_get_ip(Octstr *addr)
Definition: socket.c:557

Variable Documentation

◆ usage

char usage[]
static
Initial value:
= "\
Usage: test_udp client server_port\n\
test_udp server server_port\n\
"

Definition at line 68 of file test_udp.c.

Referenced by main().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.