Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
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

#define PING   "ping"

Definition at line 73 of file test_udp.c.

Referenced by client().

#define PONG   "pong"

Definition at line 74 of file test_udp.c.

Referenced by server().

#define TIMES   10

Definition at line 75 of file test_udp.c.

Referenced by client(), and server().

Function Documentation

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 client_destroy(), client_thread(), delayed_http_reply(), eq_create_http_request(), fake_listener(), handle_reply(), http_accept_request(), http_read_thread(), http_thread(), httpadmin_run(), httpd_emu(), httpsmsc_receiver(), main(), pap_event_create(), pap_request_thread(), port_get_request(), port_remove(), receive_request(), run_requests(), sendsms_thread(), and server_thread().

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),
94  udp_get_port(from));
95  }
96 }
void info(int err, const char *fmt,...)
Definition: log.c:636
Definition: http.c:1998
#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
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 }
static void client(int port)
Definition: test_udp.c:77
static int port
Definition: fakesmsc.c:120
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
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),
111  octstr_get_cstr(udp_get_ip(from)),
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:636
Definition: http.c:1998
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

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.