Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

test_udp.c File Reference

#include "gwlib/gwlib.h"
#include <string.h>

Include dependency graph for test_udp.c:

Include dependency graph

Go to the source code of this file.

Defines

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

Functions

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

Variables

char usage []


Define 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.


Function Documentation

void client int  port  )  [static]
 

Definition at line 77 of file test_udp.c.

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

Referenced by main().

00077                              {
00078     int i, s;
00079     Octstr *ping, *pong, *addr, *from;
00080     
00081     s = udp_client_socket();
00082     ping = octstr_create(PING);
00083     addr = udp_create_address(octstr_create("localhost"), port);
00084     if (s == -1 || addr == NULL)
00085         panic(0, "Couldn't set up client socket.");
00086 
00087     for (i = 0; i < TIMES; ++i) {
00088         if (udp_sendto(s, ping, addr) == -1)
00089             panic(0, "Couldn't send ping.");
00090         if (udp_recvfrom(s, &pong, &from) == -1)
00091             panic(0, "Couldn't receive pong");
00092         info(0, "Got <%s> from <%s:%d>", octstr_get_cstr(pong),
00093             octstr_get_cstr(udp_get_ip(from)), 
00094             udp_get_port(from));
00095     }
00096 }

Here is the call graph for this function:

int main int  argc,
char **  argv
 

Definition at line 118 of file test_udp.c.

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

00118                                 {
00119     int port;
00120     
00121     gwlib_init();
00122 
00123     if (argc != 3)
00124         panic(0, "Bad argument list\n%s", usage);
00125     
00126     port = atoi(argv[2]);
00127 
00128     if (strcmp(argv[1], "client") == 0)
00129         client(port);
00130     else
00131         server(port);
00132     return 0;
00133 }

Here is the call graph for this function:

void server int  port  )  [static]
 

Definition at line 98 of file test_udp.c.

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

Referenced by main().

00098                              {
00099     int i, s;
00100     Octstr *ping, *pong, *from;
00101     
00102     s = udp_bind(port,"0.0.0.0");
00103     pong = octstr_create(PONG);
00104     if (s == -1)
00105         panic(0, "Couldn't set up client socket.");
00106 
00107     for (i = 0; i < TIMES; ++i) {
00108         if (udp_recvfrom(s, &ping, &from) == -1)
00109             panic(0, "Couldn't receive ping");
00110         info(0, "Got <%s> from <%s:%d>", octstr_get_cstr(ping),
00111             octstr_get_cstr(udp_get_ip(from)), 
00112             udp_get_port(from));
00113         if (udp_sendto(s, pong, from) == -1)
00114             panic(0, "Couldn't send pong.");
00115     }
00116 }

Here is the call graph for this function:


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.