ia64/xen-unstable

view tools/misc/xen_read_console.c @ 733:7192aa19b83c

bitkeeper revision 1.435 (3f69af50wevcD9qxxa6gtfBJnXEBEw)

Merge labyrinth.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into labyrinth.cl.cam.ac.uk:/auto/anfs/scratch/labyrinth/iap10/xeno-clone/xeno.bk
author iap10@labyrinth.cl.cam.ac.uk
date Thu Sep 18 13:12:48 2003 +0000 (2003-09-18)
parents 115b02b108a1 63f8f6b56437
children b644fab116b4
line source
1 /******************************************************************************
2 * Test program for reading console lines from DOM0 port 666.
3 */
5 #include <arpa/inet.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
12 int main(void)
13 {
14 unsigned char buf[208], abuf[32];
15 struct sockaddr_in addr, from;
16 int fromlen = sizeof(from);
17 int len, fd = socket(PF_INET, SOCK_DGRAM, 0);
19 if ( fd < 0 )
20 {
21 fprintf(stderr, "could not open datagram socket\n");
22 return -1;
23 }
25 memset(&addr, 0, sizeof(addr));
26 addr.sin_addr.s_addr = htonl(0xa9fe0100); /* 169.254.1.0 */
27 addr.sin_port = htons(666);
28 addr.sin_family = AF_INET;
29 if ( bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0 )
30 {
31 fprintf(stderr, "could not bind to local address and port\n");
32 return -1;
33 }
35 while ( (len = recvfrom(fd, buf, sizeof(buf), 0,
36 (struct sockaddr *)&from, &fromlen))
37 >= 0 )
38 {
39 #if 0
40 printf("%d-byte message from %s:%d --\n", len,
41 inet_ntop(AF_INET, &from.sin_addr, abuf, sizeof(abuf)),
42 ntohs(from.sin_port));
43 #endif
44 /* For sanity, clean up the string's tail. */
45 if ( buf[len-1] != '\n' ) { buf[len] = '\n'; len++; }
46 buf[len] = '\0';
48 printf("[%d] %s", ntohs(from.sin_port),buf);
50 fromlen = sizeof(from);
51 }
53 return 0;
54 }