1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | #include <sys/types.h> |
---|
6 | #include <sys/socket.h> |
---|
7 | #include <netinet/in.h> |
---|
8 | |
---|
9 | #include <unistd.h> |
---|
10 | #include <fcntl.h> |
---|
11 | |
---|
12 | int main() |
---|
13 | { |
---|
14 | register int s; |
---|
15 | register int bytes; |
---|
16 | struct sockaddr_in sa; |
---|
17 | //char buffer[BUFSIZ+1]; |
---|
18 | int status = 1; |
---|
19 | char * buffer = malloc(BUFSIZ),//(char)NULL; |
---|
20 | * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='localhost' xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"}; |
---|
21 | |
---|
22 | //fcntl(O_NONBLOCK, F_SETFL, 0); |
---|
23 | //fcntl(O_ASYNC, F_SETFL, 1); |
---|
24 | if ( (s = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) |
---|
25 | { |
---|
26 | perror("socket"); |
---|
27 | return 1; |
---|
28 | } |
---|
29 | |
---|
30 | bzero(&sa, sizeof sa); |
---|
31 | |
---|
32 | sa.sin_family = AF_INET; |
---|
33 | sa.sin_port = htons(5222); |
---|
34 | sa.sin_addr.s_addr = htonl((((((127 << 8) | 0) << 8) | 0) << 8) | 1); |
---|
35 | |
---|
36 | //fcntl(O_NONBLOCK, F_SETFL, 0); |
---|
37 | //fcntl(O_ASYNC, F_SETFL, 1); |
---|
38 | if ( connect(s, (struct sockaddr *)&sa, sizeof sa) < 0 ) |
---|
39 | { |
---|
40 | perror("connect"); |
---|
41 | close(s); |
---|
42 | return 2; |
---|
43 | } |
---|
44 | |
---|
45 | printf("::: %d\n\n\n", fcntl( s, F_SETFL, fcntl( s, F_GETFL ) & ~O_NONBLOCK )); |
---|
46 | |
---|
47 | write(s, xml_connect, sizeof(xml_connect)-1); |
---|
48 | |
---|
49 | while ((bytes = read(s, buffer, 4096)) > 0) |
---|
50 | //bytes = read(s, buffer, 1);//BUFSIZ); |
---|
51 | printf("%s", buffer); |
---|
52 | |
---|
53 | close(s); |
---|
54 | return 0; |
---|
55 | } |
---|