-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.c
executable file
·91 lines (71 loc) · 2.31 KB
/
backend.c
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
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <cups/cups.h>
#include <errno.h>
int main(int argc,char *argv[])
{
unsigned char *buf;
FILE *fp;
int sockfd;
char readbuf[1024];
struct sockaddr_in server_addr;
struct hostent *host;
int portnumber,nbytes;
clock_t start_16, end_16;
/*
if(argc==1)
{
printf("network pcl://127.0.0.1:10000 \"BayerPcl\" \"BayerPcl\"");
return(0);
}
*/
char scheme[255], /* Scheme in URI */
hostname[1024], /* Hostname */
username[255], /* Username info (not used) */
resource[1024], /* Resource info (not used) */
*deviceuri;
int port; /* Port number */
if (freopen("/tmp/uri.txt", "wb", stderr)==NULL)
fprintf(stderr, "error redirecting stderr\n");
fp=fopen("/tmp/bke.txt","wb+");
//»ñÈ¡URI
deviceuri=getenv("DEVICE_URI");
fprintf(stderr, "Printer URI: %d\n", deviceuri);
httpSeparateURI(HTTP_URI_CODING_ALL, deviceuri, scheme, sizeof(scheme),
username, sizeof(username), hostname, sizeof(hostname), &port,
resource, sizeof(resource));
fprintf(stderr, "URI RESULT:\n scheme: %s\n username: %s\n hostname:%s\n port:%d\n resource:%s\n\n",
scheme, username, hostname, port, resource );
buf = (unsigned char*)malloc(1024*64);
if((sockfd=socket(AF_INET,SOCK_STREAM,0))== -1)
{
fprintf(stderr,"Socket Error:%s\a\n",strerror(errno));
exit(1);
}
start_16 = clock();
bzero(&server_addr,sizeof(server_addr));
server_addr.sin_family =AF_INET;
server_addr.sin_port =htons(6000);
server_addr.sin_addr.s_addr=inet_addr("192.168.0.1");
if(connect(sockfd,(struct sockaddr*)(&server_addr),sizeof(struct sockaddr))==-1)
{
fprintf(stderr,"Connect Error:%s\a\n",strerror(errno));
exit(1);
}
fprintf(stderr,"before buf\n");
fflush(stderr);
while(!(feof(stdin)))
{
int n=fread(buf,1,1024*64,stdin);
fwrite(buf,1,n,fp);
if((nbytes=send(sockfd,buf,n,0))==-1)
{
fprintf(stderr,"Write Error:%s\n",strerror(errno));
exit(1);
}
}
end_16 = clock();
fprintf(stderr, "Sent to Windows time is:%f\n",(double)(end_16 - start_16) / CLOCKS_PER_SEC);
close(sockfd);
return(0);
}