1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
/* Lac - Library for asynchronous communication
* Copyright (C) 2002 Søren Sandmann (sandmann@daimi.au.dk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <lac.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
int i;
GMainLoop *main_loop;
gchar buffer[5000];
LacAddress *addr;
GError *err = NULL;
int fd;
addr = lac_address_new_from_localhost_wait (NULL, NULL);
if (!addr)
{
g_print ("can't find local IP address \n");
}
else
{
char *str = lac_address_to_string (addr);
g_print ("local IP address is: %s\n", str);
g_free (str);
}
addr = lac_address_new_from_a_b_c_d (130, 225, 18, 72);
fd = lac_socket_udp (NULL);
if (!lac_connect (fd, addr, 53, &err))
{
g_print ("connect: %s\n", err->message);
exit (1);
}
else
g_print ("connect ok (to %s)\n", lac_address_to_string (addr));
#define MSG "asd jkl;faqpwoe8rusjldklsdf jklajks ls jkf ljkasdf jlsdfsdfa j"
i = lac_send (fd, MSG, strlen (MSG), &err);
if (err)
{
g_print ("send: %s\n", err->message);
exit (1);
}
g_print ("sent %d\n", i);
i = lac_recv (fd, buffer, sizeof (buffer), &err);
if (err)
{
g_print ("recv: %s\n", err->message);
exit (1);
}
else
{
if (i == 0)
g_print ("i == 0\n");
else
while (i > 0)
printf ("%c", buffer[i--]);
g_print ("\n");
}
lac_close (fd, &err);
return 0;
}
|