2 ** BPALogin - lightweight portable BIDS2 login client
3 ** Copyright (c) 2001-3 Shane Hyde, and others.
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 ** Main processing loop. Logs in, handles heartbeats, and logs out on request
26 ** Returns - 0 - We are no longer connected, and should not retry.
27 ** 1 - We are no longer connnected and should retry.
29 int mainloop(struct session
* s
)
32 struct sockaddr_in listenaddr
;
39 s
->listensock
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
41 s
->localaddr
.sin_family
= AF_INET
;
42 s
->localaddr
.sin_port
= htons(s
->localport
);
43 if(strcmp(s
->localaddress
,""))
45 s
->debug(0,"Using local address %s\n",s
->localaddress
);
46 he
= gethostbyname(s
->localaddress
);
50 s
->localaddr
.sin_addr
.s_addr
= *((int*)(he
->h_addr_list
[0]));
54 s
->localaddr
.sin_addr
.s_addr
= inet_addr(s
->localaddress
);
59 s
->localaddr
.sin_addr
.s_addr
= INADDR_ANY
;
62 addrsize
= sizeof(struct sockaddr_in
);
63 err
= bind(s
->listensock
,(struct sockaddr
*)&s
->localaddr
,sizeof(s
->localaddr
));
64 err
= getsockname(s
->listensock
,(struct sockaddr
*)&listenaddr
,&addrsize
);
66 //s->sessionid = time(NULL);
67 s
->sessionid
= get_time(NULL
);
69 s
->listenport
= ntohs(listenaddr
.sin_port
);
70 strcpy(s
->osname
,"whocares");
71 strcpy(s
->osrelease
,"notme");
73 he
= gethostbyname(s
->authserver
);
77 s
->authhost
.sin_addr
.s_addr
= *((int*)(he
->h_addr_list
[0]));
81 s
->authhost
.sin_addr
.s_addr
= inet_addr(s
->authserver
);
84 s
->authhost
.sin_port
= htons(s
->authport
);
85 s
->authhost
.sin_family
= AF_INET
;
87 s
->debug(0,"Auth host = %s:%d\n",s
->authserver
,s
->authport
);
88 s
->debug(0,"Auth domain = %s\n",s
->authdomain
);
89 s
->debug(0,"Listening on port %d\n",s
->listenport
);
91 if(test_connect_success
// by honor, for debug
94 s
->onconnected(s
->listenport
);
95 if(!handle_heartbeats(s
))
99 s
->noncritical("Sleeping for 10 seconds (1)");
110 closesocket(s
->listensock
);
113 closesocket(s
->listensock
);
118 s
->noncritical("Sleeping for 10 seconds (2)");
126 closesocket(s
->listensock
);
132 log_to_file(char *buf
) // add by honor
136 if ((fp
= fopen("/tmp/ppp/log", "w"))) {
137 fprintf(fp
, "%s", buf
);